access_manager 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a44076b88453152b0ff5d98bac2f98d92ac3f3ab
4
- data.tar.gz: aeb2a1d0a310e816c540adc119a8f55dadb9075f
3
+ metadata.gz: ff289656f076f55f1e09706bea32a558a3a0e96e
4
+ data.tar.gz: fc7966d7942807c2377af604172ce9fa7cf8be7b
5
5
  SHA512:
6
- metadata.gz: 8e973227a715128a2b1c148df9184373333c2577d4115bf3e051e9d69c4fc97b28af5848487376db66292ef55bd3c0870f0ecf5197923bc80f2b32bb6331c769
7
- data.tar.gz: afce5aa7895d25d029f39d848ced9622b9848e09381112c7548a956ff47f5be7e88099e8218bbfd37570049abad72d6e4ce9ef44fe14cc35dd4edde561208d66
6
+ metadata.gz: acaa35dd7632981054e0f70a6da047837fd65a18c1848ff4ce0b4ea9f96e0a3e44fb7d197555304f93c473ea3707ad4404188f7685dc056ae18a9a0b31fbdb2f
7
+ data.tar.gz: 1b38494c63f42a24cfd4fe6dbd103b5f4b8b9591d65ecb26a7b10b40bba0ae7114e35011ee144332993ee6c60bd3bd018a064dd8058f4fb1bad31a80625286d4
data/CHANGELOG.md CHANGED
@@ -25,3 +25,7 @@
25
25
  ## v0.1.0
26
26
 
27
27
  * Added assets and view helpers
28
+
29
+ ## v0.1.1
30
+
31
+ * Bugfixes
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AccessManager
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'access_manager/control'
2
- require 'access_manager/rules'
3
2
  require 'access_manager/version'
4
3
 
5
4
  if defined? (Rails)
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.0
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
@@ -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