flexible_accessibility 0.2.0.pre → 0.2.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
 - data/flexible_accessibility.gemspec +2 -2
 - data/lib/flexible_accessibility/exceptions.rb +36 -7
 - data/lib/flexible_accessibility/filters.rb +15 -12
 - metadata +4 -4
 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -15,7 +15,7 @@ require 'jeweler' 
     | 
|
| 
       15 
15 
     | 
    
         
             
            Jeweler::Tasks.new do |gem|
         
     | 
| 
       16 
16 
     | 
    
         
             
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         
     | 
| 
       17 
17 
     | 
    
         
             
              gem.name = "flexible_accessibility"
         
     | 
| 
       18 
     | 
    
         
            -
              gem.version = "0.2. 
     | 
| 
      
 18 
     | 
    
         
            +
              gem.version = "0.2.1.pre"
         
     | 
| 
       19 
19 
     | 
    
         
             
              gem.homepage = "http://github.com/mochnatiy/flexible_accessibility"
         
     | 
| 
       20 
20 
     | 
    
         
             
              gem.license = "MIT"
         
     | 
| 
       21 
21 
     | 
    
         
             
              gem.summary = %Q{Flexible access control system}
         
     | 
| 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = "flexible_accessibility"
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.2. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.2.1.pre"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Sergey Awanesov"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = "2012-07- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = "2012-07-26"
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = "Flexible access control system for your rails application. Based on analysis of controller actions"
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = "sergey.awanesov@gmail.com"
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -1,17 +1,46 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module FlexibleAccessibility
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                attr_writer :default_message
         
     | 
| 
      
 2 
     | 
    
         
            +
              class FlexibleAccessibilityException < StandardError
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :action, :subject, :default_message
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                def initialize( 
     | 
| 
       7 
     | 
    
         
            -
                  @message = message
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(action = nil, subject = nil)
         
     | 
| 
       8 
6 
     | 
    
         
             
                  @action = action
         
     | 
| 
       9 
7 
     | 
    
         
             
                  @subject = subject
         
     | 
| 
       10 
     | 
    
         
            -
                  @default_message = I18n.t('flexible_accessibility.errors.access_denied', :action => @action)
         
     | 
| 
       11 
8 
     | 
    
         
             
                end
         
     | 
| 
       12 
9 
     | 
    
         | 
| 
       13 
10 
     | 
    
         
             
                def to_s
         
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
      
 11 
     | 
    
         
            +
                  message || default_message
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                private
         
     | 
| 
      
 15 
     | 
    
         
            +
                def message
         
     | 
| 
      
 16 
     | 
    
         
            +
                  nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def default_message
         
     | 
| 
      
 20 
     | 
    
         
            +
                  "An exception is occured"
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            	class AccessDeniedException < FlexibleAccessibilityException
         
     | 
| 
      
 26 
     | 
    
         
            +
                private
         
     | 
| 
      
 27 
     | 
    
         
            +
                def message
         
     | 
| 
      
 28 
     | 
    
         
            +
                  I18n.t 'flexible_accessibility.errors.access_denied', :action => @action
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def default_message
         
     | 
| 
      
 32 
     | 
    
         
            +
            		  "The acess for resoure #{@action} is denied"
         
     | 
| 
       15 
33 
     | 
    
         
             
                end
         
     | 
| 
       16 
34 
     | 
    
         
             
            	end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              class UserNotLoggedInException < FlexibleAccessibilityException
         
     | 
| 
      
 37 
     | 
    
         
            +
                private
         
     | 
| 
      
 38 
     | 
    
         
            +
                def message
         
     | 
| 
      
 39 
     | 
    
         
            +
                  I18n.t 'flexible_accessibility.errors.user_is_not_logged_in'
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def default_message
         
     | 
| 
      
 43 
     | 
    
         
            +
                  "Current user is not logged in"
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
       17 
46 
     | 
    
         
             
            end
         
     | 
| 
         @@ -7,7 +7,7 @@ module FlexibleAccessibility 
     | 
|
| 
       7 
7 
     | 
    
         
             
              	  append_before_filter :check_if_route_permitted
         
     | 
| 
       8 
8 
     | 
    
         
             
              	end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
            	  private
         
     | 
| 
       11 
11 
     | 
    
         
             
                # Detect current controller and action and return a permission
         
     | 
| 
       12 
12 
     | 
    
         
             
                def current_resource
         
     | 
| 
       13 
13 
     | 
    
         
             
                  # ActionController::Routing::Routes.recognize_path request.env["PATH_INFO"][:controller]
         
     | 
| 
         @@ -22,18 +22,21 @@ module FlexibleAccessibility 
     | 
|
| 
       22 
22 
     | 
    
         
             
                def current_route
         
     | 
| 
       23 
23 
     | 
    
         
             
                  "#{current_resource}##{current_action}"
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
              	# We checks access to route
         
     | 
| 
      
 26 
     | 
    
         
            +
              	# And we expected the existing of current_user helper
         
     | 
| 
      
 27 
     | 
    
         
            +
              	def check_permission_to_route
         
     | 
| 
      
 28 
     | 
    
         
            +
                  if self.class.instance_variable_get(:@_checkable_routes).include? current_action.to_sym
         
     | 
| 
      
 29 
     | 
    
         
            +
                    raise UserNotLoggedInException.new(current_route, nil) if current_user.nil?
         
     | 
| 
      
 30 
     | 
    
         
            +
              	    self.class.instance_variable_set :@_route_permitted, Permission.is_action_permitted_for_user?(current_route, current_user)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  else
         
     | 
| 
      
 32 
     | 
    
         
            +
                    self.class.instance_variable_set :@_route_permitted, true
         
     | 
| 
      
 33 
     | 
    
         
            +
              	  end
         
     | 
| 
      
 34 
     | 
    
         
            +
              	end
         
     | 
| 
       32 
35 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
              	# We checks @authorized variable state
         
     | 
| 
      
 37 
     | 
    
         
            +
              	def check_if_route_permitted
         
     | 
| 
      
 38 
     | 
    
         
            +
              	  raise AccessDeniedException.new(current_route, nil) unless self.class.instance_variable_get :@_route_permitted
         
     | 
| 
      
 39 
     | 
    
         
            +
            	  end
         
     | 
| 
       37 
40 
     | 
    
         
             
              end
         
     | 
| 
       38 
41 
     | 
    
         | 
| 
       39 
42 
     | 
    
         
             
              ActiveSupport.on_load(:action_controller) do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: flexible_accessibility
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 961915984
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 6
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 2
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
      
 9 
     | 
    
         
            +
              - 1
         
     | 
| 
       10 
10 
     | 
    
         
             
              - pre
         
     | 
| 
       11 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 11 
     | 
    
         
            +
              version: 0.2.1.pre
         
     | 
| 
       12 
12 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       13 
13 
     | 
    
         
             
            authors: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            - Sergey Awanesov
         
     | 
| 
         @@ -16,7 +16,7 @@ autorequire: 
     | 
|
| 
       16 
16 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       17 
17 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            date: 2012-07- 
     | 
| 
      
 19 
     | 
    
         
            +
            date: 2012-07-26 00:00:00 Z
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :development
         
     |