hydra-access-controls 5.4.1 → 6.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hydra/ability.rb +27 -51
- data/lib/hydra/access_controls_enforcement.rb +13 -18
- data/lib/hydra/policy_aware_ability.rb +14 -19
- data/lib/hydra/policy_aware_access_controls_enforcement.rb +7 -18
- data/spec/unit/ability_spec.rb +111 -9
- data/spec/unit/admin_policy_spec.rb +0 -116
- metadata +38 -22
- checksums.yaml +0 -7
data/lib/hydra/ability.rb
CHANGED
@@ -25,14 +25,11 @@ module Hydra::Ability
|
|
25
25
|
@current_user = user || Hydra::Ability.user_class.new # guest user (not logged in)
|
26
26
|
@user = @current_user # just in case someone was using this in an override. Just don't.
|
27
27
|
@session = session
|
28
|
-
@permission_doc_cache = {}
|
29
28
|
hydra_default_permissions()
|
30
29
|
end
|
31
30
|
|
32
31
|
## You can override this method if you are using a different AuthZ (such as LDAP)
|
33
|
-
def user_groups
|
34
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to user_groups, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
35
|
-
|
32
|
+
def user_groups
|
36
33
|
return @user_groups if @user_groups
|
37
34
|
|
38
35
|
@user_groups = default_user_groups
|
@@ -47,22 +44,18 @@ module Hydra::Ability
|
|
47
44
|
end
|
48
45
|
|
49
46
|
|
50
|
-
|
51
|
-
def hydra_default_permissions(deprecated_user=nil, deprecated_session=nil)
|
52
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to hydra_default_permissions, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
47
|
+
def hydra_default_permissions
|
53
48
|
logger.debug("Usergroups are " + user_groups.inspect)
|
54
49
|
self.ability_logic.each do |method|
|
55
50
|
send(method)
|
56
51
|
end
|
57
52
|
end
|
58
53
|
|
59
|
-
def create_permissions
|
60
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to create_permissions, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
54
|
+
def create_permissions
|
61
55
|
can :create, :all if user_groups.include? 'registered'
|
62
56
|
end
|
63
57
|
|
64
|
-
def edit_permissions
|
65
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to edit_permissions, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
58
|
+
def edit_permissions
|
66
59
|
can [:edit, :update, :destroy], String do |pid|
|
67
60
|
test_edit(pid)
|
68
61
|
end
|
@@ -72,13 +65,12 @@ module Hydra::Ability
|
|
72
65
|
end
|
73
66
|
|
74
67
|
can :edit, SolrDocument do |obj|
|
75
|
-
@
|
68
|
+
@permissions_solr_document = obj
|
76
69
|
test_edit(obj.id)
|
77
70
|
end
|
78
71
|
end
|
79
72
|
|
80
|
-
def read_permissions
|
81
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to read_permissions, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
73
|
+
def read_permissions
|
82
74
|
can :read, String do |pid|
|
83
75
|
test_read(pid)
|
84
76
|
end
|
@@ -88,87 +80,71 @@ module Hydra::Ability
|
|
88
80
|
end
|
89
81
|
|
90
82
|
can :read, SolrDocument do |obj|
|
91
|
-
@
|
83
|
+
@permissions_solr_document = obj
|
92
84
|
test_read(obj.id)
|
93
85
|
end
|
94
86
|
end
|
95
87
|
|
96
88
|
|
97
89
|
## Override custom permissions in your own app to add more permissions beyond what is defined by default.
|
98
|
-
def custom_permissions
|
99
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to custom_permissions, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
90
|
+
def custom_permissions
|
100
91
|
end
|
101
92
|
|
102
93
|
protected
|
103
94
|
|
104
95
|
def permissions_doc(pid)
|
105
|
-
return @
|
106
|
-
|
107
|
-
|
108
|
-
@permission_doc_cache[pid] = doc
|
96
|
+
return @permissions_solr_document if @permissions_solr_document
|
97
|
+
response, @permissions_solr_document = get_permissions_solr_response_for_doc_id(pid)
|
98
|
+
@permissions_solr_document
|
109
99
|
end
|
110
100
|
|
111
101
|
|
112
|
-
def test_edit(pid
|
113
|
-
|
102
|
+
def test_edit(pid)
|
103
|
+
permissions_doc(pid)
|
114
104
|
logger.debug("[CANCAN] Checking edit permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
|
115
|
-
group_intersection = user_groups & edit_groups
|
116
|
-
result = !group_intersection.empty? || edit_persons
|
105
|
+
group_intersection = user_groups & edit_groups
|
106
|
+
result = !group_intersection.empty? || edit_persons.include?(current_user.user_key)
|
117
107
|
logger.debug("[CANCAN] decision: #{result}")
|
118
108
|
result
|
119
109
|
end
|
120
110
|
|
121
|
-
def test_read(pid
|
122
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to test_read, use the instance_variables", caller()) if deprecated_user || deprecated_session
|
111
|
+
def test_read(pid)
|
123
112
|
permissions_doc(pid)
|
124
|
-
logger.debug("[CANCAN] Checking
|
125
|
-
group_intersection = user_groups & read_groups
|
126
|
-
result = !group_intersection.empty? || read_persons
|
113
|
+
logger.debug("[CANCAN] Checking edit permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
|
114
|
+
group_intersection = user_groups & read_groups
|
115
|
+
result = !group_intersection.empty? || read_persons.include?(current_user.user_key)
|
127
116
|
logger.debug("[CANCAN] decision: #{result}")
|
128
117
|
result
|
129
118
|
end
|
130
119
|
|
131
|
-
def edit_groups
|
120
|
+
def edit_groups
|
132
121
|
edit_group_field = Hydra.config[:permissions][:edit][:group]
|
133
|
-
|
134
|
-
eg = ((doc == nil || doc.fetch(edit_group_field,nil) == nil) ? [] : doc.fetch(edit_group_field,nil))
|
122
|
+
eg = ((@permissions_solr_document == nil || @permissions_solr_document.fetch(edit_group_field,nil) == nil) ? [] : @permissions_solr_document.fetch(edit_group_field,nil))
|
135
123
|
logger.debug("[CANCAN] edit_groups: #{eg.inspect}")
|
136
124
|
return eg
|
137
125
|
end
|
138
126
|
|
139
127
|
# edit implies read, so read_groups is the union of edit and read groups
|
140
|
-
def read_groups
|
128
|
+
def read_groups
|
141
129
|
read_group_field = Hydra.config[:permissions][:read][:group]
|
142
|
-
|
143
|
-
rg = edit_groups(pid) | ((doc == nil || doc.fetch(read_group_field,nil) == nil) ? [] : doc.fetch(read_group_field,nil))
|
130
|
+
rg = edit_groups | ((@permissions_solr_document == nil || @permissions_solr_document.fetch(read_group_field,nil) == nil) ? [] : @permissions_solr_document.fetch(read_group_field,nil))
|
144
131
|
logger.debug("[CANCAN] read_groups: #{rg.inspect}")
|
145
132
|
return rg
|
146
133
|
end
|
147
134
|
|
148
|
-
def edit_persons
|
135
|
+
def edit_persons
|
149
136
|
edit_person_field = Hydra.config[:permissions][:edit][:individual]
|
150
|
-
|
151
|
-
ep = ((doc == nil || doc.fetch(edit_person_field,nil) == nil) ? [] : doc.fetch(edit_person_field,nil))
|
137
|
+
ep = ((@permissions_solr_document == nil || @permissions_solr_document.fetch(edit_person_field,nil) == nil) ? [] : @permissions_solr_document.fetch(edit_person_field,nil))
|
152
138
|
logger.debug("[CANCAN] edit_persons: #{ep.inspect}")
|
153
139
|
return ep
|
154
140
|
end
|
155
141
|
|
156
142
|
# edit implies read, so read_persons is the union of edit and read persons
|
157
|
-
def read_persons
|
143
|
+
def read_persons
|
158
144
|
read_individual_field = Hydra.config[:permissions][:read][:individual]
|
159
|
-
|
160
|
-
rp = edit_persons(pid) | ((doc == nil || doc.fetch(read_individual_field,nil) == nil) ? [] : doc.fetch(read_individual_field,nil))
|
145
|
+
rp = edit_persons | ((@permissions_solr_document == nil || @permissions_solr_document.fetch(read_individual_field,nil) == nil) ? [] : @permissions_solr_document.fetch(read_individual_field,nil))
|
161
146
|
logger.debug("[CANCAN] read_persons: #{rp.inspect}")
|
162
147
|
return rp
|
163
148
|
end
|
164
149
|
|
165
|
-
|
166
|
-
# get the currently configured user identifier. Can be overridden to return whatever (ie. login, email, etc)
|
167
|
-
# defaults to using whatever you have set as the Devise authentication_key
|
168
|
-
def user_key(user)
|
169
|
-
ActiveSupport::Deprecation.warn("Ability#user_key is deprecated, call user.user_key instead", caller(1))
|
170
|
-
user.send(Devise.authentication_keys.first)
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
150
|
end
|
@@ -89,22 +89,6 @@ module Hydra::AccessControlsEnforcement
|
|
89
89
|
|
90
90
|
protected
|
91
91
|
|
92
|
-
def gated_discovery_filters
|
93
|
-
# Grant access to public content
|
94
|
-
permission_types = discovery_permissions
|
95
|
-
user_access_filters = []
|
96
|
-
|
97
|
-
permission_types.each do |type|
|
98
|
-
user_access_filters << "#{type}_access_group_t:public"
|
99
|
-
end
|
100
|
-
|
101
|
-
# Grant access based on user id & role
|
102
|
-
solr_access_filters_logic.each do |method_name|
|
103
|
-
user_access_filters += send(method_name, permission_types)
|
104
|
-
end
|
105
|
-
user_access_filters
|
106
|
-
end
|
107
|
-
|
108
92
|
# If someone hits the show action while their session's viewing_context is in edit mode,
|
109
93
|
# this will redirect them to the edit action.
|
110
94
|
# If they do not have sufficient privileges to edit documents, it will silently switch their session to browse mode.
|
@@ -227,10 +211,21 @@ module Hydra::AccessControlsEnforcement
|
|
227
211
|
# @param user_parameters the current user-subitted parameters
|
228
212
|
def apply_gated_discovery(solr_parameters, user_parameters)
|
229
213
|
solr_parameters[:fq] ||= []
|
230
|
-
|
214
|
+
# Grant access to public content
|
215
|
+
permission_types = discovery_permissions
|
216
|
+
user_access_filters = []
|
217
|
+
|
218
|
+
permission_types.each do |type|
|
219
|
+
user_access_filters << "#{type}_access_group_t:public"
|
220
|
+
end
|
221
|
+
|
222
|
+
# Grant access based on user id & role
|
223
|
+
solr_access_filters_logic.each do |method_name|
|
224
|
+
user_access_filters += send(method_name, permission_types)
|
225
|
+
end
|
226
|
+
solr_parameters[:fq] << user_access_filters.join(" OR ")
|
231
227
|
logger.debug("Solr parameters: #{ solr_parameters.inspect }")
|
232
228
|
end
|
233
|
-
|
234
229
|
|
235
230
|
def apply_role_permissions(permission_types)
|
236
231
|
# for roles
|
@@ -2,24 +2,22 @@
|
|
2
2
|
module Hydra::PolicyAwareAbility
|
3
3
|
|
4
4
|
# Extends Hydra::Ability.test_edit to try policy controls if object-level controls deny access
|
5
|
-
def test_edit(pid
|
6
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to test_edit, use the instance_variables", caller) if user || session
|
5
|
+
def test_edit(pid)
|
7
6
|
result = super
|
8
7
|
if result
|
9
8
|
return result
|
10
9
|
else
|
11
|
-
return test_edit_from_policy(pid
|
10
|
+
return test_edit_from_policy(pid)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
# Extends Hydra::Ability.test_read to try policy controls if object-level controls deny access
|
16
|
-
def test_read(pid
|
17
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to test_read, use the instance_variables", caller) if user || session
|
15
|
+
def test_read(pid)
|
18
16
|
result = super
|
19
17
|
if result
|
20
18
|
return result
|
21
19
|
else
|
22
|
-
return test_read_from_policy(pid
|
20
|
+
return test_read_from_policy(pid)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -39,39 +37,36 @@ module Hydra::PolicyAwareAbility
|
|
39
37
|
|
40
38
|
# Returns the permissions solr document for policy_pid
|
41
39
|
# The document is stored in an instance variable, so calling this multiple times will only query solr once.
|
42
|
-
# To force reload, set @
|
40
|
+
# To force reload, set @policy_permissions_solr_document to nil
|
43
41
|
def policy_permissions_doc(policy_pid)
|
44
|
-
@
|
45
|
-
|
46
|
-
|
47
|
-
@policy_permissions_solr_cache[policy_pid] = doc
|
42
|
+
return @policy_permissions_solr_document if @policy_permissions_solr_document
|
43
|
+
response, @policy_permissions_solr_document = get_permissions_solr_response_for_doc_id(policy_pid)
|
44
|
+
@policy_permissions_solr_document
|
48
45
|
end
|
49
46
|
|
50
47
|
# Tests whether the object's governing policy object grants edit access for the current user
|
51
|
-
def test_edit_from_policy(object_pid
|
52
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to test_edit_from_policy, use the instance_variables", caller) if user || session
|
48
|
+
def test_edit_from_policy(object_pid)
|
53
49
|
policy_pid = policy_pid_for(object_pid)
|
54
50
|
if policy_pid.nil?
|
55
51
|
return false
|
56
52
|
else
|
57
|
-
logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide EDIT permissions for #{
|
53
|
+
logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide EDIT permissions for #{current_user.user_key}?")
|
58
54
|
group_intersection = user_groups & edit_groups_from_policy( policy_pid )
|
59
|
-
result = !group_intersection.empty? || edit_persons_from_policy( policy_pid ).include?(
|
55
|
+
result = !group_intersection.empty? || edit_persons_from_policy( policy_pid ).include?(current_user.user_key)
|
60
56
|
logger.debug("[CANCAN] -policy- decision: #{result}")
|
61
57
|
return result
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
61
|
# Tests whether the object's governing policy object grants read access for the current user
|
66
|
-
def test_read_from_policy(object_pid
|
67
|
-
ActiveSupport::Deprecation.warn("No need to pass user or session to test_read_from_policy, use the instance_variables", caller) if user || session
|
62
|
+
def test_read_from_policy(object_pid)
|
68
63
|
policy_pid = policy_pid_for(object_pid)
|
69
64
|
if policy_pid.nil?
|
70
65
|
return false
|
71
66
|
else
|
72
|
-
logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide READ permissions for #{
|
67
|
+
logger.debug("[CANCAN] -policy- Does the POLICY #{policy_pid} provide READ permissions for #{current_user.user_key}?")
|
73
68
|
group_intersection = user_groups & read_groups_from_policy( policy_pid )
|
74
|
-
result = !group_intersection.empty? || read_persons_from_policy( policy_pid ).include?(
|
69
|
+
result = !group_intersection.empty? || read_persons_from_policy( policy_pid ).include?(current_user.user_key)
|
75
70
|
logger.debug("[CANCAN] -policy- decision: #{result}")
|
76
71
|
result
|
77
72
|
end
|
@@ -3,15 +3,15 @@ module Hydra::PolicyAwareAccessControlsEnforcement
|
|
3
3
|
|
4
4
|
# Extends Hydra::AccessControlsEnforcement.apply_gated_discovery to reflect policy-provided access
|
5
5
|
# appends the result of policy_clauses into the :fq
|
6
|
-
# @param solr_parameters the current solr parameters
|
7
|
-
# @param user_parameters the current user-subitted parameters
|
8
6
|
def apply_gated_discovery(solr_parameters, user_parameters)
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
super
|
8
|
+
additional_clauses = policy_clauses
|
9
|
+
unless additional_clauses.nil? || additional_clauses.empty?
|
10
|
+
solr_parameters[:fq].first << " OR " + additional_clauses
|
11
|
+
logger.debug("POLICY-aware Solr parameters: #{ solr_parameters.inspect }")
|
12
|
+
end
|
12
13
|
end
|
13
|
-
|
14
|
-
|
14
|
+
|
15
15
|
# returns solr query for finding all objects whose policies grant discover access to current_user
|
16
16
|
def policy_clauses
|
17
17
|
policy_pids = policies_with_access
|
@@ -64,16 +64,5 @@ module Hydra::PolicyAwareAccessControlsEnforcement
|
|
64
64
|
return Hydra.config[:permissions][:policy_class]
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
def gated_discovery_filters
|
71
|
-
filters = super
|
72
|
-
additional_clauses = policy_clauses
|
73
|
-
unless additional_clauses.blank?
|
74
|
-
filters << additional_clauses
|
75
|
-
end
|
76
|
-
filters
|
77
|
-
end
|
78
67
|
|
79
68
|
end
|
data/spec/unit/ability_spec.rb
CHANGED
@@ -269,18 +269,120 @@ describe Ability do
|
|
269
269
|
|
270
270
|
end
|
271
271
|
|
272
|
-
|
272
|
+
#
|
273
|
+
# Policy-based Access Controls
|
274
|
+
#
|
275
|
+
describe "When accessing assets with Policies associated" do
|
273
276
|
before do
|
274
|
-
@
|
275
|
-
|
276
|
-
@user = FactoryGirl.build(:calvin_collaborator) # has access to @asset1, but not @asset2
|
277
|
+
@user = FactoryGirl.build(:martia_morocco)
|
278
|
+
RoleMapper.stub(:roles).with(@user.user_key).and_return(@user.roles)
|
277
279
|
end
|
278
280
|
subject { Ability.new(@user) }
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
281
|
+
context "Given a policy grants read access to a group I belong to" do
|
282
|
+
before do
|
283
|
+
@policy = Hydra::AdminPolicy.new
|
284
|
+
@policy.default_permissions = [{:type=>"group", :access=>"read", :name=>"africana-faculty"}]
|
285
|
+
@policy.save
|
286
|
+
end
|
287
|
+
after { @policy.delete }
|
288
|
+
context "And a subscribing asset does not grant access" do
|
289
|
+
before do
|
290
|
+
@asset = ModsAsset.new()
|
291
|
+
@asset.admin_policy = @policy
|
292
|
+
@asset.save
|
293
|
+
end
|
294
|
+
after { @asset.delete }
|
295
|
+
it "Then I should be able to view the asset" do
|
296
|
+
subject.can?(:read, @asset).should be_true
|
297
|
+
end
|
298
|
+
it "Then I should not be able to edit, update and destroy the asset" do
|
299
|
+
subject.can?(:edit, @asset).should be_false
|
300
|
+
subject.can?(:update, @asset).should be_false
|
301
|
+
subject.can?(:destroy, @asset).should be_false
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
context "Given a policy grants edit access to a group I belong to" do
|
306
|
+
before do
|
307
|
+
@policy = Hydra::AdminPolicy.new
|
308
|
+
@policy.default_permissions = [{:type=>"group", :access=>"edit", :name=>"africana-faculty"}]
|
309
|
+
@policy.save
|
310
|
+
end
|
311
|
+
after { @policy.delete }
|
312
|
+
context "And a subscribing asset does not grant access" do
|
313
|
+
before do
|
314
|
+
@asset = ModsAsset.new()
|
315
|
+
@asset.admin_policy = @policy
|
316
|
+
@asset.save
|
317
|
+
end
|
318
|
+
after { @asset.delete }
|
319
|
+
it "Then I should be able to view the asset" do
|
320
|
+
subject.can?(:read, @asset).should be_true
|
321
|
+
end
|
322
|
+
it "Then I should be able to edit/update/destroy the asset" do
|
323
|
+
subject.can?(:edit, @asset).should be_true
|
324
|
+
subject.can?(:update, @asset).should be_true
|
325
|
+
subject.can?(:destroy, @asset).should be_true
|
326
|
+
end
|
327
|
+
end
|
328
|
+
context "And a subscribing asset grants read access to me as an individual" do
|
329
|
+
before do
|
330
|
+
@asset = ModsAsset.new()
|
331
|
+
@asset.read_users = [@user.uid]
|
332
|
+
@asset.admin_policy = @policy
|
333
|
+
@asset.save
|
334
|
+
end
|
335
|
+
after { @asset.delete }
|
336
|
+
it "Then I should be able to view the asset" do
|
337
|
+
subject.can?(:read, @asset).should be_true
|
338
|
+
end
|
339
|
+
it "Then I should be able to edit/update/destroy the asset" do
|
340
|
+
subject.can?(:edit, @asset).should be_true
|
341
|
+
subject.can?(:update, @asset).should be_true
|
342
|
+
subject.can?(:destroy, @asset).should be_true
|
343
|
+
end
|
344
|
+
end
|
283
345
|
end
|
284
|
-
end
|
285
346
|
|
347
|
+
context "Given a policy does not grant access to any group I belong to" do
|
348
|
+
before do
|
349
|
+
@policy = Hydra::AdminPolicy.new
|
350
|
+
@policy.save
|
351
|
+
end
|
352
|
+
after { @policy.delete }
|
353
|
+
context "And a subscribing asset does not grant access" do
|
354
|
+
before do
|
355
|
+
@asset = ModsAsset.new()
|
356
|
+
@asset.admin_policy = @policy
|
357
|
+
@asset.save
|
358
|
+
end
|
359
|
+
after { @asset.delete }
|
360
|
+
it "Then I should not be able to view the asset" do
|
361
|
+
subject.can?(:read, @asset).should be_false
|
362
|
+
end
|
363
|
+
it "Then I should not be able to edit/update/destroy the asset" do
|
364
|
+
subject.can?(:edit, @asset).should be_false
|
365
|
+
subject.can?(:update, @asset).should be_false
|
366
|
+
subject.can?(:destroy, @asset).should be_false
|
367
|
+
end
|
368
|
+
end
|
369
|
+
context "And a subscribing asset grants read access to me as an individual" do
|
370
|
+
before do
|
371
|
+
@asset = ModsAsset.new()
|
372
|
+
@asset.read_users = [@user.uid]
|
373
|
+
@asset.admin_policy = @policy
|
374
|
+
@asset.save
|
375
|
+
end
|
376
|
+
after { @asset.delete }
|
377
|
+
it "Then I should be able to view the asset" do
|
378
|
+
subject.can?(:read, @asset).should be_true
|
379
|
+
end
|
380
|
+
it "Then I should not be able to edit/update/destroy the asset" do
|
381
|
+
subject.can?(:edit, @asset).should be_false
|
382
|
+
subject.can?(:update, @asset).should be_false
|
383
|
+
subject.can?(:destroy, @asset).should be_false
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
286
388
|
end
|
@@ -124,121 +124,5 @@ describe Hydra::AdminPolicy do
|
|
124
124
|
|
125
125
|
end
|
126
126
|
|
127
|
-
#
|
128
|
-
# Policy-based Access Controls
|
129
|
-
#
|
130
|
-
describe "When accessing assets with Policies associated" do
|
131
|
-
before do
|
132
|
-
@user = FactoryGirl.build(:martia_morocco)
|
133
|
-
RoleMapper.stub(:roles).with(@user.user_key).and_return(@user.roles)
|
134
|
-
end
|
135
|
-
subject { Ability.new(@user) }
|
136
|
-
context "Given a policy grants read access to a group I belong to" do
|
137
|
-
before do
|
138
|
-
@policy = Hydra::AdminPolicy.new
|
139
|
-
@policy.default_permissions = [{:type=>"group", :access=>"read", :name=>"africana-faculty"}]
|
140
|
-
@policy.save
|
141
|
-
end
|
142
|
-
after { @policy.delete }
|
143
|
-
context "And a subscribing asset does not grant access" do
|
144
|
-
before do
|
145
|
-
@asset = ModsAsset.new()
|
146
|
-
@asset.admin_policy = @policy
|
147
|
-
@asset.save
|
148
|
-
end
|
149
|
-
after { @asset.delete }
|
150
|
-
it "Then I should be able to view the asset" do
|
151
|
-
subject.can?(:read, @asset).should be_true
|
152
|
-
end
|
153
|
-
it "Then I should not be able to edit, update and destroy the asset" do
|
154
|
-
subject.can?(:edit, @asset).should be_false
|
155
|
-
subject.can?(:update, @asset).should be_false
|
156
|
-
subject.can?(:destroy, @asset).should be_false
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
context "Given a policy grants edit access to a group I belong to" do
|
161
|
-
before do
|
162
|
-
@policy = Hydra::AdminPolicy.new
|
163
|
-
@policy.default_permissions = [{:type=>"group", :access=>"edit", :name=>"africana-faculty"}]
|
164
|
-
@policy.save
|
165
|
-
end
|
166
|
-
after { @policy.delete }
|
167
|
-
context "And a subscribing asset does not grant access" do
|
168
|
-
before do
|
169
|
-
@asset = ModsAsset.new()
|
170
|
-
@asset.admin_policy = @policy
|
171
|
-
@asset.save
|
172
|
-
end
|
173
|
-
after { @asset.delete }
|
174
|
-
it "Then I should be able to view the asset" do
|
175
|
-
subject.can?(:read, @asset).should be_true
|
176
|
-
end
|
177
|
-
it "Then I should be able to edit/update/destroy the asset" do
|
178
|
-
subject.can?(:edit, @asset).should be_true
|
179
|
-
subject.can?(:update, @asset).should be_true
|
180
|
-
subject.can?(:destroy, @asset).should be_true
|
181
|
-
end
|
182
|
-
end
|
183
|
-
context "And a subscribing asset grants read access to me as an individual" do
|
184
|
-
before do
|
185
|
-
@asset = ModsAsset.new()
|
186
|
-
@asset.read_users = [@user.uid]
|
187
|
-
@asset.admin_policy = @policy
|
188
|
-
@asset.save
|
189
|
-
end
|
190
|
-
after { @asset.delete }
|
191
|
-
it "Then I should be able to view the asset" do
|
192
|
-
subject.can?(:read, @asset).should be_true
|
193
|
-
end
|
194
|
-
it "Then I should be able to edit/update/destroy the asset" do
|
195
|
-
subject.can?(:edit, @asset).should be_true
|
196
|
-
subject.can?(:update, @asset).should be_true
|
197
|
-
subject.can?(:destroy, @asset).should be_true
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "Given a policy does not grant access to any group I belong to" do
|
203
|
-
before do
|
204
|
-
@policy = Hydra::AdminPolicy.new
|
205
|
-
@policy.save
|
206
|
-
end
|
207
|
-
after { @policy.delete }
|
208
|
-
context "And a subscribing asset does not grant access" do
|
209
|
-
before do
|
210
|
-
@asset = ModsAsset.new()
|
211
|
-
@asset.admin_policy = @policy
|
212
|
-
@asset.save
|
213
|
-
end
|
214
|
-
after { @asset.delete }
|
215
|
-
it "Then I should not be able to view the asset" do
|
216
|
-
subject.can?(:read, @asset).should be_false
|
217
|
-
end
|
218
|
-
it "Then I should not be able to edit/update/destroy the asset" do
|
219
|
-
subject.can?(:edit, @asset).should be_false
|
220
|
-
subject.can?(:update, @asset).should be_false
|
221
|
-
subject.can?(:destroy, @asset).should be_false
|
222
|
-
end
|
223
|
-
end
|
224
|
-
context "And a subscribing asset grants read access to me as an individual" do
|
225
|
-
before do
|
226
|
-
@asset = ModsAsset.new()
|
227
|
-
@asset.read_users = [@user.uid]
|
228
|
-
@asset.admin_policy = @policy
|
229
|
-
@asset.save
|
230
|
-
end
|
231
|
-
after { @asset.delete }
|
232
|
-
it "Then I should be able to view the asset" do
|
233
|
-
subject.can?(:read, @asset).should be_true
|
234
|
-
end
|
235
|
-
it "Then I should not be able to edit/update/destroy the asset" do
|
236
|
-
subject.can?(:edit, @asset).should be_false
|
237
|
-
subject.can?(:update, @asset).should be_false
|
238
|
-
subject.can?(:destroy, @asset).should be_false
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
127
|
|
244
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-access-controls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.pre1
|
5
|
+
prerelease: 6
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Chris Beer
|
@@ -10,104 +11,118 @@ authors:
|
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: activesupport
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
18
20
|
requirements:
|
19
|
-
- -
|
21
|
+
- - ! '>='
|
20
22
|
- !ruby/object:Gem::Version
|
21
23
|
version: '0'
|
22
24
|
type: :runtime
|
23
25
|
prerelease: false
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
25
28
|
requirements:
|
26
|
-
- -
|
29
|
+
- - ! '>='
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: '0'
|
29
32
|
- !ruby/object:Gem::Dependency
|
30
33
|
name: active-fedora
|
31
34
|
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
32
36
|
requirements:
|
33
|
-
- -
|
37
|
+
- - ! '>='
|
34
38
|
- !ruby/object:Gem::Version
|
35
39
|
version: '0'
|
36
40
|
type: :runtime
|
37
41
|
prerelease: false
|
38
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
39
44
|
requirements:
|
40
|
-
- -
|
45
|
+
- - ! '>='
|
41
46
|
- !ruby/object:Gem::Version
|
42
47
|
version: '0'
|
43
48
|
- !ruby/object:Gem::Dependency
|
44
49
|
name: cancan
|
45
50
|
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
46
52
|
requirements:
|
47
|
-
- -
|
53
|
+
- - ! '>='
|
48
54
|
- !ruby/object:Gem::Version
|
49
55
|
version: '0'
|
50
56
|
type: :runtime
|
51
57
|
prerelease: false
|
52
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
53
60
|
requirements:
|
54
|
-
- -
|
61
|
+
- - ! '>='
|
55
62
|
- !ruby/object:Gem::Version
|
56
63
|
version: '0'
|
57
64
|
- !ruby/object:Gem::Dependency
|
58
65
|
name: deprecation
|
59
66
|
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
60
68
|
requirements:
|
61
|
-
- -
|
69
|
+
- - ! '>='
|
62
70
|
- !ruby/object:Gem::Version
|
63
71
|
version: '0'
|
64
72
|
type: :runtime
|
65
73
|
prerelease: false
|
66
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
67
76
|
requirements:
|
68
|
-
- -
|
77
|
+
- - ! '>='
|
69
78
|
- !ruby/object:Gem::Version
|
70
79
|
version: '0'
|
71
80
|
- !ruby/object:Gem::Dependency
|
72
81
|
name: blacklight
|
73
82
|
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
74
84
|
requirements:
|
75
|
-
- -
|
85
|
+
- - ! '>='
|
76
86
|
- !ruby/object:Gem::Version
|
77
87
|
version: '0'
|
78
88
|
type: :runtime
|
79
89
|
prerelease: false
|
80
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
81
92
|
requirements:
|
82
|
-
- -
|
93
|
+
- - ! '>='
|
83
94
|
- !ruby/object:Gem::Version
|
84
95
|
version: '0'
|
85
96
|
- !ruby/object:Gem::Dependency
|
86
97
|
name: rake
|
87
98
|
requirement: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
88
100
|
requirements:
|
89
|
-
- -
|
101
|
+
- - ! '>='
|
90
102
|
- !ruby/object:Gem::Version
|
91
103
|
version: '0'
|
92
104
|
type: :development
|
93
105
|
prerelease: false
|
94
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
95
108
|
requirements:
|
96
|
-
- -
|
109
|
+
- - ! '>='
|
97
110
|
- !ruby/object:Gem::Version
|
98
111
|
version: '0'
|
99
112
|
- !ruby/object:Gem::Dependency
|
100
113
|
name: rspec
|
101
114
|
requirement: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
102
116
|
requirements:
|
103
|
-
- -
|
117
|
+
- - ! '>='
|
104
118
|
- !ruby/object:Gem::Version
|
105
119
|
version: '0'
|
106
120
|
type: :development
|
107
121
|
prerelease: false
|
108
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
109
124
|
requirements:
|
110
|
-
- -
|
125
|
+
- - ! '>='
|
111
126
|
- !ruby/object:Gem::Version
|
112
127
|
version: '0'
|
113
128
|
description: Access controls for project hydra
|
@@ -158,26 +173,27 @@ files:
|
|
158
173
|
- tasks/hydra-access-controls.rake
|
159
174
|
homepage: http://projecthydra.org
|
160
175
|
licenses: []
|
161
|
-
metadata: {}
|
162
176
|
post_install_message:
|
163
177
|
rdoc_options: []
|
164
178
|
require_paths:
|
165
179
|
- lib
|
166
180
|
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
167
182
|
requirements:
|
168
|
-
- -
|
183
|
+
- - ! '>='
|
169
184
|
- !ruby/object:Gem::Version
|
170
185
|
version: 1.9.3
|
171
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
172
188
|
requirements:
|
173
|
-
- -
|
189
|
+
- - ! '>'
|
174
190
|
- !ruby/object:Gem::Version
|
175
|
-
version:
|
191
|
+
version: 1.3.1
|
176
192
|
requirements: []
|
177
193
|
rubyforge_project:
|
178
|
-
rubygems_version:
|
194
|
+
rubygems_version: 1.8.24
|
179
195
|
signing_key:
|
180
|
-
specification_version:
|
196
|
+
specification_version: 3
|
181
197
|
summary: Access controls for project hydra
|
182
198
|
test_files:
|
183
199
|
- spec/factories.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: fb5798a1c238c4a1a8cdff7d57bf8e318788f5ce
|
4
|
-
data.tar.gz: ca2650d4190dceb65aa2c799ad831e4cba980d7b
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 1584f38fd4cbc2f2c13e0f05e0a4904489c99cedfb85e7c07cca7c254c2760db9d2e2a3a737cef1ea3169e6e163144bf2a66c80c02d9c1eca573d00c32a4391c
|
7
|
-
data.tar.gz: e05a9e7648d05db52a44eb623fe41a93de39fbe75a2e342d7c872cec81153eb5f7842d6c4fc7daf3f1481b6d775778a2723cd05ce87b9adca71dc5c7f130266f
|