hydra-access-controls 6.0.0.pre4 → 6.0.0.pre5
Sign up to get free protection for your applications and to get access to all the features.
- data/hydra-access-controls.gemspec +1 -1
- data/lib/hydra/ability.rb +42 -23
- data/lib/hydra/access_controls_enforcement.rb +34 -14
- data/lib/hydra/permissions_query.rb +7 -2
- data/lib/hydra/policy_aware_ability.rb +3 -2
- data/lib/hydra/policy_aware_access_controls_enforcement.rb +18 -7
- data/spec/factories.rb +4 -0
- data/spec/unit/ability_spec.rb +30 -114
- data/spec/unit/admin_policy_spec.rb +116 -0
- metadata +4 -4
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.required_ruby_version = '>= 1.9.3'
|
19
19
|
|
20
20
|
gem.add_dependency 'activesupport'
|
21
|
-
gem.add_dependency
|
21
|
+
gem.add_dependency "active-fedora", '>= 6.0.0.pre8'
|
22
22
|
gem.add_dependency 'cancan'
|
23
23
|
gem.add_dependency 'deprecation'
|
24
24
|
gem.add_dependency 'blacklight'
|
data/lib/hydra/ability.rb
CHANGED
@@ -65,7 +65,7 @@ module Hydra::Ability
|
|
65
65
|
end
|
66
66
|
|
67
67
|
can :edit, SolrDocument do |obj|
|
68
|
-
@
|
68
|
+
@permission_doc_cache[obj.id] = obj
|
69
69
|
test_edit(obj.id)
|
70
70
|
end
|
71
71
|
end
|
@@ -80,7 +80,7 @@ module Hydra::Ability
|
|
80
80
|
end
|
81
81
|
|
82
82
|
can :read, SolrDocument do |obj|
|
83
|
-
@
|
83
|
+
@permission_doc_cache[obj.id] = obj
|
84
84
|
test_read(obj.id)
|
85
85
|
end
|
86
86
|
end
|
@@ -93,51 +93,70 @@ module Hydra::Ability
|
|
93
93
|
protected
|
94
94
|
|
95
95
|
def test_edit(pid)
|
96
|
-
permissions_doc(pid)
|
97
96
|
logger.debug("[CANCAN] Checking edit permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
|
98
|
-
group_intersection = user_groups & edit_groups
|
99
|
-
result = !group_intersection.empty? || edit_persons.include?(current_user.user_key)
|
97
|
+
group_intersection = user_groups & edit_groups(pid)
|
98
|
+
result = !group_intersection.empty? || edit_persons(pid).include?(current_user.user_key)
|
100
99
|
logger.debug("[CANCAN] decision: #{result}")
|
101
100
|
result
|
102
101
|
end
|
103
102
|
|
104
103
|
def test_read(pid)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
result = !group_intersection.empty? || read_persons.include?(current_user.user_key)
|
109
|
-
logger.debug("[CANCAN] decision: #{result}")
|
104
|
+
logger.debug("[CANCAN] Checking read permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}")
|
105
|
+
group_intersection = user_groups & read_groups(pid)
|
106
|
+
result = !group_intersection.empty? || read_persons(pid).include?(current_user.user_key)
|
110
107
|
result
|
111
108
|
end
|
112
|
-
|
113
|
-
def edit_groups
|
114
|
-
|
115
|
-
|
109
|
+
|
110
|
+
def edit_groups(pid)
|
111
|
+
doc = permissions_doc(pid)
|
112
|
+
return [] if doc.nil?
|
113
|
+
eg = doc[self.class.edit_group_field] || []
|
116
114
|
logger.debug("[CANCAN] edit_groups: #{eg.inspect}")
|
117
115
|
return eg
|
118
116
|
end
|
119
117
|
|
120
118
|
# edit implies read, so read_groups is the union of edit and read groups
|
121
|
-
def read_groups
|
122
|
-
|
123
|
-
|
119
|
+
def read_groups(pid)
|
120
|
+
doc = permissions_doc(pid)
|
121
|
+
return [] if doc.nil?
|
122
|
+
rg = edit_groups(pid) | (doc[self.class.read_group_field] || [])
|
124
123
|
logger.debug("[CANCAN] read_groups: #{rg.inspect}")
|
125
124
|
return rg
|
126
125
|
end
|
127
126
|
|
128
|
-
def edit_persons
|
129
|
-
|
130
|
-
|
127
|
+
def edit_persons(pid)
|
128
|
+
doc = permissions_doc(pid)
|
129
|
+
return [] if doc.nil?
|
130
|
+
ep = doc[self.class.edit_person_field] || []
|
131
131
|
logger.debug("[CANCAN] edit_persons: #{ep.inspect}")
|
132
132
|
return ep
|
133
133
|
end
|
134
134
|
|
135
135
|
# edit implies read, so read_persons is the union of edit and read persons
|
136
|
-
def read_persons
|
137
|
-
|
138
|
-
|
136
|
+
def read_persons(pid)
|
137
|
+
doc = permissions_doc(pid)
|
138
|
+
return [] if doc.nil?
|
139
|
+
rp = edit_persons(pid) | (doc[self.class.read_person_field] || [])
|
139
140
|
logger.debug("[CANCAN] read_persons: #{rp.inspect}")
|
140
141
|
return rp
|
141
142
|
end
|
142
143
|
|
144
|
+
module ClassMethods
|
145
|
+
def read_group_field
|
146
|
+
Hydra.config[:permissions][:read][:group]
|
147
|
+
end
|
148
|
+
|
149
|
+
def edit_person_field
|
150
|
+
Hydra.config[:permissions][:edit][:individual]
|
151
|
+
end
|
152
|
+
|
153
|
+
def read_person_field
|
154
|
+
Hydra.config[:permissions][:read][:individual]
|
155
|
+
end
|
156
|
+
|
157
|
+
def edit_group_field
|
158
|
+
Hydra.config[:permissions][:edit][:group]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
143
162
|
end
|
@@ -3,7 +3,6 @@ module Hydra::AccessControlsEnforcement
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
include Hydra::AccessControlsEvaluation
|
6
|
-
include Blacklight::SolrHelper # for force_to_utf8
|
7
6
|
include Hydra::PermissionsQuery
|
8
7
|
class_attribute :solr_access_filters_logic
|
9
8
|
|
@@ -19,6 +18,38 @@ module Hydra::AccessControlsEnforcement
|
|
19
18
|
|
20
19
|
protected
|
21
20
|
|
21
|
+
def gated_discovery_filters
|
22
|
+
# Grant access to public content
|
23
|
+
permission_types = discovery_permissions
|
24
|
+
user_access_filters = []
|
25
|
+
|
26
|
+
permission_types.each do |type|
|
27
|
+
user_access_filters << ActiveFedora::SolrService.solr_name("#{type}_access_group", Hydra::Datastream::RightsMetadata.indexer) + ":public"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Grant access based on user id & role
|
31
|
+
solr_access_filters_logic.each do |method_name|
|
32
|
+
user_access_filters += send(method_name, permission_types)
|
33
|
+
end
|
34
|
+
user_access_filters
|
35
|
+
end
|
36
|
+
|
37
|
+
def under_embargo?
|
38
|
+
load_permissions_from_solr
|
39
|
+
embargo_key = ActiveFedora::SolrService.solr_name("embargo_release_date", Hydra::Datastream::RightsMetadata.date_indexer)
|
40
|
+
if @permissions_solr_document[embargo_key]
|
41
|
+
embargo_date = Date.parse(@permissions_solr_document[embargo_key].split(/T/)[0])
|
42
|
+
return embargo_date > Date.parse(Time.now.to_s)
|
43
|
+
end
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_public?
|
48
|
+
load_permissions_from_solr
|
49
|
+
access_key = ActiveFedora::SolrService.solr_name("access", Hydra::Datastream::RightsMetadata.indexer)
|
50
|
+
@permissions_solr_document[access_key].present? && @permissions_solr_document[access_key].first.downcase == "public"
|
51
|
+
end
|
52
|
+
|
22
53
|
|
23
54
|
#
|
24
55
|
# Action-specific enforcement
|
@@ -69,21 +100,10 @@ module Hydra::AccessControlsEnforcement
|
|
69
100
|
# @param user_parameters the current user-subitted parameters
|
70
101
|
def apply_gated_discovery(solr_parameters, user_parameters)
|
71
102
|
solr_parameters[:fq] ||= []
|
72
|
-
|
73
|
-
permission_types = discovery_permissions
|
74
|
-
user_access_filters = []
|
75
|
-
|
76
|
-
permission_types.each do |type|
|
77
|
-
user_access_filters << ActiveFedora::SolrService.solr_name("#{type}_access_group", Hydra::Datastream::RightsMetadata.indexer) + ":public"
|
78
|
-
end
|
79
|
-
|
80
|
-
# Grant access based on user id & role
|
81
|
-
solr_access_filters_logic.each do |method_name|
|
82
|
-
user_access_filters += send(method_name, permission_types)
|
83
|
-
end
|
84
|
-
solr_parameters[:fq] << user_access_filters.join(" OR ")
|
103
|
+
solr_parameters[:fq] << gated_discovery_filters.join(" OR ")
|
85
104
|
logger.debug("Solr parameters: #{ solr_parameters.inspect }")
|
86
105
|
end
|
106
|
+
|
87
107
|
|
88
108
|
def apply_role_permissions(permission_types)
|
89
109
|
# for roles
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module Hydra::PermissionsQuery
|
2
|
-
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
include Blacklight::SolrHelper # for force_to_utf8
|
5
|
+
end
|
6
|
+
|
3
7
|
def permissions_doc(pid)
|
4
|
-
@
|
8
|
+
@permission_doc_cache ||= {}
|
9
|
+
@permission_doc_cache[pid] ||= get_permissions_solr_response_for_doc_id(pid)
|
5
10
|
end
|
6
11
|
|
7
12
|
|
@@ -38,9 +38,10 @@ module Hydra::PolicyAwareAbility
|
|
38
38
|
|
39
39
|
# Returns the permissions solr document for policy_pid
|
40
40
|
# The document is stored in an instance variable, so calling this multiple times will only query solr once.
|
41
|
-
# To force reload, set @
|
41
|
+
# To force reload, set @policy_permissions_solr_cache to {}
|
42
42
|
def policy_permissions_doc(policy_pid)
|
43
|
-
@
|
43
|
+
@policy_permissions_solr_cache ||= {}
|
44
|
+
@policy_permissions_solr_cache[policy_pid] ||= get_permissions_solr_response_for_doc_id(policy_pid)
|
44
45
|
end
|
45
46
|
|
46
47
|
# Tests whether the object's governing policy object grants edit access for the current user
|
@@ -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
|
6
8
|
def apply_gated_discovery(solr_parameters, user_parameters)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
solr_parameters[:fq].first << " OR " + additional_clauses
|
11
|
-
logger.debug("POLICY-aware Solr parameters: #{ solr_parameters.inspect }")
|
12
|
-
end
|
9
|
+
solr_parameters[:fq] ||= []
|
10
|
+
solr_parameters[:fq] << gated_discovery_filters.join(" OR ")
|
11
|
+
logger.debug("POLICY-aware Solr parameters: #{ solr_parameters.inspect }")
|
13
12
|
end
|
14
|
-
|
13
|
+
|
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,5 +64,16 @@ 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
|
67
78
|
|
68
79
|
end
|
data/spec/factories.rb
CHANGED
@@ -88,6 +88,10 @@ FactoryGirl.define do
|
|
88
88
|
factory :dept_access_asset, :parent=>:asset do |a|
|
89
89
|
permissions [{:name=>"africana-faculty", :access=>"read", :type=>"group"}, {:name=>"joe_creator", :access=>"edit", :type=>"user"}]
|
90
90
|
end
|
91
|
+
|
92
|
+
factory :group_edit_asset, :parent=>:asset do |a|
|
93
|
+
permissions [{:name=>"africana-faculty", :access=>"edit", :type=>"group"}, {:name=>"calvin_collaborator", :access=>"edit", :type=>"user"}]
|
94
|
+
end
|
91
95
|
|
92
96
|
factory :org_read_access_asset, :parent=>:asset do |a|
|
93
97
|
permissions [{:name=>"registered", :access=>"read", :type=>"group"}, {:name=>"joe_creator", :access=>"edit", :type=>"user"}, {:name=>"calvin_collaborator", :access=>"edit", :type=>"user"}]
|
data/spec/unit/ability_spec.rb
CHANGED
@@ -20,6 +20,14 @@ describe Ability do
|
|
20
20
|
}})
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "class methods" do
|
24
|
+
subject { Ability }
|
25
|
+
its(:read_group_field) { should == 'read_access_group_tsim'}
|
26
|
+
its(:read_person_field) { should == 'read_access_person_tsim'}
|
27
|
+
its(:edit_group_field) { should == 'edit_access_group_tsim'}
|
28
|
+
its(:edit_person_field) { should == 'edit_access_person_tsim'}
|
29
|
+
end
|
30
|
+
|
23
31
|
context "for a not-signed in user" do
|
24
32
|
before do
|
25
33
|
User.any_instance.stub(:email).and_return(nil)
|
@@ -166,10 +174,9 @@ describe Ability do
|
|
166
174
|
|
167
175
|
describe "Given an asset with collaborator" do
|
168
176
|
before do
|
169
|
-
@asset = FactoryGirl.
|
170
|
-
@asset.save
|
177
|
+
@asset = FactoryGirl.create(:group_edit_asset)
|
171
178
|
end
|
172
|
-
context "Then a collaborator with edit access" do
|
179
|
+
context "Then a collaborator with edit access (user permision)" do
|
173
180
|
before do
|
174
181
|
@user = FactoryGirl.build(:calvin_collaborator)
|
175
182
|
end
|
@@ -187,6 +194,17 @@ describe Ability do
|
|
187
194
|
subject.can?(:admin, @asset).should be_false
|
188
195
|
end
|
189
196
|
end
|
197
|
+
context "Then a collaborator with edit access (group permision)" do
|
198
|
+
before do
|
199
|
+
@user = FactoryGirl.build(:martia_morocco)
|
200
|
+
RoleMapper.stub(:roles).with(@user.user_key).and_return(@user.roles)
|
201
|
+
end
|
202
|
+
subject { Ability.new(@user) }
|
203
|
+
|
204
|
+
it "should be able to view the asset" do
|
205
|
+
subject.can?(:read, @asset).should be_true
|
206
|
+
end
|
207
|
+
end
|
190
208
|
end
|
191
209
|
|
192
210
|
describe "Given an asset where dept can read & registered users can discover" do
|
@@ -269,120 +287,18 @@ describe Ability do
|
|
269
287
|
|
270
288
|
end
|
271
289
|
|
272
|
-
|
273
|
-
# Policy-based Access Controls
|
274
|
-
#
|
275
|
-
describe "When accessing assets with Policies associated" do
|
290
|
+
describe "calling ability on two separate objects" do
|
276
291
|
before do
|
277
|
-
@
|
278
|
-
|
292
|
+
@asset1 = FactoryGirl.create(:org_read_access_asset)
|
293
|
+
@asset2 = FactoryGirl.create(:asset)
|
294
|
+
@user = FactoryGirl.build(:calvin_collaborator) # has access to @asset1, but not @asset2
|
279
295
|
end
|
280
296
|
subject { Ability.new(@user) }
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
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
|
345
|
-
end
|
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
|
297
|
+
it "should be readable in the first instance and not in the second instance" do
|
298
|
+
# We had a bug around this where it keeps returning the access for the first object queried
|
299
|
+
subject.can?(:edit, @asset1).should be_true
|
300
|
+
subject.can?(:edit, @asset2).should be_false
|
386
301
|
end
|
387
302
|
end
|
303
|
+
|
388
304
|
end
|
@@ -121,5 +121,121 @@ describe Hydra::AdminPolicy do
|
|
121
121
|
|
122
122
|
end
|
123
123
|
|
124
|
+
#
|
125
|
+
# Policy-based Access Controls
|
126
|
+
#
|
127
|
+
describe "When accessing assets with Policies associated" do
|
128
|
+
before do
|
129
|
+
@user = FactoryGirl.build(:martia_morocco)
|
130
|
+
RoleMapper.stub(:roles).with(@user.user_key).and_return(@user.roles)
|
131
|
+
end
|
132
|
+
subject { Ability.new(@user) }
|
133
|
+
context "Given a policy grants read access to a group I belong to" do
|
134
|
+
before do
|
135
|
+
@policy = Hydra::AdminPolicy.new
|
136
|
+
@policy.default_permissions = [{:type=>"group", :access=>"read", :name=>"africana-faculty"}]
|
137
|
+
@policy.save
|
138
|
+
end
|
139
|
+
after { @policy.delete }
|
140
|
+
context "And a subscribing asset does not grant access" do
|
141
|
+
before do
|
142
|
+
@asset = ModsAsset.new()
|
143
|
+
@asset.admin_policy = @policy
|
144
|
+
@asset.save
|
145
|
+
end
|
146
|
+
after { @asset.delete }
|
147
|
+
it "Then I should be able to view the asset" do
|
148
|
+
subject.can?(:read, @asset).should be_true
|
149
|
+
end
|
150
|
+
it "Then I should not be able to edit, update and destroy the asset" do
|
151
|
+
subject.can?(:edit, @asset).should be_false
|
152
|
+
subject.can?(:update, @asset).should be_false
|
153
|
+
subject.can?(:destroy, @asset).should be_false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
context "Given a policy grants edit access to a group I belong to" do
|
158
|
+
before do
|
159
|
+
@policy = Hydra::AdminPolicy.new
|
160
|
+
@policy.default_permissions = [{:type=>"group", :access=>"edit", :name=>"africana-faculty"}]
|
161
|
+
@policy.save
|
162
|
+
end
|
163
|
+
after { @policy.delete }
|
164
|
+
context "And a subscribing asset does not grant access" do
|
165
|
+
before do
|
166
|
+
@asset = ModsAsset.new()
|
167
|
+
@asset.admin_policy = @policy
|
168
|
+
@asset.save
|
169
|
+
end
|
170
|
+
after { @asset.delete }
|
171
|
+
it "Then I should be able to view the asset" do
|
172
|
+
subject.can?(:read, @asset).should be_true
|
173
|
+
end
|
174
|
+
it "Then I should be able to edit/update/destroy the asset" do
|
175
|
+
subject.can?(:edit, @asset).should be_true
|
176
|
+
subject.can?(:update, @asset).should be_true
|
177
|
+
subject.can?(:destroy, @asset).should be_true
|
178
|
+
end
|
179
|
+
end
|
180
|
+
context "And a subscribing asset grants read access to me as an individual" do
|
181
|
+
before do
|
182
|
+
@asset = ModsAsset.new()
|
183
|
+
@asset.read_users = [@user.uid]
|
184
|
+
@asset.admin_policy = @policy
|
185
|
+
@asset.save
|
186
|
+
end
|
187
|
+
after { @asset.delete }
|
188
|
+
it "Then I should be able to view the asset" do
|
189
|
+
subject.can?(:read, @asset).should be_true
|
190
|
+
end
|
191
|
+
it "Then I should be able to edit/update/destroy the asset" do
|
192
|
+
subject.can?(:edit, @asset).should be_true
|
193
|
+
subject.can?(:update, @asset).should be_true
|
194
|
+
subject.can?(:destroy, @asset).should be_true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "Given a policy does not grant access to any group I belong to" do
|
200
|
+
before do
|
201
|
+
@policy = Hydra::AdminPolicy.new
|
202
|
+
@policy.save
|
203
|
+
end
|
204
|
+
after { @policy.delete }
|
205
|
+
context "And a subscribing asset does not grant access" do
|
206
|
+
before do
|
207
|
+
@asset = ModsAsset.new()
|
208
|
+
@asset.admin_policy = @policy
|
209
|
+
@asset.save
|
210
|
+
end
|
211
|
+
after { @asset.delete }
|
212
|
+
it "Then I should not be able to view the asset" do
|
213
|
+
subject.can?(:read, @asset).should be_false
|
214
|
+
end
|
215
|
+
it "Then I should not be able to edit/update/destroy the asset" do
|
216
|
+
subject.can?(:edit, @asset).should be_false
|
217
|
+
subject.can?(:update, @asset).should be_false
|
218
|
+
subject.can?(:destroy, @asset).should be_false
|
219
|
+
end
|
220
|
+
end
|
221
|
+
context "And a subscribing asset grants read access to me as an individual" do
|
222
|
+
before do
|
223
|
+
@asset = ModsAsset.new()
|
224
|
+
@asset.read_users = [@user.uid]
|
225
|
+
@asset.admin_policy = @policy
|
226
|
+
@asset.save
|
227
|
+
end
|
228
|
+
after { @asset.delete }
|
229
|
+
it "Then I should be able to view the asset" do
|
230
|
+
subject.can?(:read, @asset).should be_true
|
231
|
+
end
|
232
|
+
it "Then I should not be able to edit/update/destroy the asset" do
|
233
|
+
subject.can?(:edit, @asset).should be_false
|
234
|
+
subject.can?(:update, @asset).should be_false
|
235
|
+
subject.can?(:destroy, @asset).should be_false
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
124
240
|
|
125
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-access-controls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.pre5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 6.0.0.
|
39
|
+
version: 6.0.0.pre8
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 6.0.0.
|
47
|
+
version: 6.0.0.pre8
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: cancan
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|