hydra-access-controls 10.5.0 → 10.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hydra/policy_aware_access_controls_enforcement.rb +10 -9
- data/spec/factories.rb +1 -1
- data/spec/services/embargo_service_spec.rb +4 -4
- data/spec/services/lease_service_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/ability_spec.rb +25 -25
- data/spec/unit/accessible_by_spec.rb +4 -4
- data/spec/unit/admin_policy_spec.rb +1 -1
- data/spec/unit/permission_spec.rb +1 -1
- data/spec/unit/policy_aware_access_controls_enforcement_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ff67011c0dfacf46f43a710b1bf75be300c91f8
|
4
|
+
data.tar.gz: 9894ed9ca3d96943443058a9546b32cdd71c8a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a3c4f41486967062df9adb768a6002eb5762967e70ce225dfa474eb2c293c2b86edea0a0b7cc935e57518bbcc1dd4d7ea2124b2dc514e600e0221ab209a0fb
|
7
|
+
data.tar.gz: c862bc4aa6120634f94370b7d0a0d72c579e4f07de7f135fff793c9ca65024519fbe5462777659ab89c5d91fc0a83955981722aa56284cec9615d82b773614c4
|
@@ -1,27 +1,26 @@
|
|
1
1
|
# Repeats access controls evaluation methods, but checks against a governing "Policy" object (or "Collection" object) that provides inherited access controls.
|
2
2
|
module Hydra::PolicyAwareAccessControlsEnforcement
|
3
3
|
|
4
|
-
# Extends Hydra::AccessControlsEnforcement.apply_gated_discovery to reflect policy-provided access
|
5
|
-
#
|
6
|
-
# @param solr_parameters the current solr parameters
|
7
|
-
# @param user_parameters the current user-subitted parameters
|
4
|
+
# Extends Hydra::AccessControlsEnforcement.apply_gated_discovery to reflect policy-provided access.
|
5
|
+
# Appends the result of policy_clauses into the :fq
|
6
|
+
# @param [Hash] solr_parameters the current solr parameters, to be modified herein!
|
8
7
|
def apply_gated_discovery(solr_parameters)
|
9
8
|
super
|
10
9
|
logger.debug("POLICY-aware Solr parameters: #{ solr_parameters.inspect }")
|
11
10
|
end
|
12
11
|
|
13
|
-
#
|
12
|
+
# @return [String,nil] solr query for finding all objects whose policies grant discover access to current_user
|
14
13
|
def policy_clauses
|
15
14
|
policy_ids = policies_with_access
|
16
15
|
return nil if policy_ids.empty?
|
17
16
|
'(' + policy_ids.map {|id| ActiveFedora::SolrQueryBuilder.construct_query_for_rel(isGovernedBy: id)}.join(' OR '.freeze) + ')'
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
19
|
+
# Find all the policies that grant discover/read/edit permissions to this user or any of its groups.
|
20
|
+
# Grant access based on user id & group
|
21
21
|
def policies_with_access
|
22
22
|
#### TODO -- Memoize this and put it in the session?
|
23
23
|
user_access_filters = []
|
24
|
-
# Grant access based on user id & group
|
25
24
|
user_access_filters += apply_policy_group_permissions(discovery_permissions)
|
26
25
|
user_access_filters += apply_policy_user_permissions(discovery_permissions)
|
27
26
|
result = policy_class.search_with_conditions( user_access_filters.join(" OR "), fl: "id", rows: policy_class.count )
|
@@ -29,8 +28,9 @@ module Hydra::PolicyAwareAccessControlsEnforcement
|
|
29
28
|
result.map {|h| h['id']}
|
30
29
|
end
|
31
30
|
|
31
|
+
# for groups
|
32
|
+
# @param [Array{String,#to_sym}] permission_types symbols (or equivalent) from Hydra.config.permissions.inheritable
|
32
33
|
def apply_policy_group_permissions(permission_types = discovery_permissions)
|
33
|
-
# for groups
|
34
34
|
user_access_filters = []
|
35
35
|
current_ability.user_groups.each_with_index do |group, i|
|
36
36
|
permission_types.each do |type|
|
@@ -40,8 +40,9 @@ module Hydra::PolicyAwareAccessControlsEnforcement
|
|
40
40
|
user_access_filters
|
41
41
|
end
|
42
42
|
|
43
|
+
# for individual user access
|
44
|
+
# @param [Array{String,#to_sym}] permission_types
|
43
45
|
def apply_policy_user_permissions(permission_types = discovery_permissions)
|
44
|
-
# for individual user access
|
45
46
|
user = current_ability.current_user
|
46
47
|
return [] unless user && user.user_key.present?
|
47
48
|
permission_types.map do |type|
|
data/spec/factories.rb
CHANGED
@@ -5,19 +5,19 @@ describe Hydra::EmbargoService do
|
|
5
5
|
let(:past_date) { 2.days.ago }
|
6
6
|
|
7
7
|
let!(:work_with_expired_embargo1) do
|
8
|
-
|
8
|
+
FactoryBot.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
|
9
9
|
work.save(validate:false)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
let!(:work_with_expired_embargo2) do
|
14
|
-
|
14
|
+
FactoryBot.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
|
15
15
|
work.save(validate:false)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
let!(:work_with_embargo_in_effect) {
|
20
|
-
let!(:work_without_embargo) {
|
19
|
+
let!(:work_with_embargo_in_effect) { FactoryBot.create(:asset, embargo_release_date: future_date.to_s)}
|
20
|
+
let!(:work_without_embargo) { FactoryBot.create(:asset)}
|
21
21
|
|
22
22
|
describe "#assets_with_expired_embargoes" do
|
23
23
|
it "returns an array of assets with expired embargoes" do
|
@@ -5,19 +5,19 @@ describe Hydra::LeaseService do
|
|
5
5
|
let(:past_date) { 2.days.ago }
|
6
6
|
|
7
7
|
let!(:work_with_expired_lease1) do
|
8
|
-
|
8
|
+
FactoryBot.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
|
9
9
|
work.save(validate: false)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
let!(:work_with_expired_lease2) do
|
14
|
-
|
14
|
+
FactoryBot.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
|
15
15
|
work.save(validate: false)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
let!(:work_with_lease_in_effect) {
|
20
|
-
let!(:work_without_lease) {
|
19
|
+
let!(:work_with_lease_in_effect) { FactoryBot.create(:asset, lease_expiration_date: future_date.to_s)}
|
20
|
+
let!(:work_without_lease) { FactoryBot.create(:asset)}
|
21
21
|
|
22
22
|
describe "#assets_with_expired_leases" do
|
23
23
|
it "returns an array of assets with expired embargoes" do
|
data/spec/spec_helper.rb
CHANGED
@@ -35,7 +35,7 @@ ActiveSupport::Dependencies.autoload_paths += relative_load_paths
|
|
35
35
|
require 'support/mods_asset'
|
36
36
|
require 'support/solr_document'
|
37
37
|
require "support/user"
|
38
|
-
require "
|
38
|
+
require "factory_bot"
|
39
39
|
require 'rspec/mocks'
|
40
40
|
require 'rspec/its'
|
41
41
|
require "factories"
|
data/spec/unit/ability_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe Ability do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
context "for a signed in user" do
|
34
|
-
let(:user) {
|
34
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
35
35
|
|
36
36
|
it { should_not be_able_to(:create, ActiveFedora::Base) }
|
37
37
|
end
|
@@ -42,7 +42,7 @@ describe Ability do
|
|
42
42
|
# Test coverage for discover permission is in spec/requests/gated_discovery_spec.rb
|
43
43
|
|
44
44
|
describe "Given an asset that has been made publicly discoverable" do
|
45
|
-
let(:asset) {
|
45
|
+
let(:asset) { FactoryBot.create(:asset) }
|
46
46
|
before do
|
47
47
|
asset.permissions_attributes = [{ name: "public", access: "discover", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }]
|
48
48
|
asset.save
|
@@ -58,7 +58,7 @@ describe Ability do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context "Then a registered user" do
|
61
|
-
let(:user) {
|
61
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
62
62
|
it { should be_able_to(:discover, asset) }
|
63
63
|
it { should_not be_able_to(:read, asset) }
|
64
64
|
it { should_not be_able_to(:edit, asset) }
|
@@ -68,8 +68,8 @@ describe Ability do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "Given an asset that has been made publicly available (ie. open access)" do
|
71
|
-
#let(:asset) {
|
72
|
-
let(:asset) {
|
71
|
+
#let(:asset) { FactoryBot.create(:open_access_asset) }
|
72
|
+
let(:asset) { FactoryBot.create(:asset) }
|
73
73
|
before do
|
74
74
|
asset.permissions_attributes = [{ name: "public", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }]
|
75
75
|
asset.save
|
@@ -85,7 +85,7 @@ describe Ability do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
context "Then a registered user" do
|
88
|
-
let(:user) {
|
88
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
89
89
|
it { should be_able_to(:discover, asset) }
|
90
90
|
it { should be_able_to(:read, asset) }
|
91
91
|
it { should_not be_able_to(:edit, asset) }
|
@@ -95,7 +95,7 @@ describe Ability do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "Given an asset with no custom access set" do
|
98
|
-
let(:asset) {
|
98
|
+
let(:asset) { FactoryBot.create(:asset) }
|
99
99
|
before do
|
100
100
|
asset.permissions_attributes = [{ name: "joe_creator", access: "edit", type: "person" }]
|
101
101
|
asset.save
|
@@ -110,7 +110,7 @@ describe Ability do
|
|
110
110
|
it { should_not be_able_to(:destroy, asset) }
|
111
111
|
end
|
112
112
|
context "Then a registered user" do
|
113
|
-
let(:user) {
|
113
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
114
114
|
it { should_not be_able_to(:discover, asset) }
|
115
115
|
it { should_not be_able_to(:read, asset) }
|
116
116
|
it { should_not be_able_to(:edit, asset) }
|
@@ -118,7 +118,7 @@ describe Ability do
|
|
118
118
|
it { should_not be_able_to(:destroy, asset) }
|
119
119
|
end
|
120
120
|
context "Then the Creator" do
|
121
|
-
let(:user) {
|
121
|
+
let(:user) { FactoryBot.build(:joe_creator) }
|
122
122
|
it { should be_able_to(:discover, asset) }
|
123
123
|
it { should be_able_to(:read, asset) }
|
124
124
|
it { should be_able_to(:edit, asset) }
|
@@ -132,14 +132,14 @@ describe Ability do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
describe "Given an asset which registered users have read access to" do
|
135
|
-
# let(:asset) {
|
136
|
-
let(:asset) {
|
135
|
+
# let(:asset) { FactoryBot.create(:org_read_access_asset) }
|
136
|
+
let(:asset) { FactoryBot.create(:asset) }
|
137
137
|
before do
|
138
138
|
asset.permissions_attributes = [{ name: "registered", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }]
|
139
139
|
asset.save
|
140
140
|
end
|
141
141
|
context "The a registered user" do
|
142
|
-
let(:user) {
|
142
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
143
143
|
before do
|
144
144
|
allow(user).to receive(:new_record?).and_return(false)
|
145
145
|
end
|
@@ -154,7 +154,7 @@ describe Ability do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
describe "Given an asset with collaborator" do
|
157
|
-
let(:asset) {
|
157
|
+
let(:asset) { FactoryBot.create(:asset) }
|
158
158
|
before do
|
159
159
|
asset.permissions_attributes = [{ name:"africana-faculty", access: "edit", type: "group" }, {name: "calvin_collaborator", access: "edit", type: "person"}]
|
160
160
|
asset.save
|
@@ -162,7 +162,7 @@ describe Ability do
|
|
162
162
|
after { asset.destroy }
|
163
163
|
|
164
164
|
context "Then a collaborator with edit access (user permision)" do
|
165
|
-
let(:user) {
|
165
|
+
let(:user) { FactoryBot.build(:calvin_collaborator) }
|
166
166
|
|
167
167
|
it { should be_able_to(:discover, asset) }
|
168
168
|
it { should be_able_to(:read, asset) }
|
@@ -173,7 +173,7 @@ describe Ability do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
context "Then a collaborator with edit access (group permision)" do
|
176
|
-
let(:user) {
|
176
|
+
let(:user) { FactoryBot.build(:martia_morocco) }
|
177
177
|
before do
|
178
178
|
allow(user).to receive(:groups).and_return(["faculty", "africana-faculty"])
|
179
179
|
end
|
@@ -183,14 +183,14 @@ describe Ability do
|
|
183
183
|
end
|
184
184
|
|
185
185
|
describe "Given an asset where dept can read & registered users can discover" do
|
186
|
-
# let(:asset) {
|
187
|
-
let(:asset) {
|
186
|
+
# let(:asset) { FactoryBot.create(:dept_access_asset) }
|
187
|
+
let(:asset) { FactoryBot.create(:asset) }
|
188
188
|
before do
|
189
189
|
asset.permissions_attributes = [{ name: "africana-faculty", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }]
|
190
190
|
asset.save
|
191
191
|
end
|
192
192
|
context "Then a registered user" do
|
193
|
-
let(:user) {
|
193
|
+
let(:user) { FactoryBot.build(:registered_user) }
|
194
194
|
|
195
195
|
it { should_not be_able_to(:discover, asset) }
|
196
196
|
it { should_not be_able_to(:read, asset) }
|
@@ -201,7 +201,7 @@ describe Ability do
|
|
201
201
|
end
|
202
202
|
|
203
203
|
context "Then someone whose role/group has read access" do
|
204
|
-
let(:user) {
|
204
|
+
let(:user) { FactoryBot.build(:martia_morocco) }
|
205
205
|
before do
|
206
206
|
allow(user).to receive(:groups).and_return(["faculty", "africana-faculty"])
|
207
207
|
end
|
@@ -228,7 +228,7 @@ describe Ability do
|
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
231
|
-
let(:user) {
|
231
|
+
let(:user) { FactoryBot.build(:staff) }
|
232
232
|
|
233
233
|
after do
|
234
234
|
Object.send(:remove_const, :MyAbility)
|
@@ -241,13 +241,13 @@ describe Ability do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
describe "calling ability on two separate objects" do
|
244
|
-
let(:asset1) {
|
245
|
-
let(:asset2) {
|
244
|
+
let(:asset1) { FactoryBot.create(:asset) }
|
245
|
+
let(:asset2) { FactoryBot.create(:asset) }
|
246
246
|
before do
|
247
247
|
asset1.permissions_attributes = [{ name: "registered", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }]
|
248
248
|
asset1.save
|
249
249
|
end
|
250
|
-
let(:user) {
|
250
|
+
let(:user) { FactoryBot.build(:calvin_collaborator) } # has access to @asset1, but not @asset2
|
251
251
|
after do
|
252
252
|
asset1.destroy
|
253
253
|
asset2.destroy
|
@@ -261,8 +261,8 @@ describe Ability do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
describe "download permissions" do
|
264
|
-
let(:asset) {
|
265
|
-
let(:user) {
|
264
|
+
let(:asset) { FactoryBot.create(:asset) }
|
265
|
+
let(:user) { FactoryBot.build(:user) }
|
266
266
|
let(:file) { ActiveFedora::File.new() }
|
267
267
|
|
268
268
|
before { allow(file).to receive(:uri).and_return(uri) }
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "active_fedora/accessible_by" do
|
4
|
-
let(:user) {
|
4
|
+
let(:user) {FactoryBot.build(:ira_instructor)}
|
5
5
|
let(:ability) {Ability.new(user)}
|
6
|
-
let(:private_obj) {
|
7
|
-
let(:public_obj) {
|
8
|
-
let(:editable_obj) {
|
6
|
+
let(:private_obj) {FactoryBot.create(:asset)}
|
7
|
+
let(:public_obj) {FactoryBot.create(:asset)}
|
8
|
+
let(:editable_obj) {FactoryBot.create(:asset)}
|
9
9
|
|
10
10
|
before do
|
11
11
|
private_obj.permissions_attributes = [{ name: "joe_creator", access: "edit", type: "person" }]
|
@@ -120,7 +120,7 @@ describe Hydra::AdminPolicy do
|
|
120
120
|
# Policy-based Access Controls
|
121
121
|
#
|
122
122
|
describe "When accessing assets with Policies associated" do
|
123
|
-
let(:user) {
|
123
|
+
let(:user) { FactoryBot.build(:martia_morocco) }
|
124
124
|
|
125
125
|
before do
|
126
126
|
allow(user).to receive(:groups).and_return(["faculty", "africana-faculty"])
|
@@ -62,7 +62,7 @@ describe Hydra::AccessControls::Permission do
|
|
62
62
|
|
63
63
|
context 'with a User instance passed as :name argument' do
|
64
64
|
let(:permission) { described_class.new(type: 'person', name: user, access: 'read') }
|
65
|
-
let(:user) {
|
65
|
+
let(:user) { FactoryBot.build(:archivist, email: 'archivist1@example.com') }
|
66
66
|
|
67
67
|
it "uses string and escape agent when building" do
|
68
68
|
expect(permission.agent.first.rdf_subject.to_s).to eq 'http://projecthydra.org/ns/auth/person#archivist1@example.com'
|
@@ -92,7 +92,7 @@ describe Hydra::PolicyAwareAccessControlsEnforcement do
|
|
92
92
|
|
93
93
|
let(:current_ability) { Ability.new(user) }
|
94
94
|
subject { PolicyMockSearchBuilder.new(current_ability) }
|
95
|
-
let(:user) {
|
95
|
+
let(:user) { FactoryBot.build(:sara_student) }
|
96
96
|
|
97
97
|
before do
|
98
98
|
@solr_parameters = {}
|
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: 10.5.
|
4
|
+
version: 10.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-04-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.6.
|
240
|
+
rubygems_version: 2.6.14
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Access controls for project hydra
|