access_manager 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/access_manager/control.rb +37 -41
- data/lib/access_manager/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a4dc4ac9e215934f8a2975dbc10e4830efc586e
|
4
|
+
data.tar.gz: 0d7fd03cf0d7f56ad70217bc3b9ab3f8eb151062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f5eb58d18cf5dfd774a3f659a924893d5a3e5decf4f0eefa8d62a558016b6077e4e7c9fb4d079b0047111c5593072bf74ebe843f701841ce3ae1b871f7847c
|
7
|
+
data.tar.gz: 26161875a0d145847e622e4fe7088bcd2d245c59dc8b9b313fb952c23becb929d1a9bbbcc2ae55444c3bfc135a97f40c8519b658737f50d1b074b938ec9a9a8a
|
data/CHANGELOG.md
CHANGED
@@ -1,63 +1,59 @@
|
|
1
1
|
module AccessManager
|
2
2
|
module Control
|
3
|
-
def self.included(base)
|
4
|
-
base.extend(ClassMethods)
|
5
|
-
end
|
6
|
-
|
7
3
|
def can_access?(controller, action)
|
8
|
-
action_codes.any? { |user_action|
|
4
|
+
action_codes.any? { |user_action| access_granted?(controller, action, user_action) }
|
9
5
|
end
|
10
6
|
|
11
7
|
def can?(action)
|
12
8
|
action_codes.map(&:to_s).include?(action.to_s)
|
13
9
|
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if @access_tree.nil?
|
20
|
-
@access_tree = { }
|
21
|
-
end
|
11
|
+
def access_granted?(controller, action, user_action)
|
12
|
+
if @access_tree.nil?
|
13
|
+
set_grants!
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
16
|
+
if @access_tree.nil? || @access_tree.empty?
|
17
|
+
return false
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
if @access_tree[controller.to_sym]['@all'].nil?
|
30
|
-
@access_tree[controller.to_sym]['@all'] = []
|
31
|
-
end
|
20
|
+
controller_grants = @access_tree[controller.to_sym]
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
22
|
+
if controller_grants.nil?
|
23
|
+
false
|
24
|
+
elsif controller_grants['@all'] && controller_grants['@all'].include?(user_action.to_sym)
|
25
|
+
true
|
26
|
+
elsif controller_grants[action.to_sym].nil?
|
27
|
+
false
|
28
|
+
else
|
29
|
+
controller_grants[action.to_sym].include?(user_action.to_sym)
|
30
|
+
end
|
31
|
+
end
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
33
|
+
def grant_access_with(user_action, args={})
|
34
|
+
if @access_tree.nil?
|
35
|
+
@access_tree = { }
|
44
36
|
end
|
45
37
|
|
46
|
-
|
47
|
-
if @access_tree.nil?
|
48
|
-
@access_tree = { }
|
38
|
+
args[:to].each do |controller, actions|
|
39
|
+
if @access_tree[controller.to_sym].nil?
|
40
|
+
@access_tree[controller.to_sym] = { }
|
49
41
|
end
|
50
42
|
|
51
|
-
|
43
|
+
if actions == :all
|
44
|
+
if @access_tree[controller.to_sym]['@all'].nil?
|
45
|
+
@access_tree[controller.to_sym]['@all'] = []
|
46
|
+
end
|
52
47
|
|
53
|
-
|
54
|
-
false
|
55
|
-
elsif controller_grants['@all'] && controller_grants['@all'].include?(user_action.to_sym)
|
56
|
-
true
|
57
|
-
elsif controller_grants[action.to_sym].nil?
|
58
|
-
false
|
48
|
+
@access_tree[controller.to_sym]['@all'] << user_action
|
59
49
|
else
|
60
|
-
|
50
|
+
actions.each do |action|
|
51
|
+
if @access_tree[controller.to_sym][action.to_sym].nil?
|
52
|
+
@access_tree[controller.to_sym][action.to_sym] = []
|
53
|
+
end
|
54
|
+
|
55
|
+
@access_tree[controller.to_sym][action.to_sym] << user_action
|
56
|
+
end
|
61
57
|
end
|
62
58
|
end
|
63
59
|
end
|