role_based_authorization 0.1.2 → 0.1.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -55,16 +55,12 @@ module RoleBasedAuthorization
55
55
  def permit options
56
56
  options[:controller] ||= controller_name
57
57
  controller = options[:controller]
58
- role_auth_rules[controller] ||= {}
58
+ actions = [*options[:actions]] # create an array if options[:actions] is not already an array
59
59
 
60
- if options[:actions] == :all
61
- role_auth_rules[controller][:all] ||= []
62
- role_auth_rules[controller][:all] << RoleBasedAuthorization::Rule.new(options[:to], options[:if], options[:object_id])
63
- return
64
- end
65
-
66
- options[:actions].each do |action|
67
- action = action.to_s # this allows for both symbols and strings to be used for action names
60
+ role_auth_rules[controller] ||= {}
61
+
62
+ actions.each do |action|
63
+ action = action.to_sym # this allows for both symbols and strings to be used for action names
68
64
  role_auth_rules[controller][action] ||= []
69
65
  role_auth_rules[controller][action] << RoleBasedAuthorization::Rule.new(options[:to], options[:if], options[:object_id])
70
66
  end
@@ -153,8 +149,8 @@ module RoleBasedAuthorization
153
149
 
154
150
  [:all, opts[:action]].each do |action|
155
151
  AUTHORIZATION_LOGGER.debug('current action: %s' % [action])
156
-
157
- raise "Action should be a string -- not a #{action.class.name}!" if action!=:all && action.class!=String
152
+ action = action.to_sym
153
+ raise "Action should be a symbol -- not a #{action.class.name}!" if action!=:all && action.class!=Symbol
158
154
 
159
155
  next if rules[controller].nil? || rules[controller][action].nil?
160
156
  if rules[controller][action].find { |rule| rule.match(opts[:user], opts[:ids]) }
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{role_based_authorization}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roberto Esposito"]
@@ -21,6 +21,10 @@ class DummyController < ActionController::Base
21
21
 
22
22
  permit :actions => 'very_low_security',
23
23
  :to => :all
24
+
25
+ permit :actions => :very_low_security_symbol_version,
26
+ :to => :all
27
+
24
28
 
25
29
  permit :actions => 'high_security',
26
30
  :to => 3
@@ -54,6 +58,20 @@ class RoleBasedAuthorizationTest < ActiveSupport::TestCase
54
58
  test "Should permit action very_low_security to everyone" do
55
59
  assert_equal true, @controller.authorize_action?(:action => 'very_low_security')
56
60
  end
61
+
62
+ test "Should permit action very_low_security to everyone even if it is given as a symbol" do
63
+ assert_equal true, @controller.authorize_action?(:action => :very_low_security)
64
+ end
65
+
66
+ test "Should permit action very_low_security_symbol_version to everyone" do
67
+ assert_equal true, @controller.authorize_action?(:action => :very_low_security_symbol_version)
68
+ end
69
+
70
+
71
+ test "Should permit action very_low_security_symbol_version to everyone even if it is given as a string" do
72
+ assert_equal true, @controller.authorize_action?(:action => 'very_low_security_symbol_version')
73
+ end
74
+
57
75
 
58
76
  test "Should permit action high_security only to root (role 3)" do
59
77
  assert_equal false, @controller.authorize_action?(:action => 'high_security')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_based_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Esposito