flexible_accessibility 0.3.7 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/flexible_accessibility.gemspec +2 -2
- data/lib/flexible_accessibility.rb +1 -1
- data/lib/flexible_accessibility/controller_methods.rb +13 -20
- data/lib/flexible_accessibility/filters.rb +7 -9
- data/lib/flexible_accessibility/permission.rb +3 -2
- data/lib/flexible_accessibility/{utils.rb → route_provider.rb} +36 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 091ff0a106f65dc17c65d44936339a4515e49fc4
|
4
|
+
data.tar.gz: d1382522645bff705556af8f6eb2e50457c67419
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df52bdf2540ca2dab17fe892d482c2c9046cf523a7228bba1f79de76557c2fae58cf261ffe3f50419fd64bcf804840500b3af7ef456ffeab2e18472c2a1b77f
|
7
|
+
data.tar.gz: 922db8d98a6ea243bf2cd7e9e91dfff6965f005214c99e593b4dafe23eb19692fbd91dde78786bf81cfd2d0be03605e36728c78140f28266c2eaa36899c0c41c
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'flexible_accessibility'
|
5
|
-
s.version = '0.3.
|
5
|
+
s.version = '0.3.16'
|
6
6
|
s.authors = ['Sergey Avanesov']
|
7
|
-
s.date = '2014-
|
7
|
+
s.date = '2014-07-08'
|
8
8
|
s.summary = 'Flexible access control system'
|
9
9
|
s.description = 'Flexible access control system for your rails application. Based on analysis of controller actions'
|
10
10
|
s.email = 'sergey.awanesov@gmail.com'
|
@@ -4,6 +4,6 @@ require 'flexible_accessibility/exceptions.rb'
|
|
4
4
|
require 'flexible_accessibility/permission.rb'
|
5
5
|
require 'flexible_accessibility/filters.rb'
|
6
6
|
require 'flexible_accessibility/resource.rb'
|
7
|
-
require 'flexible_accessibility/
|
7
|
+
require 'flexible_accessibility/route_provider.rb'
|
8
8
|
require 'flexible_accessibility/access_provider.rb'
|
9
9
|
require 'flexible_accessibility/access_rule.rb'
|
@@ -7,26 +7,18 @@ module FlexibleAccessibility
|
|
7
7
|
authorize :skip => :all
|
8
8
|
end
|
9
9
|
|
10
|
-
# Macro for define
|
10
|
+
# Macro for define routes table with authorization
|
11
11
|
def authorize(args={})
|
12
12
|
arguments = parse_arguments(args)
|
13
|
-
validate_arguments(arguments)
|
14
|
-
available_routes = Utils.new.app_routes[self.to_s.gsub(/Controller/, '')]
|
15
|
-
# available_routes = self.action_methods if available_routes.nil?
|
16
|
-
raise NoWayToDetectAvailableRoutesException if available_routes.nil?
|
17
|
-
|
18
|
-
self.instance_variable_set(:@_verifiable_routes, available_routes) if arguments[:all]
|
19
|
-
self.instance_variable_set(:@_verifiable_routes, arguments[:only]) unless arguments[:only].nil?
|
20
|
-
self.instance_variable_set(:@_verifiable_routes, available_routes - arguments[:except]) unless arguments[:except].nil?
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
14
|
+
validate_arguments(arguments)
|
15
|
+
|
16
|
+
self.instance_variable_set(:@_routes_table, arguments)
|
26
17
|
end
|
27
18
|
|
28
19
|
private
|
29
|
-
|
20
|
+
|
21
|
+
# Parse arguments from macro call
|
30
22
|
def parse_arguments(args={})
|
31
23
|
result = {}
|
32
24
|
(result[:all] = ['all'].to_set) and return result if args.to_s == 'all'
|
@@ -40,6 +32,7 @@ module FlexibleAccessibility
|
|
40
32
|
result
|
41
33
|
end
|
42
34
|
|
35
|
+
# Validate arguments from macro call
|
43
36
|
def validate_arguments(args={})
|
44
37
|
return if args.count == 1 && args.keys.include?(:all)
|
45
38
|
only_options = args[:only] || Set.new
|
@@ -54,18 +47,18 @@ module FlexibleAccessibility
|
|
54
47
|
end
|
55
48
|
end
|
56
49
|
end
|
50
|
+
|
51
|
+
# Check the url for each link in view to show it
|
52
|
+
def has_access?(permission, user)
|
53
|
+
raise UnknownUserException if user.nil?
|
54
|
+
AccessProvider.is_action_permitted_for_user?(permission, user)
|
55
|
+
end
|
57
56
|
|
58
57
|
# Callback is needed for include methods and define helper method
|
59
58
|
def self.included(base)
|
60
59
|
base.extend(ClassMethods)
|
61
60
|
base.helper_method(:has_access?)
|
62
61
|
end
|
63
|
-
|
64
|
-
# Check the url for each link in view to show it
|
65
|
-
def has_access?(permission, user)
|
66
|
-
raise UnknownUserException if user.nil?
|
67
|
-
AccessProvider.is_action_permitted_for_user?(permission, user)
|
68
|
-
end
|
69
62
|
end
|
70
63
|
end
|
71
64
|
|
@@ -31,16 +31,14 @@ module FlexibleAccessibility
|
|
31
31
|
|
32
32
|
# Check access to route and we expected the existing of current_user helper
|
33
33
|
def check_permission_to_route
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if self.class.instance_variable_get(:@_verifiable_routes).include?(current_action)
|
34
|
+
route_provider = RouteProvider.new(self.class)
|
35
|
+
if route_provider.verifiable_routes_list.include?(current_action)
|
38
36
|
raise UserNotLoggedInException.new(current_route, nil) if logged_user.nil?
|
39
|
-
|
40
|
-
elsif
|
41
|
-
|
37
|
+
AccessProvider.is_action_permitted_for_user?(current_route, logged_user) ? allow_route : deny_route
|
38
|
+
elsif route_provider.non_verifiable_routes_list.include?(current_action)
|
39
|
+
allow_route
|
42
40
|
else
|
43
|
-
|
41
|
+
deny_route
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
@@ -52,7 +50,7 @@ module FlexibleAccessibility
|
|
52
50
|
self.class.instance_variable_set(:@_route_permitted, false)
|
53
51
|
end
|
54
52
|
|
55
|
-
# Check the @
|
53
|
+
# Check the @_route_permitted variable state
|
56
54
|
def check_if_route_is_permitted
|
57
55
|
raise AccessDeniedException.new(current_route, nil) unless self.class.instance_variable_get(:@_route_permitted)
|
58
56
|
end
|
@@ -20,11 +20,12 @@ module FlexibleAccessibility
|
|
20
20
|
class << self
|
21
21
|
def all
|
22
22
|
permissions = []
|
23
|
-
|
23
|
+
RouteProvider.new.app_controllers.each do |scope|
|
24
24
|
namespace = scope.first.to_s
|
25
25
|
scope.last.each do |resource|
|
26
26
|
resource = "#{namespace}/#{resource}" unless namespace == 'default'
|
27
|
-
permissions << Permission.new(:resource => resource.gsub(/_controller/, ''),
|
27
|
+
permissions << Permission.new(:resource => resource.gsub(/_controller/, ''),
|
28
|
+
:actions => RouteProvider.new(ApplicationResource.new(resource).klass).verifiable_routes_list)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
permissions
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module FlexibleAccessibility
|
2
|
-
class
|
2
|
+
class RouteProvider
|
3
3
|
@@routes ||= {}
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize(controller=nil)
|
6
6
|
@path = "#{::Rails.root}/app/controllers/"
|
7
7
|
@controllers = {}
|
8
|
+
@current_controller = controller
|
8
9
|
end
|
9
10
|
|
10
11
|
def app_controllers
|
@@ -13,10 +14,42 @@ module FlexibleAccessibility
|
|
13
14
|
|
14
15
|
def app_routes
|
15
16
|
app_routes_as_hash if @@routes.empty?
|
16
|
-
@@routes
|
17
|
+
@@routes
|
18
|
+
end
|
19
|
+
|
20
|
+
def verifiable_routes_list
|
21
|
+
routes_table, list = @current_controller.instance_variable_get(:@_routes_table), []
|
22
|
+
|
23
|
+
unless routes_table.nil?
|
24
|
+
list = available_routes_list if routes_table[:all]
|
25
|
+
list = routes_table[:only] unless routes_table[:only].nil?
|
26
|
+
list = available_routes_list - routes_table[:except] unless routes_table[:except].nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
list
|
30
|
+
end
|
31
|
+
|
32
|
+
def non_verifiable_routes_list
|
33
|
+
routes_table, list = @current_controller.instance_variable_get(:@_routes_table), []
|
34
|
+
|
35
|
+
unless routes_table.nil?
|
36
|
+
unless routes_table[:skip].nil?
|
37
|
+
list = routes_table[:skip].first == 'all' ? available_routes_list : routes_table[:skip]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
list
|
17
42
|
end
|
18
43
|
|
19
44
|
private
|
45
|
+
|
46
|
+
def available_routes_list
|
47
|
+
available_routes = self.app_routes[@current_controller.to_s.gsub(/Controller/, '')]
|
48
|
+
# available_routes = self.action_methods if available_routes.nil?
|
49
|
+
raise NoWayToDetectAvailableRoutesException if available_routes.nil?
|
50
|
+
available_routes.to_set
|
51
|
+
end
|
52
|
+
|
20
53
|
# All controller classes placed in :default scope
|
21
54
|
def app_controllers_recursive(path)
|
22
55
|
invalid_entries = ['..', '.', 'concerns']
|
@@ -37,7 +70,6 @@ module FlexibleAccessibility
|
|
37
70
|
|
38
71
|
# Routes from routes.rb
|
39
72
|
def app_routes_as_hash
|
40
|
-
Rails.application.reload_routes!
|
41
73
|
Rails.application.routes.routes.each do |route|
|
42
74
|
controller = route.defaults[:controller]
|
43
75
|
unless controller.nil?
|
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
|
-
version: 0.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Avanesov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- lib/flexible_accessibility/filters.rb
|
91
91
|
- lib/flexible_accessibility/permission.rb
|
92
92
|
- lib/flexible_accessibility/resource.rb
|
93
|
-
- lib/flexible_accessibility/
|
93
|
+
- lib/flexible_accessibility/route_provider.rb
|
94
94
|
- lib/generators/flexible_accessibility/install/install_generator.rb
|
95
95
|
- lib/generators/flexible_accessibility/install/templates/create_access_rules.rb
|
96
96
|
- test/helper.rb
|