acl9 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8c381fe3a5d5c08f53de89f42e32a3d537c0194
4
- data.tar.gz: 6f1ecac6cf51489c7ac811b1cf953b260c7b0e97
3
+ metadata.gz: d5f65e35d4e9298c14f5954b31b864aa8257d8ab
4
+ data.tar.gz: 0b603fd3fcf803a503a1a3e8ac16244227e1c932
5
5
  SHA512:
6
- metadata.gz: 12dc684ca7c51688d5b19706ccde9c257e673212475ff31d897a403529879649a5381d7961aaab17a7e94b14bcbd483039aed942f053ab1aa716452c8560f0ff
7
- data.tar.gz: af2e0997183914917e14239eb1268a803bad66bd7f0a35f9703a43431d84bf532671a32e2d22471e13a42af28daf32bac211f2cfe12a0cd861cfd520379e7479
6
+ metadata.gz: 8bc88b6be0fd0bb9b189a5e004cb79a06b552d527f8f7f76627bb8fbc2a02fb1e44cd67a29d4fb9241f7633ded1445346149bb174ce47a2e850d14bdc5a086b9
7
+ data.tar.gz: 21dee50ff08be47a3e2b07f101b2f348a73242917c12cbf6e461ba38ac86fc8826d05eddd3f054ce2ba302c8ccf692fdea99f4c390432f55dbbfdb7d4eea8237
@@ -1,3 +1,8 @@
1
+ ## 2.1.0 - 14 May 2015
2
+
3
+ Added `:only` (as well as `:to`) for specifying actions in `allow`/`deny`
4
+ blocks.
5
+
1
6
  ## 2.0.0 - 14 May 2015
2
7
 
3
8
  Thanks to @pjungwir:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acl9 (1.3.0)
4
+ acl9 (2.1.0)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
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, :to => :destroy
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, :to => :show
51
+ allow logged_in, :only => :show
52
52
  deny :students
53
53
  end
54
54
 
@@ -5,6 +5,7 @@ source "http://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "tapout"
7
7
  gem "minitap"
8
+ gem "byebug"
8
9
  gem "rails", "~> 4.0.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -5,6 +5,7 @@ source "http://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "tapout"
7
7
  gem "minitap"
8
+ gem "byebug"
8
9
  gem "rails", "~> 4.1.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -5,6 +5,7 @@ source "http://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "tapout"
7
7
  gem "minitap"
8
+ gem "byebug"
8
9
  gem "rails", "~> 4.2.0"
9
10
 
10
11
  gemspec :path => "../"
@@ -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(to, except)
73
- raise ArgumentError, "You cannot use :to/:except inside actions block" if to || except
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.delete(:to), options.delete(:except))
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(to, except)
151
- raise ArgumentError, "both :to and :except cannot be specified in the rule" if to && except
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 = to || except
160
+ action_list = only || except
155
161
  return unless action_list
156
162
 
157
163
  expr = _action_check_expression(action_list)
158
- @action_clause = to ? "#{expr}" : "!#{expr}"
164
+ @action_clause = only ? "#{expr}" : "!#{expr}"
159
165
  end
160
166
 
161
167
  def _action_check_expression(action_list)
@@ -1,3 +1,3 @@
1
1
  module Acl9
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -35,7 +35,7 @@ module ControllerExtensions
35
35
  end
36
36
  end
37
37
 
38
- [:to, :except].each do |opt|
38
+ [:to, :only, :except].each do |opt|
39
39
  test "should raise an ArgumentError when allow is called with #{opt} option" do
40
40
  assert_raise ArgumentError do
41
41
  @tester.acl_block! do
@@ -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 both :to and :except are specified" do
16
- assert_raise ArgumentError do
17
- @tester.acl_block! { allow all, :to => :index, :except => ['show', 'edit'] }
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 should limit rule scope to specified actions" do
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, :to => [:index, :show]
28
+ allow all, :only => :index, :to => :show
27
29
 
28
- allow 'manager', :to => :edit
29
- allow 'manager', :to => 'update'
30
- allow 'trusted', :to => %w(edit update delete destroy)
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
@@ -36,4 +36,5 @@ Dummy::Application.configure do
36
36
 
37
37
  # Raises error for missing translations
38
38
  # config.action_view.raise_on_missing_translations = true
39
+ config.log_level = :unknown
39
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acl9
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oleg dashevskii