Add option to skip authorization
This commit is contained in:
		
							parent
							
								
									315a24556c
								
							
						
					
					
						commit
						b4f5fddc5c
					
				|  | @ -197,13 +197,22 @@ module  OrbitCoreLib | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  |       def skip_authorization(arg = nil) | ||||||
|  |         if arg | ||||||
|  |           key = arg.shift | ||||||
|  |           prepend_before_filter key[0] => key[1] {|f| f.no_authorization} | ||||||
|  |         else | ||||||
|  |           prepend_before_filter {|f| f.no_authorization} | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     module InstanceMethods |     module InstanceMethods | ||||||
|       protected |       protected | ||||||
|       def can_use |       def can_use | ||||||
|         setup_vars |         setup_vars | ||||||
|         set_current_user |         unless @no_authorization | ||||||
|           if @user_type |           if @user_type | ||||||
|             @user_type.each do |user_type| |             @user_type.each do |user_type| | ||||||
|               open = false |               open = false | ||||||
|  | @ -218,6 +227,7 @@ module  OrbitCoreLib | ||||||
|               when :approver |               when :approver | ||||||
|                 open ||= check_sub_manager |                 open ||= check_sub_manager | ||||||
|               when :visitor |               when :visitor | ||||||
|  |                 set_current_user | ||||||
|                 open ||= true |                 open ||= true | ||||||
|                 visitor ||= true |                 visitor ||= true | ||||||
|               end |               end | ||||||
|  | @ -230,6 +240,7 @@ module  OrbitCoreLib | ||||||
|             check_user_can_use |             check_user_can_use | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|  |       end | ||||||
| 
 | 
 | ||||||
|       def check_admin |       def check_admin | ||||||
|         current_or_guest_user.admin? |         current_or_guest_user.admin? | ||||||
|  | @ -252,6 +263,10 @@ module  OrbitCoreLib | ||||||
|         @user_type << var |         @user_type << var | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  |       def no_authorization | ||||||
|  |         @no_authorization = true | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|       def check_user_can_use |       def check_user_can_use | ||||||
|         unless current_or_guest_user.admin? || @module_app.is_manager?(current_or_guest_user) || @module_app.is_sub_manager?(current_or_guest_user) || @module_app.can_approve?(current_or_guest_user) |         unless current_or_guest_user.admin? || @module_app.is_manager?(current_or_guest_user) || @module_app.is_sub_manager?(current_or_guest_user) || @module_app.can_approve?(current_or_guest_user) | ||||||
|           redirect_to root_url |           redirect_to root_url | ||||||
|  | @ -259,9 +274,8 @@ module  OrbitCoreLib | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def setup_vars |       def setup_vars | ||||||
|         @app_title ||= controller_path.split('/')[1].singularize |         @app_title ||= controller_path.split('/')[1].singularize rescue nil | ||||||
|         @module_app ||= ModuleApp.first(conditions: {:key => @app_title} ) |         @module_app ||= ModuleApp.first(conditions: {:key => @app_title} ) rescue nil | ||||||
|         # raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil? |  | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue