ddr-models 2.4.9 → 2.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 118099299635f47da8f51b83cd5b80704b7e468f
4
- data.tar.gz: a40ea8e7ccddd6dfedab7d310a76becb8324c4a5
3
+ metadata.gz: cdb63bca20c6403cb271efc0fbef7a69e9639bd0
4
+ data.tar.gz: a2ed58e92914138708aee15495f447396fbc1242
5
5
  SHA512:
6
- metadata.gz: cf4764e68f14cbb08cc76466b13e6d037611fb3bd9dd01e21d9c95b7d6401f05b63523d93dca6a5f8e5b2399e3e8c00763ba660a50dfc975c36562aa64fac2f7
7
- data.tar.gz: c2b81312e83cb349158b66ce3ddceef637ad14f0ee12927822434ff5cc2726569402444d332a5bcd3e308210f8e9b4a9c3854776100d0f41471f60fae74e39f4
6
+ metadata.gz: 1d6f7995169176b2705b96e2503af57a18e16c4490d6a3940b20b35881b5e1fdfa0d4655be1cbddd56217c42b4a3e2341f946cb3081651a9a395385dca757bdf
7
+ data.tar.gz: 44ec9729ef02ac1bba6dd9a3390fded3583ea656c58936138498e03f8ca3695cb252120b41a5290102d8c8faded0bb1ad0222217ed309e3519949cd8956ea2f5
@@ -39,6 +39,7 @@ module Ddr
39
39
  autoload :DatastreamAbilityDefinitions
40
40
  autoload :EventAbilityDefinitions
41
41
  autoload :ItemAbilityDefinitions
42
+ autoload :LockAbilityDefinitions
42
43
  autoload :RoleBasedAbilityDefinitions
43
44
  autoload :SuperuserAbilityDefinitions
44
45
  end
@@ -9,7 +9,8 @@ module Ddr
9
9
  AttachmentAbilityDefinitions,
10
10
  RoleBasedAbilityDefinitions,
11
11
  DatastreamAbilityDefinitions,
12
- EventAbilityDefinitions ]
12
+ EventAbilityDefinitions,
13
+ LockAbilityDefinitions ]
13
14
 
14
15
  end
15
16
  end
@@ -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
@@ -49,6 +49,9 @@ module Ddr
49
49
  property :aspace_id,
50
50
  predicate: Ddr::Vocab::Asset.archivesSpaceId
51
51
 
52
+ property :is_locked,
53
+ predicate: Ddr::Vocab::Asset.isLocked
54
+
52
55
  end
53
56
  end
54
57
  end
@@ -35,6 +35,7 @@ module Ddr::Index
35
35
  IS_ATTACHED_TO = Field.new :is_attached_to, :symbol
36
36
  IS_EXTERNAL_TARGET_FOR = Field.new :is_external_target_for, :symbol
37
37
  IS_GOVERNED_BY = Field.new :is_governed_by, :symbol
38
+ IS_LOCKED = Field.new :is_locked, :stored_sortable
38
39
  IS_MEMBER_OF = Field.new :is_member_of, :symbol
39
40
  IS_MEMBER_OF_COLLECTION = Field.new :is_member_of_collection, :symbol
40
41
  IS_PART_OF = Field.new :is_part_of, :symbol
@@ -21,6 +21,7 @@ module Ddr::Models
21
21
  :workflow_state,
22
22
  :ead_id,
23
23
  :aspace_id,
24
+ :is_locked,
24
25
  datastream: "adminMetadata",
25
26
  multiple: false
26
27
 
@@ -82,6 +83,28 @@ module Ddr::Models
82
83
  end
83
84
  end
84
85
 
86
+ def locked?
87
+ !!is_locked
88
+ end
89
+
90
+ def lock
91
+ self.is_locked = true
92
+ end
93
+
94
+ def unlock
95
+ self.is_locked = false
96
+ end
97
+
98
+ def lock!
99
+ lock
100
+ save
101
+ end
102
+
103
+ def unlock!
104
+ unlock
105
+ save
106
+ end
107
+
85
108
  private
86
109
 
87
110
  def update_permanent_id_on_destroy
@@ -33,6 +33,7 @@ module Ddr
33
33
  FORMAT_FACET => format,
34
34
  IDENTIFIER_ALL => all_identifiers,
35
35
  INTERNAL_URI => internal_uri,
36
+ IS_LOCKED => is_locked,
36
37
  LICENSE => license,
37
38
  LICENSE_DESCRIPTION => rightsMetadata.license.description.first,
38
39
  LICENSE_TITLE => rightsMetadata.license.title.first,
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.4.9"
3
+ VERSION = "2.4.10"
4
4
  end
5
5
  end
@@ -21,6 +21,9 @@
21
21
  property "archivesSpaceId",
22
22
  label: "ArchivesSpace Identifier"
23
23
 
