permissioner 0.0.1.beta → 0.0.2.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Guardfile +2 -0
- data/epl-v10.html +1 -2
- data/lib/permissioner/controller_additions.rb +2 -3
- data/lib/permissioner/matchers.rb +2 -2
- data/lib/permissioner/permission_configurer.rb +7 -19
- data/lib/permissioner/permission_service_additions.rb +12 -16
- data/lib/permissioner/version.rb +1 -1
- data/permissioner.gemspec +4 -2
- data/spec/permissioner/controller_additions_spec.rb +6 -7
- data/spec/permissioner/matchers_spec.rb +11 -6
- data/spec/permissioner/permission_configurer_spec.rb +28 -27
- data/spec/permissioner/permission_service_additions_spec.rb +86 -95
- data/spec/spec_helper.rb +0 -1
- metadata +13 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfc2e5ec9d5f94f5c6630cac9b25295e5d6c0730
|
4
|
+
data.tar.gz: 35ceaa2887957280d16025bf13da99d891d23685
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68a379955f1b30f03d356196495edc5bc3ba5a7f51cd6466e7723e453fcbcea5db11bad372a71fad1b6e2f9fab298af4adcc8a3cbd032bba50f8dcf6e147c01f
|
7
|
+
data.tar.gz: e2dd5c7b676575a23fe64207317e2af0ff00fbdc51df8f6442a2342bd8ffc4905989c11be269665a22e68f1732985704b15bbd85ae2fde09c283b685dfb36fa0
|
data/Guardfile
CHANGED
data/epl-v10.html
CHANGED
@@ -2,7 +2,7 @@ module Permissioner
|
|
2
2
|
module ControllerAdditions
|
3
3
|
|
4
4
|
def self.included(base)
|
5
|
-
base.helper_method :allow_action?, :allow_attribute
|
5
|
+
base.helper_method :allow_action?, :allow_attribute?, :permission_service
|
6
6
|
base.delegate :allow_action?, :allow_attribute?, to: :permission_service
|
7
7
|
end
|
8
8
|
|
@@ -16,12 +16,11 @@ module Permissioner
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def permission_service
|
19
|
-
@permission_service ||= PermissionService.
|
19
|
+
@permission_service ||= PermissionService.new(current_user)
|
20
20
|
end
|
21
21
|
|
22
22
|
def current_resource
|
23
23
|
nil
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
26
|
end
|
@@ -9,8 +9,8 @@ RSpec::Matchers.define :allow_attribute do |*args|
|
|
9
9
|
permission_service.allow_attribute?(*args)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
RSpec::Matchers.define :
|
12
|
+
RSpec::Matchers.define :pass_filters do |controller, action, params={}|
|
13
13
|
match do |permission_service|
|
14
|
-
permission_service.passed_filters?(
|
14
|
+
permission_service.passed_filters?(controller, action, params)
|
15
15
|
end
|
16
16
|
end
|
@@ -26,28 +26,16 @@ module Permissioner
|
|
26
26
|
#
|
27
27
|
module PermissionConfigurer
|
28
28
|
|
29
|
-
|
29
|
+
attr_reader :current_user, :permission_service
|
30
30
|
delegate :allow_actions, :allow_attributes, :add_filter, to: :permission_service
|
31
31
|
|
32
|
-
module ClassMethods
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def create permission_service, current_user
|
41
|
-
permission_configurer= self.new
|
42
|
-
permission_configurer.permission_service = permission_service
|
43
|
-
permission_configurer.current_user = current_user
|
44
|
-
permission_configurer.configure_permissions
|
45
|
-
permission_configurer
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.included(base)
|
50
|
-
base.extend(ClassMethods)
|
33
|
+
# Expects an instance of a class including module Permissioner::PermissionServiceAdditions acting as
|
34
|
+
# permission service and current signed in user.
|
35
|
+
def initialize permission_service, current_user
|
36
|
+
@permission_service = permission_service
|
37
|
+
@current_user = current_user
|
38
|
+
configure_permissions
|
51
39
|
end
|
52
40
|
|
53
41
|
# Should be overwritten by the including class and is called during initialization in ::create.
|
@@ -1,21 +1,13 @@
|
|
1
1
|
module Permissioner
|
2
2
|
module PermissionServiceAdditions
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
def create current_user
|
7
|
-
permission_service = self.new
|
8
|
-
permission_service.current_user = current_user
|
9
|
-
permission_service.configure_permissions
|
10
|
-
permission_service
|
11
|
-
end
|
12
|
-
end
|
4
|
+
attr_accessor :current_user
|
13
5
|
|
14
|
-
def
|
15
|
-
|
6
|
+
def initialize current_user=nil
|
7
|
+
@current_user = current_user
|
8
|
+
configure_permissions
|
16
9
|
end
|
17
10
|
|
18
|
-
attr_accessor :current_user
|
19
11
|
|
20
12
|
def allow_action?(controller, action, resource = nil)
|
21
13
|
allowed = @allow_all || (@allowed_actions && @allowed_actions[[controller.to_s, action.to_s]])
|
@@ -55,7 +47,7 @@ module Permissioner
|
|
55
47
|
#You can allow a single action or multiple actions at once:
|
56
48
|
#
|
57
49
|
# allow_actions :comments, :index
|
58
|
-
#
|
50
|
+
# allow_actions [:comments, :posts], [:index, :create, :update]
|
59
51
|
#
|
60
52
|
#If a block is given it is stored for the given action and will be evaluated every time the authorization for the
|
61
53
|
#action runs. If the block returns true the action is allowed otherwise not. The current_resource will be put
|
@@ -74,7 +66,11 @@ module Permissioner
|
|
74
66
|
@allowed_attributes ||= {}
|
75
67
|
Array(resources).each do |resource|
|
76
68
|
@allowed_attributes[resource] ||= []
|
77
|
-
|
69
|
+
if attributes.is_a?(Hash)
|
70
|
+
@allowed_attributes[resource] << attributes
|
71
|
+
else
|
72
|
+
@allowed_attributes[resource] += Array(attributes)
|
73
|
+
end
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
@@ -89,11 +85,11 @@ module Permissioner
|
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
92
|
-
# Configures permissions by
|
88
|
+
# Configures permissions by instantiate a new object of the given class which is intended to include
|
93
89
|
# the module Permissioner::PermissionConfigurer.
|
94
90
|
#
|
95
91
|
def configure configurer_class
|
96
|
-
configurer_class.
|
92
|
+
configurer_class.new(self, current_user)
|
97
93
|
end
|
98
94
|
|
99
95
|
# Should be overwritten by the including class and is called during initialization in ::create.
|
data/lib/permissioner/version.rb
CHANGED
data/permissioner.gemspec
CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Permissioner::VERSION
|
9
9
|
gem.authors = ["Daniel Grawunder, Christian Mierich"]
|
10
10
|
gem.email = ["gramie.sw@gmail.com"]
|
11
|
-
gem.
|
11
|
+
gem.homepage = "https://github.com/gramie-sw/permissioner"
|
12
|
+
gem.description = %q{A Ruby on Rails authorization gem}
|
12
13
|
gem.summary = %q{An easy to use authorization solution for Ruby on Rails.}
|
14
|
+
gem.license = "EPL 1.0"
|
13
15
|
|
14
16
|
gem.files = `git ls-files`.split($/)
|
15
17
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
@@ -18,5 +20,5 @@ Gem::Specification.new do |gem|
|
|
18
20
|
|
19
21
|
gem.add_development_dependency "rspec", "~> 2.13"
|
20
22
|
gem.add_development_dependency "activesupport", "~>3.2"
|
21
|
-
gem.add_development_dependency "guard-rspec", "~>
|
23
|
+
gem.add_development_dependency "guard-rspec", "~>3.0.1"
|
22
24
|
end
|
@@ -16,8 +16,8 @@ describe Permissioner::ControllerAdditions do
|
|
16
16
|
@clazz = Class.new
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'should
|
20
|
-
@clazz.should_receive(:helper_method).with(:allow_action?, :allow_attribute
|
19
|
+
it 'should set view helpers' do
|
20
|
+
@clazz.should_receive(:helper_method).with(:allow_action?, :allow_attribute?, :permission_service)
|
21
21
|
@clazz.send(:include, Permissioner::ControllerAdditions)
|
22
22
|
end
|
23
23
|
|
@@ -85,14 +85,14 @@ describe Permissioner::ControllerAdditions do
|
|
85
85
|
permission_service_1.should eq permission_service_2
|
86
86
|
end
|
87
87
|
|
88
|
-
it 'should create PermissionService by calling PermissionService::
|
89
|
-
PermissionService.should_receive(:
|
88
|
+
it 'should create PermissionService by calling PermissionService::new' do
|
89
|
+
PermissionService.should_receive(:new)
|
90
90
|
@controller.permission_service
|
91
91
|
end
|
92
92
|
|
93
|
-
it 'should pass current_user to PermissionService::
|
93
|
+
it 'should pass current_user to PermissionService::initialize' do
|
94
94
|
@controller.should_receive(:current_user).and_return('current_user')
|
95
|
-
PermissionService.should_receive(:
|
95
|
+
PermissionService.should_receive(:new).with('current_user')
|
96
96
|
@controller.permission_service
|
97
97
|
end
|
98
98
|
end
|
@@ -103,5 +103,4 @@ describe Permissioner::ControllerAdditions do
|
|
103
103
|
@controller.current_resource.should be_nil
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
107
106
|
end
|
@@ -32,16 +32,21 @@ describe 'matchers' do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe '
|
35
|
+
describe 'pass_filters' do
|
36
36
|
|
37
|
-
it 'should delegate call to PermissionService#
|
38
|
-
@permission_service.should_receive(:passed_filters?).with(:comment, :user_id, :
|
39
|
-
@permission_service.should
|
37
|
+
it 'should delegate call to PermissionService#passed_filters?' do
|
38
|
+
@permission_service.should_receive(:passed_filters?).with(:comment, :user_id, :block).and_return(true)
|
39
|
+
@permission_service.should pass_filters :comment, :user_id, :block
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'should return false when PermissionService#
|
42
|
+
it 'should return false when PermissionService#passed_filters? returns false' do
|
43
43
|
@permission_service.should_receive(:passed_filters?).and_return(false)
|
44
|
-
@permission_service.should_not
|
44
|
+
@permission_service.should_not pass_filters
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should set empty Hash as default value for params argument' do
|
48
|
+
@permission_service.should_receive(:passed_filters?).with(:comment, :user_id, {}).and_return(true)
|
49
|
+
@permission_service.should pass_filters :comment, :user_id
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
@@ -2,59 +2,60 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Permissioner::PermissionConfigurer do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
let(:permission_configurer_class) do
|
6
|
+
permission_configurer_class = Class.new
|
7
|
+
permission_configurer_class.send(:include, Permissioner::PermissionConfigurer)
|
8
|
+
permission_configurer_class
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'delegation' do
|
12
|
+
let(:permission_service) { double('PermissionService') }
|
13
|
+
let(:permission_configurer) { permission_configurer_class.new(permission_service, 'current_user') }
|
12
14
|
|
13
15
|
it 'should delegate call to allow_actions to permission_service' do
|
14
|
-
|
15
|
-
|
16
|
+
permission_service.should_receive(:allow_actions).with(:comments, :index)
|
17
|
+
permission_configurer.allow_actions(:comments, :index)
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'should delegate call to allow_attributes to permission_service' do
|
19
|
-
|
20
|
-
|
21
|
+
permission_service.should_receive(:allow_attributes).with(:comment, [:user_id, :text])
|
22
|
+
permission_configurer.allow_attributes(:comment, [:user_id, :text])
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'should delegate call to add_filter to permission_service' do
|
24
|
-
|
25
|
-
|
26
|
+
block = Proc.new {}
|
27
|
+
permission_service.should_receive(:add_filter).with(:comments, :create, &block)
|
28
|
+
permission_configurer.add_filter(:comments, :create, &block)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
|
-
|
32
|
+
context 'setters' do
|
33
|
+
subject(:permission_configurer){ permission_configurer_class.new(nil, nil) }
|
30
34
|
|
31
|
-
it 'should
|
32
|
-
|
33
|
-
clazz.should_receive(:extend).with(Permissioner::PermissionConfigurer::ClassMethods)
|
34
|
-
clazz.send(:include, Permissioner::PermissionConfigurer)
|
35
|
+
it 'should respond_to permission_service' do
|
36
|
+
should respond_to(:permission_service)
|
35
37
|
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '::create' do
|
39
38
|
|
40
|
-
it 'should
|
41
|
-
|
42
|
-
permission_service.class.included_modules.should include(Permissioner::PermissionConfigurer)
|
39
|
+
it 'should respond_to current_user' do
|
40
|
+
should respond_to(:current_user)
|
43
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#initialize' do
|
44
45
|
|
45
46
|
it 'should set permission_service' do
|
46
|
-
|
47
|
-
|
47
|
+
permission_configurer = permission_configurer_class.new('permission_service', nil)
|
48
|
+
permission_configurer.permission_service.should eq 'permission_service'
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'should set current_user' do
|
51
|
-
|
52
|
-
|
52
|
+
permission_configurer = permission_configurer_class.new(nil, 'current_user')
|
53
|
+
permission_configurer.current_user.should eq 'current_user'
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'should call configure_permissions current_user' do
|
56
|
-
|
57
|
-
|
57
|
+
permission_configurer_class.any_instance.should_receive(:configure_permissions)
|
58
|
+
permission_configurer_class.new(nil, nil)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -2,61 +2,45 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Permissioner::PermissionServiceAdditions do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
let(:permission_service_class) do
|
6
|
+
permission_service_class = Class.new
|
7
|
+
permission_service_class.send(:include, Permissioner::PermissionServiceAdditions)
|
8
|
+
permission_service_class
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
let(:permission_service) { permission_service_class.new }
|
12
12
|
|
13
|
-
|
14
|
-
clazz = Class.new
|
15
|
-
clazz.should_receive(:extend).with(Permissioner::PermissionServiceAdditions::ClassMethods)
|
16
|
-
clazz.send(:include, Permissioner::PermissionServiceAdditions)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '::create' do
|
13
|
+
describe '#initialize' do
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it 'should return permission_service instance' do
|
27
|
-
permission_service = @permission_service_class.create(nil)
|
28
|
-
permission_service.class.included_modules.should include(Permissioner::PermissionServiceAdditions)
|
15
|
+
it 'should call configure_permissions' do
|
16
|
+
permission_service_class.any_instance.should_receive(:configure_permissions).once
|
17
|
+
permission_service_class.new
|
29
18
|
end
|
30
19
|
|
31
20
|
it 'should set current_user' do
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should call configure_permissions current_user' do
|
37
|
-
@permission_service_class.any_instance.should_receive(:configure_permissions)
|
38
|
-
@permission_service_class.create(nil)
|
21
|
+
permission_service = permission_service_class.new 'current_user'
|
22
|
+
permission_service.current_user.should eq 'current_user'
|
39
23
|
end
|
40
24
|
end
|
41
25
|
|
42
26
|
describe '#allow_action?' do
|
43
27
|
|
44
28
|
it 'should return true if @allow_all is true' do
|
45
|
-
|
46
|
-
|
29
|
+
permission_service.allow_all
|
30
|
+
permission_service.allow_action?(:comments, :index).should be_true
|
47
31
|
end
|
48
32
|
|
49
33
|
context 'when no block given' do
|
50
34
|
|
51
35
|
it 'should return true if given action allowed' do
|
52
|
-
|
53
|
-
|
36
|
+
permission_service.allow_actions :comments, :index
|
37
|
+
permission_service.allow_action?(:comments, :index).should be_true
|
54
38
|
end
|
55
39
|
|
56
40
|
it 'should return false if given action not allowed' do
|
57
|
-
|
58
|
-
|
59
|
-
|
41
|
+
permission_service.allow_action?(:comments, :index).should be_false
|
42
|
+
permission_service.allow_actions :comments, :create
|
43
|
+
permission_service.allow_action?(:comments, :index).should be_false
|
60
44
|
end
|
61
45
|
end
|
62
46
|
|
@@ -65,33 +49,33 @@ describe Permissioner::PermissionServiceAdditions do
|
|
65
49
|
it 'should call block for given action when ressource is given' do
|
66
50
|
block = Proc.new {}
|
67
51
|
block.should_receive(:call)
|
68
|
-
|
69
|
-
|
52
|
+
permission_service.allow_actions :comments, :index, &block
|
53
|
+
permission_service.allow_action?(:comments, :index, 'resource')
|
70
54
|
end
|
71
55
|
|
72
56
|
it 'should not call block for given action but no ressource is given' do
|
73
57
|
block = Proc.new {}
|
74
58
|
block.should_receive(:call).never
|
75
|
-
|
76
|
-
|
59
|
+
permission_service.allow_actions :comments, :index, &block
|
60
|
+
permission_service.allow_action?(:comments, :index)
|
77
61
|
end
|
78
62
|
|
79
63
|
it 'should return true when block returns true' do
|
80
64
|
block = Proc.new { true }
|
81
|
-
|
82
|
-
|
65
|
+
permission_service.allow_actions :comments, :index, &block
|
66
|
+
permission_service.allow_action?(:comments, :index, 'resource').should be_true
|
83
67
|
end
|
84
68
|
|
85
69
|
it 'should return false when block returns false' do
|
86
70
|
block = Proc.new { false }
|
87
|
-
|
88
|
-
|
71
|
+
permission_service.allow_actions :comments, :index, &block
|
72
|
+
permission_service.allow_action?(:comments, :index, 'resource').should be_false
|
89
73
|
end
|
90
74
|
|
91
75
|
it 'should return false when no ressource given' do
|
92
76
|
block = Proc.new { true }
|
93
|
-
|
94
|
-
|
77
|
+
permission_service.allow_actions :comments, :index, &block
|
78
|
+
permission_service.allow_action?(:comments, :index).should be_false
|
95
79
|
end
|
96
80
|
end
|
97
81
|
end
|
@@ -99,47 +83,47 @@ describe Permissioner::PermissionServiceAdditions do
|
|
99
83
|
describe '#passed_filters?' do
|
100
84
|
|
101
85
|
it 'should return true when all blocks for given controller and action returns true' do
|
102
|
-
|
103
|
-
|
86
|
+
permission_service.add_filter(:comments, :create, &Proc.new { true })
|
87
|
+
permission_service.passed_filters?(:comments, :create, 'params').should be_true
|
104
88
|
end
|
105
89
|
|
106
90
|
it 'should return true when no filters are added at all' do
|
107
|
-
|
91
|
+
permission_service.passed_filters?(:comments, :create, 'params').should be_true
|
108
92
|
end
|
109
93
|
|
110
94
|
it 'should return true when for given controller and action no filters has been added' do
|
111
|
-
|
112
|
-
|
95
|
+
permission_service.add_filter(:comments, :update, &Proc.new {})
|
96
|
+
permission_service.passed_filters?(:comments, :create, 'params').should be_true
|
113
97
|
end
|
114
98
|
|
115
99
|
it 'should return false when at least one block for given controller and action returns false' do
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
100
|
+
permission_service.add_filter(:comments, :create, &Proc.new { true })
|
101
|
+
permission_service.add_filter(:comments, :create, &Proc.new { false })
|
102
|
+
permission_service.add_filter(:comments, :create, &Proc.new { true })
|
103
|
+
permission_service.passed_filters?(:comments, :create, 'params').should be_false
|
120
104
|
end
|
121
105
|
|
122
106
|
it 'should pass params to the given block' do
|
123
107
|
params = Object.new
|
124
|
-
|
125
|
-
|
108
|
+
permission_service.add_filter(:comments, :create, &Proc.new { |p| p.object_id.should eq params.object_id })
|
109
|
+
permission_service.passed_filters?(:comments, :create, params)
|
126
110
|
end
|
127
111
|
end
|
128
112
|
|
129
113
|
describe '#allow_attributes?' do
|
130
114
|
|
131
115
|
it 'should return true when @allow_all is true' do
|
132
|
-
|
133
|
-
|
116
|
+
permission_service.allow_all
|
117
|
+
permission_service.allow_attribute?(:comment, :user_id).should be_true
|
134
118
|
end
|
135
119
|
|
136
120
|
it 'should return true when param is allowed' do
|
137
|
-
|
138
|
-
|
121
|
+
permission_service.allow_attributes(:comment, :user_id)
|
122
|
+
permission_service.allow_attribute?(:comment, :user_id).should be_true
|
139
123
|
end
|
140
124
|
|
141
125
|
it 'should return false when param not allowed' do
|
142
|
-
|
126
|
+
permission_service.allow_attribute?(:comment, :user_id).should be_false
|
143
127
|
end
|
144
128
|
end
|
145
129
|
|
@@ -148,41 +132,41 @@ describe Permissioner::PermissionServiceAdditions do
|
|
148
132
|
it 'should call permit! on given params when @allow_all is true' do
|
149
133
|
params = double('params')
|
150
134
|
params.should_receive(:permit!)
|
151
|
-
|
152
|
-
|
135
|
+
permission_service.allow_all
|
136
|
+
permission_service.permit_params!(params)
|
153
137
|
end
|
154
138
|
|
155
139
|
it 'should call permit on allowed params' do
|
156
140
|
params = {comment: {user_id: '12', text: 'text', date: 'date'}, post: {title: 'title', content: 'content'}}
|
157
|
-
|
158
|
-
|
141
|
+
permission_service.allow_attributes(:comment, [:user_id, :text])
|
142
|
+
permission_service.allow_attributes(:post, [:title, :content])
|
159
143
|
params[:comment].should_receive(:respond_to?).with(:permit).and_return(true)
|
160
144
|
params[:comment].should_receive(:permit).with(:user_id, :text)
|
161
145
|
params[:post].should_receive(:permit).with(:title, :content)
|
162
|
-
|
146
|
+
permission_service.permit_params!(params)
|
163
147
|
end
|
164
148
|
end
|
165
149
|
|
166
150
|
describe '#allow_all' do
|
167
151
|
|
168
152
|
it 'should set @allow_all to true' do
|
169
|
-
|
170
|
-
|
153
|
+
permission_service.allow_all
|
154
|
+
permission_service.instance_variable_get(:@allow_all).should be_true
|
171
155
|
end
|
172
156
|
end
|
173
157
|
|
174
158
|
describe '#allow_actions' do
|
175
159
|
|
176
160
|
it 'should add controller and action to @allowed_actions' do
|
177
|
-
|
178
|
-
allowed_actions =
|
161
|
+
permission_service.allow_actions :comments, :index
|
162
|
+
allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
|
179
163
|
allowed_actions.count.should eq 1
|
180
164
|
allowed_actions[['comments', 'index']].should be_true
|
181
165
|
end
|
182
166
|
|
183
167
|
it 'should add controllers and action to @allowed_actions when multiple given' do
|
184
|
-
|
185
|
-
allowed_actions =
|
168
|
+
permission_service.allow_actions([:comments, :users], [:index, :create])
|
169
|
+
allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
|
186
170
|
allowed_actions.count.should eq 4
|
187
171
|
allowed_actions[['comments', 'index']].should be_true
|
188
172
|
allowed_actions[['comments', 'create']].should be_true
|
@@ -192,8 +176,8 @@ describe Permissioner::PermissionServiceAdditions do
|
|
192
176
|
|
193
177
|
it 'should add controllers and action to @allowed_actions and store block when given' do
|
194
178
|
block = Proc.new {}
|
195
|
-
|
196
|
-
allowed_actions =
|
179
|
+
permission_service.allow_actions(:comments, :edit, &block)
|
180
|
+
allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
|
197
181
|
allowed_actions[['comments', 'edit']].object_id.should eq block.object_id
|
198
182
|
end
|
199
183
|
end
|
@@ -201,63 +185,70 @@ describe Permissioner::PermissionServiceAdditions do
|
|
201
185
|
describe '#allow_attributes' do
|
202
186
|
|
203
187
|
it 'should add resource and attribute to @allowed_params' do
|
204
|
-
|
205
|
-
allowed_params =
|
188
|
+
permission_service.allow_attributes :comment, :text
|
189
|
+
allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
|
206
190
|
allowed_params.count.should eq 1
|
207
191
|
allowed_params[:comment].should eq [:text]
|
208
192
|
end
|
209
193
|
|
210
|
-
it 'should add resource and
|
211
|
-
|
212
|
-
allowed_params =
|
194
|
+
it 'should add resource and attributes to @allowed_params if multiple given' do
|
195
|
+
permission_service.allow_attributes [:comment, :post], [:user, :text]
|
196
|
+
allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
|
213
197
|
allowed_params.count.should eq 2
|
214
198
|
allowed_params[:comment].should eq [:user, :text]
|
215
199
|
allowed_params[:post].should eq [:user, :text]
|
216
200
|
end
|
201
|
+
|
202
|
+
it 'should add resource and attributes to @allowed_params if attributes is a Hash' do
|
203
|
+
permission_service.allow_attributes :comment, {attributes: [:user, :text]}
|
204
|
+
allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
|
205
|
+
allowed_params.count.should eq 1
|
206
|
+
allowed_params[:comment].should eq [{attributes: [:user, :text]}]
|
207
|
+
end
|
217
208
|
end
|
218
209
|
|
219
210
|
describe '#add_filter' do
|
220
211
|
|
221
212
|
it 'should add given block to @filters addressed by controller and action' do
|
222
213
|
block = Proc.new {}
|
223
|
-
|
224
|
-
filter_list =
|
214
|
+
permission_service.add_filter(:comments, :create, &block)
|
215
|
+
filter_list = permission_service.instance_variable_get(:@filters)[['comments', 'create']]
|
225
216
|
filter_list.count.should eq 1
|
226
217
|
filter_list.should include block
|
227
218
|
end
|
228
219
|
|
229
220
|
it 'should add given block to @filters addressed by controller and action when multiple given' do
|
230
221
|
block = Proc.new {}
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
222
|
+
permission_service.add_filter([:comments, :posts], [:create, :update], &block)
|
223
|
+
permission_service.instance_variable_get(:@filters)[['comments', 'create']].should include block
|
224
|
+
permission_service.instance_variable_get(:@filters)[['comments', 'update']].should include block
|
225
|
+
permission_service.instance_variable_get(:@filters)[['posts', 'create']].should include block
|
226
|
+
permission_service.instance_variable_get(:@filters)[['posts', 'update']].should include block
|
236
227
|
end
|
237
228
|
|
238
229
|
it 'should add multiple blocks to @filters addressed by controller and action' do
|
239
230
|
block_1 = Proc.new { 'block 1' }
|
240
231
|
block_2 = Proc.new { 'block 2' }
|
241
|
-
|
242
|
-
|
243
|
-
filter_list =
|
232
|
+
permission_service.add_filter(:comments, :create, &block_1)
|
233
|
+
permission_service.add_filter(:comments, :create, &block_2)
|
234
|
+
filter_list = permission_service.instance_variable_get(:@filters)[['comments', 'create']]
|
244
235
|
filter_list.count.should eq 2
|
245
236
|
filter_list.should include block_1
|
246
237
|
filter_list.should include block_2
|
247
238
|
end
|
248
239
|
|
249
240
|
it 'should rails exception when no block given' do
|
250
|
-
expect {
|
241
|
+
expect { permission_service.add_filter(:comments, :index) }.to raise_error('no block given')
|
251
242
|
end
|
252
243
|
end
|
253
244
|
|
254
245
|
describe 'configure' do
|
255
246
|
|
256
|
-
it 'should
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
247
|
+
it 'should create new instance of given configurer class' do
|
248
|
+
permission_service.stub(:current_user).and_return('current_user')
|
249
|
+
configurer_class = double('permission_configurer')
|
250
|
+
configurer_class.should_receive(:new).with(permission_service, 'current_user')
|
251
|
+
permission_service.configure(configurer_class)
|
252
|
+
end
|
261
253
|
end
|
262
|
-
end
|
263
254
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: permissioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease: 6
|
4
|
+
version: 0.0.2.beta
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Grawunder, Christian Mierich
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,20 +41,18 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: guard-rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 3.0.1
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
description: A Ruby on
|
54
|
+
version: 3.0.1
|
55
|
+
description: A Ruby on Rails authorization gem
|
63
56
|
email:
|
64
57
|
- gramie.sw@gmail.com
|
65
58
|
executables: []
|
@@ -89,29 +82,29 @@ files:
|
|
89
82
|
- spec/permissioner/permission_configurer_spec.rb
|
90
83
|
- spec/permissioner/permission_service_additions_spec.rb
|
91
84
|
- spec/spec_helper.rb
|
92
|
-
homepage:
|
93
|
-
licenses:
|
85
|
+
homepage: https://github.com/gramie-sw/permissioner
|
86
|
+
licenses:
|
87
|
+
- EPL 1.0
|
88
|
+
metadata: {}
|
94
89
|
post_install_message:
|
95
90
|
rdoc_options: []
|
96
91
|
require_paths:
|
97
92
|
- lib
|
98
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
94
|
requirements:
|
101
|
-
- -
|
95
|
+
- - '>='
|
102
96
|
- !ruby/object:Gem::Version
|
103
97
|
version: '0'
|
104
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
99
|
requirements:
|
107
|
-
- -
|
100
|
+
- - '>'
|
108
101
|
- !ruby/object:Gem::Version
|
109
102
|
version: 1.3.1
|
110
103
|
requirements: []
|
111
104
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
105
|
+
rubygems_version: 2.0.3
|
113
106
|
signing_key:
|
114
|
-
specification_version:
|
107
|
+
specification_version: 4
|
115
108
|
summary: An easy to use authorization solution for Ruby on Rails.
|
116
109
|
test_files:
|
117
110
|
- spec/permissioner/controller_additions_spec.rb
|