arrthorizer 0.1.0.pre2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/arrthorizer.rb +20 -1
- data/lib/arrthorizer/group.rb +26 -0
- data/lib/arrthorizer/rails/controller_configuration.rb +5 -2
- data/lib/arrthorizer/role.rb +1 -1
- data/lib/arrthorizer/version.rb +1 -1
- data/lib/generators/arrthorizer/install/templates/config.yml +4 -3
- data/spec/integration/group/initialize_spec.rb +11 -0
- data/spec/{controllers → integration}/some_controller_spec.rb +68 -1
- data/spec/internal/app/roles/another_group.rb +1 -0
- data/spec/internal/app/roles/some_group.rb +1 -0
- data/spec/internal/config/application.rb +1 -1
- data/spec/internal/config/environment.rb +1 -1
- data/spec/internal/config/initializers/arrthorizer.rb +9 -0
- data/spec/permission/grant_spec.rb +1 -1
- data/spec/privilege/accessible_to_spec.rb +2 -2
- data/spec/privilege/initialize_spec.rb +1 -1
- data/spec/privilege/make_accessible_to_spec.rb +2 -2
- data/spec/role/get_spec.rb +16 -0
- metadata +35 -16
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
[![
|
2
|
-
(
|
1
|
+
[![Code Climate](https://codeclimate.com/github/BUS-OGD/arrthorizer.png)](https://codeclimate.com/github/BUS-OGD/arrthorizer)
|
2
|
+
[![Build Status](https://travis-ci.org/BUS-OGD/arrthorizer.png)](https://travis-ci.org/BUS-OGD/arrthorizer)
|
3
3
|
|
4
4
|
# Arrthorizer
|
5
5
|
|
data/lib/arrthorizer.rb
CHANGED
@@ -7,6 +7,7 @@ module Arrthorizer
|
|
7
7
|
|
8
8
|
autoload :Role, "arrthorizer/role"
|
9
9
|
autoload :ContextRole, "arrthorizer/context_role"
|
10
|
+
autoload :Group, "arrthorizer/group"
|
10
11
|
|
11
12
|
autoload :Permission, "arrthorizer/permission"
|
12
13
|
autoload :Privilege, "arrthorizer/privilege"
|
@@ -23,6 +24,24 @@ module Arrthorizer
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.configure(&block)
|
26
|
-
self.
|
27
|
+
self.instance_eval(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Inject a dependency for Arrthorizer's Groups feature.
|
32
|
+
# The provided object needs to be able to respond_to :is_member_of?
|
33
|
+
# The is_member_of? function is expected to return a boolean-like
|
34
|
+
# object which represents whether or not the user is a member of the
|
35
|
+
# provided Group
|
36
|
+
def self.check_group_membership_using(object)
|
37
|
+
if object.respond_to?(:is_member_of?)
|
38
|
+
@membership_service = object
|
39
|
+
else
|
40
|
+
raise "Arrthorizer cannot check role membership using #{object.inspect}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.membership_service
|
45
|
+
@membership_service
|
27
46
|
end
|
28
47
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
##
|
2
|
+
# This is the class of all Groups. A Group is a role that does not depend
|
3
|
+
# on context, but rather on membership - a user can be made a member
|
4
|
+
# of such a role. This might be related to that person's role in the
|
5
|
+
# organization, for example.
|
6
|
+
module Arrthorizer
|
7
|
+
class Group < Role
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
|
13
|
+
Role.register(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def applies_to_user?(user, _)
|
17
|
+
is_member?(user)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def is_member?(user)
|
22
|
+
Arrthorizer.membership_service.is_member_of?(user, self)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -13,9 +13,12 @@ module Arrthorizer
|
|
13
13
|
self.defaults_block = block
|
14
14
|
end
|
15
15
|
|
16
|
-
def for_action(
|
17
|
-
|
16
|
+
def for_action(*actions, &block)
|
17
|
+
actions.each do |action|
|
18
|
+
add_action_block(action, &block)
|
19
|
+
end
|
18
20
|
end
|
21
|
+
alias_method :for_actions, :for_action
|
19
22
|
|
20
23
|
def block_for(action)
|
21
24
|
action_blocks.fetch(action) { defaults_block }
|
data/lib/arrthorizer/role.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Arrthorizer
|
3
3
|
class Role
|
4
4
|
# Template method: This method is implemented in the
|
5
|
-
# ContextRole subclasses.
|
5
|
+
# ContextRole subclasses and Group.
|
6
6
|
def applies_to_user?(user, context = {})
|
7
7
|
raise NotImplementedError, "#{self.name} does not implement #applies_to_user?(user, context)"
|
8
8
|
end
|
data/lib/arrthorizer/version.rb
CHANGED
@@ -11,9 +11,10 @@
|
|
11
11
|
# Let's also assume that we have Roles for Forum::TopicStarter and Forum::Administrators.
|
12
12
|
# ForumTopicStarters may be allowed to delete any topics they started and update them in
|
13
13
|
# whatever way they deem relevant, but not change any topics they did not start themselves. This
|
14
|
-
# means the role would be a ContextRole.
|
15
|
-
#
|
16
|
-
#
|
14
|
+
# means the role would be a ContextRole. The administrators can do anything they bloody well
|
15
|
+
# please with any topic at all (therefore, the role would be a Group). Let's also assume
|
16
|
+
# you have a LoggedInUser role which allows anyone to see any topic or start a new one, as
|
17
|
+
# long as they're logged in.
|
17
18
|
#
|
18
19
|
# We would define these privileges as follows:
|
19
20
|
#
|
@@ -4,7 +4,7 @@ describe SomeController do
|
|
4
4
|
let(:action) { Arrthorizer::Rails::ControllerAction.fetch("some#some_action") }
|
5
5
|
let(:other_action) { Arrthorizer::Rails::ControllerAction.fetch("some#other_action") }
|
6
6
|
|
7
|
-
describe :some_action do
|
7
|
+
describe :some_action, type: :controller do
|
8
8
|
let!(:privilege) { action.privilege }
|
9
9
|
let!(:current_user) { double("user") }
|
10
10
|
|
@@ -12,6 +12,57 @@ describe SomeController do
|
|
12
12
|
controller.stub(:current_user) { current_user }
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "group roles" do
|
16
|
+
let!(:group) { Arrthorizer::Group.new("some group") }
|
17
|
+
|
18
|
+
context "when the role is linked to the privilege" do
|
19
|
+
before do
|
20
|
+
Arrthorizer::Permission.grant(privilege, to: group)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when I am a member of the required group" do
|
24
|
+
before do
|
25
|
+
add_user_to_group(current_user, group)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "succeeds" do
|
29
|
+
get :some_action
|
30
|
+
|
31
|
+
response.should be_success
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when I am not a member of the required group" do
|
36
|
+
before do
|
37
|
+
remove_user_from_group(current_user, group)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "fails" do
|
41
|
+
get :some_action
|
42
|
+
|
43
|
+
response.should be_forbidden
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when I am only a member of an unrelated group" do
|
48
|
+
let(:other_group) { Arrthorizer::Group.new("other group") }
|
49
|
+
|
50
|
+
before do
|
51
|
+
other_privilege = other_action.privilege
|
52
|
+
Arrthorizer::Permission.grant(other_privilege, to: other_group)
|
53
|
+
remove_user_from_group(current_user, group)
|
54
|
+
add_user_to_group(current_user, other_group)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "fails" do
|
58
|
+
get :some_action
|
59
|
+
|
60
|
+
response.should be_forbidden
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
15
66
|
describe "context roles" do
|
16
67
|
let!(:context_role) do
|
17
68
|
configure_context_role do |user, context|
|
@@ -76,4 +127,20 @@ describe SomeController do
|
|
76
127
|
role.stub(:applies_to_user?, &block)
|
77
128
|
end
|
78
129
|
end
|
130
|
+
|
131
|
+
def add_user_to_group( user, group )
|
132
|
+
stub_membership_with(user, group) do
|
133
|
+
true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def remove_user_from_group( user, group )
|
138
|
+
stub_membership_with(user, group) do
|
139
|
+
false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def stub_membership_with(user, group, &block)
|
144
|
+
Arrthorizer.membership_service.stub(:is_member_of?).with(user, group, &block)
|
145
|
+
end
|
79
146
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
AnotherGroup = Arrthorizer::Group.new('antother_group')
|
@@ -0,0 +1 @@
|
|
1
|
+
SomeGroup = Arrthorizer::Group.new('some_group')
|
@@ -15,7 +15,7 @@ if defined?(Bundler)
|
|
15
15
|
# Bundler.require(:default, :assets, Rails.env)
|
16
16
|
end
|
17
17
|
|
18
|
-
module
|
18
|
+
module TestArrthorizer
|
19
19
|
class Application < Rails::Application
|
20
20
|
# Settings in config/environments/* take precedence over those specified here.
|
21
21
|
# Application configuration should go into files in config/initializers
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Arrthorizer::Permission do
|
4
4
|
describe :grant do
|
5
5
|
let(:privilege) { Arrthorizer::Privilege.new(name: "privilege") }
|
6
|
-
let(:role) {
|
6
|
+
let(:role) { Arrthorizer::Group.new("role") }
|
7
7
|
|
8
8
|
it "adds the role to the privilege set" do
|
9
9
|
Arrthorizer::Permission.grant(privilege, to: role)
|
@@ -3,8 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe Arrthorizer::Privilege do
|
4
4
|
subject(:privilege) { Arrthorizer::Privilege.new(name: "some privilege") }
|
5
5
|
|
6
|
-
let(:role) {
|
7
|
-
let(:other_role) {
|
6
|
+
let(:role) { SomeGroup }
|
7
|
+
let(:other_role) { AnotherGroup }
|
8
8
|
|
9
9
|
describe :accessible_to? do
|
10
10
|
context "when a Role was configured to have access to this privilege" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Arrthorizer::Privilege do
|
4
4
|
describe :make_accessible_to do
|
5
5
|
let(:privilege) { Arrthorizer::Privilege.new(name: "privilege") }
|
6
|
-
let(:role) {
|
6
|
+
let(:role) { SomeGroup }
|
7
7
|
|
8
8
|
it "makes the privilege accessible to the role" do
|
9
9
|
expect {
|
@@ -12,7 +12,7 @@ describe Arrthorizer::Privilege do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "does not make it accessible to a different role" do
|
15
|
-
unrelated_role =
|
15
|
+
unrelated_role = Arrthorizer::Group.new("unrelated role")
|
16
16
|
|
17
17
|
expect {
|
18
18
|
privilege.make_accessible_to(role)
|
data/spec/role/get_spec.rb
CHANGED
@@ -25,5 +25,21 @@ describe Arrthorizer::Role do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
context "fetching Groups" do
|
30
|
+
let(:expected_role) { SomeGroup } # provided by the internal Rails app
|
31
|
+
|
32
|
+
context "when a Group is provided" do
|
33
|
+
it_behaves_like "finding the right Role" do
|
34
|
+
let(:arg) { expected_role }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when a String representing a Group is provided" do
|
39
|
+
it_behaves_like "finding the right Role" do
|
40
|
+
let(:arg) { expected_role.to_key }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arrthorizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- René van den Berg
|
@@ -9,25 +10,28 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rails
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- - '>='
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- - '>='
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: combustion
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
36
|
- - ~>
|
33
37
|
- !ruby/object:Gem::Version
|
@@ -35,6 +39,7 @@ dependencies:
|
|
35
39
|
type: :development
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
44
|
- - ~>
|
40
45
|
- !ruby/object:Gem::Version
|
@@ -42,29 +47,33 @@ dependencies:
|
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: sqlite3
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
|
-
- - '>='
|
52
|
+
- - ! '>='
|
47
53
|
- !ruby/object:Gem::Version
|
48
54
|
version: '0'
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
|
-
- - '>='
|
60
|
+
- - ! '>='
|
54
61
|
- !ruby/object:Gem::Version
|
55
62
|
version: '0'
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rspec-rails
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- - '>='
|
68
|
+
- - ! '>='
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- - '>='
|
76
|
+
- - ! '>='
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
description: Contextual authorization for your Rails (3+) application
|
@@ -88,6 +97,7 @@ files:
|
|
88
97
|
- lib/arrthorizer/context.rb
|
89
98
|
- lib/arrthorizer/context_builder.rb
|
90
99
|
- lib/arrthorizer/context_role.rb
|
100
|
+
- lib/arrthorizer/group.rb
|
91
101
|
- lib/arrthorizer/permission.rb
|
92
102
|
- lib/arrthorizer/privilege.rb
|
93
103
|
- lib/arrthorizer/rails.rb
|
@@ -109,9 +119,10 @@ files:
|
|
109
119
|
- spec/context_builder/build_spec.rb
|
110
120
|
- spec/context_role/to_key_spec.rb
|
111
121
|
- spec/context_spec.rb
|
112
|
-
- spec/
|
122
|
+
- spec/integration/group/initialize_spec.rb
|
113
123
|
- spec/integration/registry/missing_handler_spec.rb
|
114
124
|
- spec/integration/role_spec.rb
|
125
|
+
- spec/integration/some_controller_spec.rb
|
115
126
|
- spec/internal/app/assets/images/rails.png
|
116
127
|
- spec/internal/app/assets/javascripts/application.js
|
117
128
|
- spec/internal/app/assets/javascripts/test.js.coffee
|
@@ -123,7 +134,9 @@ files:
|
|
123
134
|
- spec/internal/app/helpers/test_helper.rb
|
124
135
|
- spec/internal/app/mailers/.gitkeep
|
125
136
|
- spec/internal/app/models/.gitkeep
|
137
|
+
- spec/internal/app/roles/another_group.rb
|
126
138
|
- spec/internal/app/roles/namespaced/context_role.rb
|
139
|
+
- spec/internal/app/roles/some_group.rb
|
127
140
|
- spec/internal/app/roles/unnamespaced_context_role.rb
|
128
141
|
- spec/internal/app/views/layouts/application.html.erb
|
129
142
|
- spec/internal/app/views/some/some_action.html.erb
|
@@ -132,6 +145,7 @@ files:
|
|
132
145
|
- spec/internal/config/boot.rb
|
133
146
|
- spec/internal/config/database.yml
|
134
147
|
- spec/internal/config/environment.rb
|
148
|
+
- spec/internal/config/initializers/arrthorizer.rb
|
135
149
|
- spec/internal/config/routes.rb
|
136
150
|
- spec/internal/db/schema.rb
|
137
151
|
- spec/internal/log/.gitignore
|
@@ -156,26 +170,27 @@ files:
|
|
156
170
|
- spec/support/reset.rb
|
157
171
|
homepage: https://github.com/BUS-ogd/arrthorizer
|
158
172
|
licenses: []
|
159
|
-
metadata: {}
|
160
173
|
post_install_message:
|
161
174
|
rdoc_options: []
|
162
175
|
require_paths:
|
163
176
|
- lib
|
164
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
165
179
|
requirements:
|
166
|
-
- - '>='
|
180
|
+
- - ! '>='
|
167
181
|
- !ruby/object:Gem::Version
|
168
182
|
version: '0'
|
169
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
170
185
|
requirements:
|
171
|
-
- - '
|
186
|
+
- - ! '>='
|
172
187
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
188
|
+
version: '0'
|
174
189
|
requirements: []
|
175
190
|
rubyforge_project:
|
176
|
-
rubygems_version:
|
191
|
+
rubygems_version: 1.8.23
|
177
192
|
signing_key:
|
178
|
-
specification_version:
|
193
|
+
specification_version: 3
|
179
194
|
summary: Contextual authorization for your Rails (3+) application
|
180
195
|
test_files:
|
181
196
|
- spec/arrthorizer_exception/inner_spec.rb
|
@@ -184,9 +199,10 @@ test_files:
|
|
184
199
|
- spec/context_builder/build_spec.rb
|
185
200
|
- spec/context_role/to_key_spec.rb
|
186
201
|
- spec/context_spec.rb
|
187
|
-
- spec/
|
202
|
+
- spec/integration/group/initialize_spec.rb
|
188
203
|
- spec/integration/registry/missing_handler_spec.rb
|
189
204
|
- spec/integration/role_spec.rb
|
205
|
+
- spec/integration/some_controller_spec.rb
|
190
206
|
- spec/internal/app/assets/images/rails.png
|
191
207
|
- spec/internal/app/assets/javascripts/application.js
|
192
208
|
- spec/internal/app/assets/javascripts/test.js.coffee
|
@@ -198,7 +214,9 @@ test_files:
|
|
198
214
|
- spec/internal/app/helpers/test_helper.rb
|
199
215
|
- spec/internal/app/mailers/.gitkeep
|
200
216
|
- spec/internal/app/models/.gitkeep
|
217
|
+
- spec/internal/app/roles/another_group.rb
|
201
218
|
- spec/internal/app/roles/namespaced/context_role.rb
|
219
|
+
- spec/internal/app/roles/some_group.rb
|
202
220
|
- spec/internal/app/roles/unnamespaced_context_role.rb
|
203
221
|
- spec/internal/app/views/layouts/application.html.erb
|
204
222
|
- spec/internal/app/views/some/some_action.html.erb
|
@@ -207,6 +225,7 @@ test_files:
|
|
207
225
|
- spec/internal/config/boot.rb
|
208
226
|
- spec/internal/config/database.yml
|
209
227
|
- spec/internal/config/environment.rb
|
228
|
+
- spec/internal/config/initializers/arrthorizer.rb
|
210
229
|
- spec/internal/config/routes.rb
|
211
230
|
- spec/internal/db/schema.rb
|
212
231
|
- spec/internal/log/.gitignore
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: b71c7c666f99142b09c0bf02f42eba2942090799
|
4
|
-
data.tar.gz: 7ae245473bca34b41a2d99b5fdb01a240b8bb2fc
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: b7c6ab52920724e0ee79ae75365385829c7d3f5f2124aec3380687cfca1fc0d308412d38c697b6d9264b05422834d2667b494ecce7dfd8087380a399ef40d992
|
7
|
-
data.tar.gz: c2d9eacd2683e5b07b2231cf58ad2405b240e334811dc884ea811dc8ecf585cf6bf46afd269a7778a90ce36db7eba2f825ccdef4fd9bf63276503f328b639ca5
|