24
+ property "isLocked",
25
+ label: "Is Locked?"
26
+
24
27
  end
25
28
  end
26
29
  end
@@ -2,7 +2,7 @@ module Ddr::Auth
2
2
  RSpec.describe Ability, type: :model, abilities: true do
3
3
 
4
4
  subject { described_class.new(auth_context) }
5
-
5
+
6
6
  let(:auth_context) { FactoryGirl.build(:auth_context) }
7
7
 
8
8
  describe "aliases" do
@@ -144,6 +144,25 @@ module Ddr::Auth
144
144
  end
145
145
  end
146
146
 
147
+ describe "locks" do
148
+ let(:obj) { Ddr::Models::Base.new }
149
+
150
+ describe "effects of locks on abilities" do
151
+ before do
152
+ allow(obj).to receive(:effective_permissions) { Permissions::ALL }
153
+ allow(obj).to receive(:locked?) { true }
154
+ end
155
+ it { should be_able_to(:read, obj) }
156
+ it { should be_able_to(:download, obj) }
157
+ it { should_not be_able_to(:add_children, obj) }
158
+ it { should_not be_able_to(:update, obj) }
159
+ it { should_not be_able_to(:replace, obj) }
160
+ it { should_not be_able_to(:arrange, obj) }
161
+ it { should be_able_to(:audit, obj) }
162
+ it { should_not be_able_to(:grant, obj) }
163
+ end
164
+ end
165
+
147
166
  describe "role based abilities" do
148
167
  shared_examples "it has role based abilities" do
149
168
  describe "when permissions are cached" do
@@ -190,23 +190,77 @@ module Ddr::Models
190
190
  end
191
191
  end
192
192
 
193
- describe "contacts" do
194
- before do
195
- allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'xa') do
196
- {'id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A'}
197
- end
198
- allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'yb') do
199
- {'id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B'}
193
+ end
194
+
195
+ describe "contacts" do
196
+
197
+ subject { FactoryGirl.build(:item) }
198
+
199
+ before do
200
+ allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'xa') do
201
+ {'id'=>1, 'slug'=>'xa', 'name'=>'Contact A', 'short_name'=>'A'}
202
+ end
203
+ allow(Ddr::Models::Contact).to receive(:get).with(:find, slug: 'yb') do
204
+ {'id'=>1, 'slug'=>'yb', 'name'=>'Contact B', 'short_name'=>'B'}
205
+ end
206
+ end
207
+ describe "#research_help" do
208
+ before { subject.research_help_contact = 'yb' }
209
+ it "should return the appropriate contact" do
210
+ expect(subject.research_help.slug).to eq('yb')
211
+ end
212
+ end
213
+ end
214
+
215
+ describe "locking" do
216
+
217
+ subject { FactoryGirl.build(:item) }
218
+
219
+ describe "#locked?" do
220
+ context "object is locked" do
221
+ before { subject.is_locked = true }
222
+ it "should be true" do
223
+ expect(subject.locked?).to be true
200
224
  end
201
225
  end
202
- describe "#research_help" do
203
- before { subject.research_help_contact = 'yb' }
204
- it "should return the appropriate contact" do
205
- expect(subject.research_help.slug).to eq('yb')
226
+ context "object is not locked" do
227
+ it "should be false" do
228
+ expect(subject.locked?).to be false
206
229
  end
207
230
  end
208
231
  end
209
232
 
233
+ describe "lock" do
234
+ it "should lock the object" do
235
+ expect { subject.lock }.to change(subject, :locked?).from(false).to(true)
236
+ end
237
+ end
238
+
239
+ describe "unlock" do
240
+ before { subject.lock }
241
+ it "should unlock the object" do
242
+ expect { subject.unlock }.to change(subject, :locked?).from(true).to(false)
243
+ end
244
+ end
245
+
246
+ describe "lock!" do
247
+ it "should lock and save the object" do
248
+ subject.lock!
249
+ subject.reload
250
+ expect(subject.locked?).to be true
251
+ end
252
+ end
253
+
254
+ describe "unlock!" do
255
+ before { subject.lock! }
256
+ it "should unlock and save the object" do
257
+ subject.unlock!
258
+ subject.reload
259
+ expect(subject.locked?).to be false
260
+ end
261
+ end
262
+
210
263
  end
264
+
211
265
  end
212
266
  end
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: 2.4.9
4
+ version: 2.4.10
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-03-22 00:00:00.000000000 Z
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -405,6 +405,7 @@ files:
405
405
  - lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
406
406
  - lib/ddr/auth/ability_definitions/event_ability_definitions.rb
407
407
  - lib/ddr/auth/ability_definitions/item_ability_definitions.rb
408
+ - lib/ddr/auth/ability_definitions/lock_ability_definitions.rb
408
409
  - lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
409
410
  - lib/ddr/auth/ability_definitions/superuser_ability_definitions.rb
410
411
  - lib/ddr/auth/ability_factory.rb