ddr-models 3.0.0.beta.20 → 3.0.0.beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ddr/auth.rb +1 -0
- data/lib/ddr/auth/ability.rb +2 -1
- data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +13 -0
- data/lib/ddr/index/fields.rb +1 -0
- data/lib/ddr/index/query.rb +12 -1
- data/lib/ddr/index/query_result.rb +12 -1
- data/lib/ddr/models/has_admin_metadata.rb +26 -0
- data/lib/ddr/models/indexing.rb +2 -1
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/vocab/asset.rb +3 -0
- data/spec/auth/ability_spec.rb +19 -0
- data/spec/models/has_admin_metadata_spec.rb +65 -11
- data/spec/support/shared_examples_for_ddr_models.rb +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e3d477eef945d6636d2efdfd19053988b54b7b
|
4
|
+
data.tar.gz: 9775e2a63e01749a0594c131803133e57e38156a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9180d73d0e6c23c52bba318e5cf823172531819fc16696ec885a342a2ffde4918fa97167bcd093d1a64f0c5f7a3d428c6dd83f4c494f72a8b757650541af58e
|
7
|
+
data.tar.gz: d04f18db69f8183c65d6eef39ccfe915a220b5b4914f9a20ecea5f5add682e78d9bb709d5d572c1ad5ce45a7281130a7197f2cf0ef44e1b4214af48ac33e1dda
|
data/lib/ddr/auth.rb
CHANGED
@@ -38,6 +38,7 @@ module Ddr
|
|
38
38
|
autoload :DatastreamAbilityDefinitions
|
39
39
|
autoload :EventAbilityDefinitions
|
40
40
|
autoload :ItemAbilityDefinitions
|
41
|
+
autoload :LockAbilityDefinitions
|
41
42
|
autoload :PublicationAbilityDefinitions
|
42
43
|
autoload :RoleBasedAbilityDefinitions
|
43
44
|
autoload :SuperuserAbilityDefinitions
|
data/lib/ddr/auth/ability.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ddr
|
2
|
+
module Auth
|
3
|
+
class LockAbilityDefinitions < AbilityDefinitions
|
4
|
+
|
5
|
+
DENIED_WHEN_LOCKED = [ :add_children, :update, :replace, :arrange, :grant ]
|
6
|
+
|
7
|
+
def call
|
8
|
+
cannot DENIED_WHEN_LOCKED, Ddr::Models::Base, :locked? => true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/ddr/index/fields.rb
CHANGED
@@ -35,6 +35,7 @@ module Ddr::Index
|
|
35
35
|
IS_ATTACHED_TO = Field.new :is_attached_to, solr_name: "isAttachedTo_ssim"
|
36
36
|
IS_EXTERNAL_TARGET_FOR = Field.new :is_external_target_for, solr_name: "isExternalTargetFor_ssim"
|
37
37
|
IS_GOVERNED_BY = Field.new :is_governed_by, solr_name: "isGovernedBy_ssim"
|
38
|
+
IS_LOCKED = Field.new :is_locked, :stored_sortable
|
38
39
|
IS_MEMBER_OF_COLLECTION = Field.new :is_member_of_collection, solr_name: "isMemberOfCollection_ssim"
|
39
40
|
IS_PART_OF = Field.new :is_part_of, solr_name: "isPartOf_ssim"
|
40
41
|
LAST_FIXITY_CHECK_ON = Field.new :last_fixity_check_on, :stored_sortable, type: :date
|
data/lib/ddr/index/query.rb
CHANGED
@@ -5,6 +5,7 @@ module Ddr::Index
|
|
5
5
|
class Query
|
6
6
|
include Virtus.model
|
7
7
|
extend Forwardable
|
8
|
+
extend Deprecation
|
8
9
|
|
9
10
|
attribute :q, String
|
10
11
|
attribute :fields, Array[FieldAttribute], default: [ ]
|
@@ -12,7 +13,7 @@ module Ddr::Index
|
|
12
13
|
attribute :sort, Array[String], default: [ ]
|
13
14
|
attribute :rows, Integer
|
14
15
|
|
15
|
-
delegate [:count, :docs, :
|
16
|
+
delegate [:count, :docs, :ids, :each_id, :all] => :result
|
16
17
|
delegate :params => :query_params
|
17
18
|
|
18
19
|
def initialize(**args, &block)
|
@@ -31,6 +32,16 @@ module Ddr::Index
|
|
31
32
|
URI.encode_www_form(params)
|
32
33
|
end
|
33
34
|
|
35
|
+
def pids
|
36
|
+
Deprecation.warn(QueryResult, "`pids` is deprecated; use `ids` instead.")
|
37
|
+
ids
|
38
|
+
end
|
39
|
+
|
40
|
+
def each_pid(&block)
|
41
|
+
Deprecation.warn(QueryResult, "`each_pid` is deprecated; use `each_id` instead.")
|
42
|
+
each_id(&block)
|
43
|
+
end
|
44
|
+
|
34
45
|
def result
|
35
46
|
QueryResult.new(self)
|
36
47
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Ddr::Index
|
2
2
|
class QueryResult < AbstractQueryResult
|
3
|
+
extend Deprecation
|
3
4
|
|
4
5
|
PAGE_SIZE = 1000
|
5
6
|
|
@@ -22,6 +23,11 @@ module Ddr::Index
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def pids
|
26
|
+
Deprecation.warn(QueryResult, "`pids` is deprecated; use `ids` instead.")
|
27
|
+
ids
|
28
|
+
end
|
29
|
+
|
30
|
+
def ids
|
25
31
|
Enumerator.new do |e|
|
26
32
|
each do |doc|
|
27
33
|
e << doc[Fields::ID]
|
@@ -30,7 +36,12 @@ module Ddr::Index
|
|
30
36
|
end
|
31
37
|
|
32
38
|
def each_pid(&block)
|
33
|
-
|
39
|
+
Deprecation.warn(QueryResult, "`each_pid` is deprecated; use `each_id` instead.")
|
40
|
+
each_id(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def each_id(&block)
|
44
|
+
ids.each(&block)
|
34
45
|
end
|
35
46
|
|
36
47
|
def docs
|
@@ -37,6 +37,10 @@ module Ddr::Models
|
|
37
37
|
predicate: RDF::URI("info:fedora/fedora-system:def/model#PID"),
|
38
38
|
multiple: false
|
39
39
|
|
40
|
+
property :is_locked,
|
41
|
+
predicate: Ddr::Vocab::Asset.isLocked,
|
42
|
+
multiple: false
|
43
|
+
|
40
44
|
property :license,
|
41
45
|
predicate: RDF::Vocab::DC.license,
|
42
46
|
multiple: false
|
@@ -119,6 +123,28 @@ module Ddr::Models
|
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
126
|
+
def locked?
|
127
|
+
!!is_locked
|
128
|
+
end
|
129
|
+
|
130
|
+
def lock
|
131
|
+
self.is_locked = true
|
132
|
+
end
|
133
|
+
|
134
|
+
def unlock
|
135
|
+
self.is_locked = false
|
136
|
+
end
|
137
|
+
|
138
|
+
def lock!
|
139
|
+
lock
|
140
|
+
save
|
141
|
+
end
|
142
|
+
|
143
|
+
def unlock!
|
144
|
+
unlock
|
145
|
+
save
|
146
|
+
end
|
147
|
+
|
122
148
|
private
|
123
149
|
|
124
150
|
def update_permanent_id_on_destroy
|
data/lib/ddr/models/indexing.rb
CHANGED
@@ -34,6 +34,7 @@ module Ddr
|
|
34
34
|
FCREPO3_PID => fcrepo3_pid,
|
35
35
|
FORMAT_FACET => desc_metadata.format,
|
36
36
|
IDENTIFIER_ALL => all_identifiers,
|
37
|
+
IS_LOCKED => is_locked,
|
37
38
|
LICENSE => license,
|
38
39
|
LOCAL_ID => local_id,
|
39
40
|
PERMANENT_ID => permanent_id,
|
@@ -101,7 +102,7 @@ module Ddr
|
|
101
102
|
end
|
102
103
|
|
103
104
|
def all_identifiers
|
104
|
-
desc_metadata.identifier + [local_id, permanent_id, id].compact
|
105
|
+
desc_metadata.identifier + [fcrepo3_pid, local_id, permanent_id, id].compact
|
105
106
|
end
|
106
107
|
|
107
108
|
def associated_collection
|
data/lib/ddr/models/version.rb
CHANGED
data/lib/ddr/vocab/asset.rb
CHANGED
data/spec/auth/ability_spec.rb
CHANGED
@@ -210,6 +210,25 @@ module Ddr::Auth
|
|
210
210
|
|
211
211
|
end
|
212
212
|
|
213
|
+
describe "locks" do
|
214
|
+
let(:obj) { Ddr::Models::Base.new }
|
215
|
+
|
216
|
+
describe "effects of locks on abilities" do
|
217
|
+
before do
|
218
|
+
allow(obj).to receive(:effective_permissions) { Permissions::ALL }
|
219
|
+
allow(obj).to receive(:locked?) { true }
|
220
|
+
end
|
221
|
+
it { should be_able_to(:read, obj) }
|
222
|
+
it { should be_able_to(:download, obj) }
|
223
|
+
it { should_not be_able_to(:add_children, obj) }
|
224
|
+
it { should_not be_able_to(:update, obj) }
|
225
|
+
it { should_not be_able_to(:replace, obj) }
|
226
|
+
it { should_not be_able_to(:arrange, obj) }
|
227
|
+
it { should be_able_to(:audit, obj) }
|
228
|
+
it { should_not be_able_to(:grant, obj) }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
213
232
|
describe "role based abilities" do
|
214
233
|
shared_examples "it has role based abilities" do
|
215
234
|
describe "when permissions are cached" do
|
@@ -198,23 +198,77 @@ module Ddr::Models
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "contacts" do
|
204
|
+
|
205
|
+
subject { FactoryGirl.build(:item) }
|
206
|
+
|
207
|
+
before do
|
208
|
+
allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'xa') do
|
209
|
+
{'id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A'}
|
210
|
+
end
|
211
|
+
allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'yb') do
|
212
|
+
{'id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B'}
|
213
|
+
end
|
214
|
+
end
|
215
|
+
describe "#research_help" do
|
216
|
+
before { subject.research_help_contact = 'yb' }
|
217
|
+
it "should return the appropriate contact" do
|
218
|
+
expect(subject.research_help.slug).to eq('yb')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "locking" do
|
224
|
+
|
225
|
+
subject { FactoryGirl.build(:item) }
|
226
|
+
|
227
|
+
describe "#locked?" do
|
228
|
+
context "object is locked" do
|
229
|
+
before { subject.is_locked = true }
|
230
|
+
it "should be true" do
|
231
|
+
expect(subject.locked?).to be true
|
208
232
|
end
|
209
233
|
end
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
expect(subject.research_help.slug).to eq('yb')
|
234
|
+
context "object is not locked" do
|
235
|
+
it "should be false" do
|
236
|
+
expect(subject.locked?).to be false
|
214
237
|
end
|
215
238
|
end
|
216
239
|
end
|
217
240
|
|
241
|
+
describe "lock" do
|
242
|
+
it "should lock the object" do
|
243
|
+
expect { subject.lock }.to change(subject, :locked?).from(false).to(true)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe "unlock" do
|
248
|
+
before { subject.lock }
|
249
|
+
it "should unlock the object" do
|
250
|
+
expect { subject.unlock }.to change(subject, :locked?).from(true).to(false)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "lock!" do
|
255
|
+
it "should lock and save the object" do
|
256
|
+
subject.lock!
|
257
|
+
subject.reload
|
258
|
+
expect(subject.locked?).to be true
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "unlock!" do
|
263
|
+
before { subject.lock! }
|
264
|
+
it "should unlock and save the object" do
|
265
|
+
subject.unlock!
|
266
|
+
subject.reload
|
267
|
+
expect(subject.locked?).to be false
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
218
271
|
end
|
272
|
+
|
219
273
|
end
|
220
274
|
end
|
@@ -101,17 +101,18 @@ RSpec.shared_examples "a DDR model" do
|
|
101
101
|
|
102
102
|
describe "#all_identifiers" do
|
103
103
|
subject { described_class.new(id: 'test-3') }
|
104
|
-
context "when it has descriptive identifiers, local ID, permanent ID, and id" do
|
104
|
+
context "when it has descriptive identifiers, Fedora 3 PID, local ID, permanent ID, and id" do
|
105
105
|
before do
|
106
106
|
subject.desc_metadata.identifier = [ 'ID001', 'ID002' ]
|
107
|
+
subject.fcrepo3_pid = 'test:92'
|
107
108
|
subject.local_id = 'LOCAL_ID_A'
|
108
109
|
subject.permanent_id = 'ark:/999999/cd3'
|
109
110
|
end
|
110
111
|
its(:all_identifiers) {
|
111
|
-
is_expected.to match_array([ 'ID001', 'ID002', 'LOCAL_ID_A', 'ark:/999999/cd3', 'test-3' ])
|
112
|
+
is_expected.to match_array([ 'ID001', 'ID002', 'test:92', 'LOCAL_ID_A', 'ark:/999999/cd3', 'test-3' ])
|
112
113
|
}
|
113
114
|
end
|
114
|
-
context "when it has no descriptive identifiers or local ID" do
|
115
|
+
context "when it has no descriptive identifiers, Fedora 3 PID, or local ID" do
|
115
116
|
before { subject.permanent_id = 'ark:/999999/cd3' }
|
116
117
|
its(:all_identifiers) {
|
117
118
|
is_expected.to match_array([ 'ark:/999999/cd3', 'test-3' ])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.beta.
|
4
|
+
version: 3.0.0.beta.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -424,6 +424,7 @@ files:
|
|
424
424
|
- lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
|
425
425
|
- lib/ddr/auth/ability_definitions/event_ability_definitions.rb
|
426
426
|
- lib/ddr/auth/ability_definitions/item_ability_definitions.rb
|
427
|
+
- lib/ddr/auth/ability_definitions/lock_ability_definitions.rb
|
427
428
|
- lib/ddr/auth/ability_definitions/publication_ability_definitions.rb
|
428
429
|
- lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
|
429
430
|
- lib/ddr/auth/ability_definitions/superuser_ability_definitions.rb
|