acl9 2.0.0 → 2.1.0
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 +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/gemfiles/rails_4.0.gemfile +1 -0
- data/gemfiles/rails_4.1.gemfile +1 -0
- data/gemfiles/rails_4.2.gemfile +1 -0
- data/lib/acl9/controller_extensions/dsl_base.rb +14 -8
- data/lib/acl9/version.rb +1 -1
- data/test/controller_extensions/actions_test.rb +1 -1
- data/test/controller_extensions/method_test.rb +28 -8
- data/test/dummy/config/environments/test.rb +1 -0
- 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: d5f65e35d4e9298c14f5954b31b864aa8257d8ab
|
4
|
+
data.tar.gz: 0b603fd3fcf803a503a1a3e8ac16244227e1c932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc88b6be0fd0bb9b189a5e004cb79a06b552d527f8f7f76627bb8fbc2a02fb1e44cd67a29d4fb9241f7633ded1445346149bb174ce47a2e850d14bdc5a086b9
|
7
|
+
data.tar.gz: 21dee50ff08be47a3e2b07f101b2f348a73242917c12cbf6e461ba38ac86fc8826d05eddd3f054ce2ba302c8ccf692fdea99f4c390432f55dbbfdb7d4eea8237
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,13 +42,13 @@ class Admin::SchoolsController < ApplicationController
|
|
42
42
|
access_control do
|
43
43
|
allow :support, :of => School
|
44
44
|
allow :admins, :managers, :teachers, :of => :school
|
45
|
-
deny :teachers, :
|
45
|
+
deny :teachers, :only => :destroy
|
46
46
|
|
47
47
|
action :index do
|
48
48
|
allow anonymous, logged_in
|
49
49
|
end
|
50
50
|
|
51
|
-
allow logged_in, :
|
51
|
+
allow logged_in, :only => :show
|
52
52
|
deny :students
|
53
53
|
end
|
54
54
|
|
data/gemfiles/rails_4.0.gemfile
CHANGED
data/gemfiles/rails_4.1.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
@@ -69,8 +69,8 @@ module Acl9
|
|
69
69
|
raise ArgumentError, "You cannot use default inside an actions block"
|
70
70
|
end
|
71
71
|
|
72
|
-
def _set_action_clause(
|
73
|
-
raise ArgumentError, "You cannot use :to
|
72
|
+
def _set_action_clause(only, except)
|
73
|
+
raise ArgumentError, "You cannot use :only (:to) or :except inside actions block" if only || except
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -93,14 +93,20 @@ module Acl9
|
|
93
93
|
alias anyone all
|
94
94
|
|
95
95
|
def _permitted_allow_deny_option!(key)
|
96
|
-
raise ArgumentError, "#{key} is not a valid option" unless [:to, :except, :if, :unless, *VALID_PREPOSITIONS].include?(key.to_sym)
|
96
|
+
raise ArgumentError, "#{key} is not a valid option" unless [:to, :only, :except, :if, :unless, *VALID_PREPOSITIONS].include?(key.to_sym)
|
97
|
+
end
|
98
|
+
|
99
|
+
def _retrieve_only options
|
100
|
+
only = [ options.delete(:only) ].flatten.compact
|
101
|
+
only |= [ options.delete(:to) ].flatten.compact
|
102
|
+
only if only.present?
|
97
103
|
end
|
98
104
|
|
99
105
|
def _parse_and_add_rule(*args)
|
100
106
|
options = args.extract_options!
|
101
107
|
options.keys.each { |key| _permitted_allow_deny_option!(key) }
|
102
108
|
|
103
|
-
_set_action_clause(options
|
109
|
+
_set_action_clause( _retrieve_only(options), options.delete(:except))
|
104
110
|
|
105
111
|
object = _role_object(options)
|
106
112
|
|
@@ -147,15 +153,15 @@ module Acl9
|
|
147
153
|
(@current_rule == :allow ? @allows : @denys) << anded.join(' && ')
|
148
154
|
end
|
149
155
|
|
150
|
-
def _set_action_clause(
|
151
|
-
raise ArgumentError, "both :to and :except cannot be specified in the rule" if
|
156
|
+
def _set_action_clause(only, except)
|
157
|
+
raise ArgumentError, "both :only (:to) and :except cannot be specified in the rule" if only && except
|
152
158
|
|
153
159
|
@action_clause = nil
|
154
|
-
action_list =
|
160
|
+
action_list = only || except
|
155
161
|
return unless action_list
|
156
162
|
|
157
163
|
expr = _action_check_expression(action_list)
|
158
|
-
@action_clause =
|
164
|
+
@action_clause = only ? "#{expr}" : "!#{expr}"
|
159
165
|
end
|
160
166
|
|
161
167
|
def _action_check_expression(action_list)
|
data/lib/acl9/version.rb
CHANGED
@@ -12,27 +12,47 @@ module ControllerExtensions
|
|
12
12
|
%w(index show edit update delete destroy).each { |act| assert_permitted @trusted, act }
|
13
13
|
end
|
14
14
|
|
15
|
-
test "should raise an ArgumentError when
|
16
|
-
|
17
|
-
|
15
|
+
test "should raise an ArgumentError when either :to or :only and :except are specified" do
|
16
|
+
%i[to only].each do |only|
|
17
|
+
assert_raise ArgumentError do
|
18
|
+
@tester.acl_block! { allow all, only => :index, :except => ['show', 'edit'] }
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
test ":to
|
23
|
+
test ":to and :only should combine in union" do
|
22
24
|
assert ( @manager = User.create ).has_role! :manager
|
23
25
|
assert ( @trusted = User.create ).has_role! :trusted
|
24
26
|
|
25
27
|
@tester.acl_block! do
|
26
|
-
allow all,
|
28
|
+
allow all, :only => :index, :to => :show
|
27
29
|
|
28
|
-
allow 'manager', :
|
29
|
-
allow 'manager', :to => 'update'
|
30
|
-
allow 'trusted', :
|
30
|
+
allow 'manager', :only => :edit, :to => 'edit'
|
31
|
+
allow 'manager', :to => 'update', :only => :update
|
32
|
+
allow 'trusted', :only => %w(edit update destroy), :to => %w(edit delete)
|
31
33
|
end
|
32
34
|
|
33
35
|
run_tests
|
34
36
|
end
|
35
37
|
|
38
|
+
|
39
|
+
test ":to and :only should limit rule scope to specified actions" do
|
40
|
+
assert ( @manager = User.create ).has_role! :manager
|
41
|
+
assert ( @trusted = User.create ).has_role! :trusted
|
42
|
+
|
43
|
+
%i[to only].each do |only|
|
44
|
+
@tester.acl_block! do
|
45
|
+
allow all, only => [:index, :show]
|
46
|
+
|
47
|
+
allow 'manager', only => :edit
|
48
|
+
allow 'manager', only => 'update'
|
49
|
+
allow 'trusted', only => %w(edit update delete destroy)
|
50
|
+
end
|
51
|
+
|
52
|
+
run_tests
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
36
56
|
test ":except should limit rule scope to all actions except specified" do
|
37
57
|
assert ( @manager = User.create ).has_role! :manager
|
38
58
|
assert ( @trusted = User.create ).has_role! :trusted
|