access_manager 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/access_manager/control.rb +54 -0
- data/lib/access_manager/version.rb +1 -1
- data/lib/access_manager.rb +0 -1
- metadata +1 -2
- data/lib/access_manager/rules.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff289656f076f55f1e09706bea32a558a3a0e96e
|
4
|
+
data.tar.gz: fc7966d7942807c2377af604172ce9fa7cf8be7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acaa35dd7632981054e0f70a6da047837fd65a18c1848ff4ce0b4ea9f96e0a3e44fb7d197555304f93c473ea3707ad4404188f7685dc056ae18a9a0b31fbdb2f
|
7
|
+
data.tar.gz: 1b38494c63f42a24cfd4fe6dbd103b5f4b8b9591d65ecb26a7b10b40bba0ae7114e35011ee144332993ee6c60bd3bd018a064dd8058f4fb1bad31a80625286d4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module AccessManager
|
2
2
|
module Control
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
3
7
|
def can_access?(controller, action)
|
4
8
|
action_codes.any? { |user_action| self.class.access_granted?(controller, action, user_action) }
|
5
9
|
end
|
@@ -7,5 +11,55 @@ module AccessManager
|
|
7
11
|
def can?(action)
|
8
12
|
action_codes.map(&:to_s).include?(action.to_s)
|
9
13
|
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
attr_accessor :access_tree
|
17
|
+
|
18
|
+
def grant_access_with(user_action, args={})
|
19
|
+
if @access_tree.nil?
|
20
|
+
@access_tree = { }
|
21
|
+
end
|
22
|
+
|
23
|
+
args[:to].each do |controller, actions|
|
24
|
+
if @access_tree[controller.to_sym].nil?
|
25
|
+
@access_tree[controller.to_sym] = { }
|
26
|
+
end
|
27
|
+
|
28
|
+
if actions == :all
|
29
|
+
if @access_tree[controller.to_sym]['@all'].nil?
|
30
|
+
@access_tree[controller.to_sym]['@all'] = []
|
31
|
+
end
|
32
|
+
|
33
|
+
@access_tree[controller.to_sym]['@all'] << user_action
|
34
|
+
else
|
35
|
+
actions.each do |action|
|
36
|
+
if @access_tree[controller.to_sym][action.to_sym].nil?
|
37
|
+
@access_tree[controller.to_sym][action.to_sym] = []
|
38
|
+
end
|
39
|
+
|
40
|
+
@access_tree[controller.to_sym][action.to_sym] << user_action
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def access_granted?(controller, action, user_action)
|
47
|
+
if @access_tree.nil?
|
48
|
+
@access_tree = { }
|
49
|
+
end
|
50
|
+
|
51
|
+
controller_grants = @access_tree[controller.to_sym]
|
52
|
+
|
53
|
+
if controller_grants.nil?
|
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
|
59
|
+
else
|
60
|
+
controller_grants[action.to_sym].include?(user_action.to_sym)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
10
64
|
end
|
11
65
|
end
|
data/lib/access_manager.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: access_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Hick
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- lib/access_manager/control.rb
|
53
53
|
- lib/access_manager/engine.rb
|
54
54
|
- lib/access_manager/railtie.rb
|
55
|
-
- lib/access_manager/rules.rb
|
56
55
|
- lib/access_manager/version.rb
|
57
56
|
- lib/access_manager/view_helpers.rb
|
58
57
|
- vendor/assets/javascripts/access_manager.js
|
data/lib/access_manager/rules.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module AccessManager
|
2
|
-
module Rules
|
3
|
-
attr_accessor :access_tree
|
4
|
-
|
5
|
-
def grant_access_with(user_action, args={})
|
6
|
-
if @access_tree.nil?
|
7
|
-
@access_tree = { }
|
8
|
-
end
|
9
|
-
|
10
|
-
args[:to].each do |controller, actions|
|
11
|
-
if @access_tree[controller.to_sym].nil?
|
12
|
-
@access_tree[controller.to_sym] = { }
|
13
|
-
end
|
14
|
-
|
15
|
-
if actions == :all
|
16
|
-
if @access_tree[controller.to_sym]['@all'].nil?
|
17
|
-
@access_tree[controller.to_sym]['@all'] = []
|
18
|
-
end
|
19
|
-
|
20
|
-
@access_tree[controller.to_sym]['@all'] << user_action
|
21
|
-
else
|
22
|
-
actions.each do |action|
|
23
|
-
if @access_tree[controller.to_sym][action.to_sym].nil?
|
24
|
-
@access_tree[controller.to_sym][action.to_sym] = []
|
25
|
-
end
|
26
|
-
|
27
|
-
@access_tree[controller.to_sym][action.to_sym] << user_action
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def access_granted?(controller, action, user_action)
|
34
|
-
if @access_tree.nil?
|
35
|
-
@access_tree = { }
|
36
|
-
end
|
37
|
-
|
38
|
-
if @access_tree[controller.to_sym].nil?
|
39
|
-
true
|
40
|
-
elsif ((!@access_tree[controller.to_sym]['@all'].nil?) && @access_tree[controller.to_sym]['@all'].any?)
|
41
|
-
@access_tree[controller.to_sym]['@all'].include?(user_action.to_sym)
|
42
|
-
elsif @access_tree[controller.to_sym][action.to_sym].nil?
|
43
|
-
true
|
44
|
-
else
|
45
|
-
@access_tree[controller.to_sym][action.to_sym].include?(user_action.to_sym)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|