ddr-models 2.4.10 → 2.4.11
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/app/models/attachment.rb +4 -0
- data/app/models/collection.rb +4 -0
- data/app/models/component.rb +4 -0
- data/app/models/item.rb +4 -0
- data/app/models/target.rb +4 -0
- data/lib/ddr/auth.rb +1 -0
- data/lib/ddr/auth/ability.rb +1 -0
- data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +16 -0
- data/lib/ddr/auth/permissions.rb +3 -1
- data/lib/ddr/models/base.rb +4 -0
- data/lib/ddr/models/has_admin_metadata.rb +1 -1
- data/lib/ddr/models/version.rb +1 -1
- data/spec/auth/ability_spec.rb +49 -0
- data/spec/models/attachment_spec.rb +1 -0
- data/spec/models/collection_spec.rb +1 -0
- data/spec/models/component_spec.rb +1 -0
- data/spec/models/has_admin_metadata_spec.rb +0 -15
- data/spec/models/item_spec.rb +1 -0
- data/spec/models/target_spec.rb +1 -0
- data/spec/support/shared_examples_for_publication.rb +43 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f6ac7dc1bb1835e59f99ca9b246644a70fc4d24
|
4
|
+
data.tar.gz: 0cd424492af393a1855e072a89badf9a5d7c3147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c05eac1799eb32e833cb9e627f219a8d62dab865818c8b8845bc435f00883b528654e570f5f3d73a2669e945ce32f5f5e26e6315dac688b2363ac5d92e039fa
|
7
|
+
data.tar.gz: 5514e0c5c3946b10f23c57ef2af02ed8014e2989e1930e205d4944ddcc0e6cb7423a7c03ab18b64a301c0ff4e68809415c131193bc0f88cc676abf557a5a116b
|
data/app/models/attachment.rb
CHANGED
data/app/models/collection.rb
CHANGED
data/app/models/component.rb
CHANGED
data/app/models/item.rb
CHANGED
@@ -21,6 +21,10 @@ class Item < Ddr::Models::Base
|
|
21
21
|
alias_method :collection_id, :parent_id
|
22
22
|
alias_method :collection=, :parent=
|
23
23
|
|
24
|
+
def publishable?
|
25
|
+
parent.present? && parent.published?
|
26
|
+
end
|
27
|
+
|
24
28
|
def children_having_extracted_text
|
25
29
|
item = self
|
26
30
|
Ddr::Index::Query.new do
|
data/app/models/target.rb
CHANGED
data/lib/ddr/auth.rb
CHANGED
@@ -39,6 +39,7 @@ module Ddr
|
|
39
39
|
autoload :DatastreamAbilityDefinitions
|
40
40
|
autoload :EventAbilityDefinitions
|
41
41
|
autoload :ItemAbilityDefinitions
|
42
|
+
autoload :PublicationAbilityDefinitions
|
42
43
|
autoload :LockAbilityDefinitions
|
43
44
|
autoload :RoleBasedAbilityDefinitions
|
44
45
|
autoload :SuperuserAbilityDefinitions
|
data/lib/ddr/auth/ability.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ddr
|
2
|
+
module Auth
|
3
|
+
class PublicationAbilityDefinitions < AbilityDefinitions
|
4
|
+
|
5
|
+
def call
|
6
|
+
cannot :publish, Ddr::Models::Base do |obj|
|
7
|
+
obj.published? || !obj.publishable?
|
8
|
+
end
|
9
|
+
cannot :unpublish, Ddr::Models::Base do |obj|
|
10
|
+
!obj.published?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ddr/auth/permissions.rb
CHANGED
@@ -8,10 +8,12 @@ module Ddr::Auth
|
|
8
8
|
UPDATE = :update
|
9
9
|
REPLACE = :replace
|
10
10
|
ARRANGE = :arrange
|
11
|
+
PUBLISH = :publish
|
12
|
+
UNPUBLISH = :unpublish
|
11
13
|
AUDIT = :audit
|
12
14
|
GRANT = :grant
|
13
15
|
|
14
|
-
ALL = [ READ, DOWNLOAD, ADD_CHILDREN, UPDATE, REPLACE, ARRANGE, AUDIT, GRANT ]
|
16
|
+
ALL = [ READ, DOWNLOAD, ADD_CHILDREN, UPDATE, REPLACE, ARRANGE, PUBLISH, UNPUBLISH, AUDIT, GRANT ]
|
15
17
|
|
16
18
|
def self.const_missing(name)
|
17
19
|
if name == :EDIT
|
data/lib/ddr/models/base.rb
CHANGED
@@ -25,7 +25,7 @@ module Ddr::Models
|
|
25
25
|
datastream: "adminMetadata",
|
26
26
|
multiple: false
|
27
27
|
|
28
|
-
delegate :publish
|
28
|
+
delegate :publish!, :unpublish!, :published?, to: :workflow
|
29
29
|
|
30
30
|
after_create :assign_permanent_id!, if: "Ddr::Models.auto_assign_permanent_ids"
|
31
31
|
around_destroy :update_permanent_id_on_destroy, if: "permanent_id.present?"
|
data/lib/ddr/models/version.rb
CHANGED
data/spec/auth/ability_spec.rb
CHANGED
@@ -144,6 +144,55 @@ module Ddr::Auth
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
+
describe "publication abilities" do
|
148
|
+
let(:obj) { Ddr::Models::Base.new }
|
149
|
+
|
150
|
+
describe "publish" do
|
151
|
+
describe "when role-based permissions permit publish" do
|
152
|
+
before do
|
153
|
+
allow(obj).to receive(:effective_permissions) { [ Permissions::PUBLISH ] }
|
154
|
+
end
|
155
|
+
describe "when the object is published" do
|
156
|
+
before { allow(obj).to receive(:published?) { true } }
|
157
|
+
it { should_not be_able_to(:publish, obj) }
|
158
|
+
end
|
159
|
+
describe "when the object is not published" do
|
160
|
+
describe "when the object is publishable" do
|
161
|
+
before { allow(obj).to receive(:publishable?) { true } }
|
162
|
+
it { should be_able_to(:publish, obj) }
|
163
|
+
end
|
164
|
+
describe "when the object is not publishable" do
|
165
|
+
before { allow(obj).to receive(:publishable?) { false } }
|
166
|
+
it { should_not be_able_to(:publish, obj) }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
describe "when role-based permissions do not permit publish" do
|
171
|
+
before { allow(obj).to receive(:publishable?) { true } }
|
172
|
+
it { should_not be_able_to(:publish, obj) }
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "unpublish" do
|
177
|
+
describe "when role-based permissions permit unpublish" do
|
178
|
+
before do
|
179
|
+
allow(obj).to receive(:effective_permissions) { [ Permissions::UNPUBLISH ] }
|
180
|
+
end
|
181
|
+
describe "when the object is published" do
|
182
|
+
before { allow(obj).to receive(:published?) { true } }
|
183
|
+
it { should be_able_to(:unpublish, obj) }
|
184
|
+
end
|
185
|
+
describe "when the object is not published" do
|
186
|
+
it { should_not be_able_to(:unpublish, obj) }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
describe "when role-based permissions do not permit unpublish" do
|
190
|
+
it { should_not be_able_to(:unpublish, obj) }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
147
196
|
describe "locks" do
|
148
197
|
let(:obj) { Ddr::Models::Base.new }
|
149
198
|
|
@@ -6,5 +6,6 @@ RSpec.describe Attachment, type: :model, attachments: true do
|
|
6
6
|
it_behaves_like "an object that can have content"
|
7
7
|
it_behaves_like "it has an association", :belongs_to, :attached_to, :is_attached_to, "ActiveFedora::Base"
|
8
8
|
it_behaves_like "a non-collection model"
|
9
|
+
it_behaves_like "an unpublishable object"
|
9
10
|
|
10
11
|
end
|
@@ -5,6 +5,7 @@ RSpec.describe Collection, type: :model do
|
|
5
5
|
it_behaves_like "a DDR model"
|
6
6
|
it_behaves_like "it has an association", :has_many, :children, :is_member_of_collection, "Item"
|
7
7
|
it_behaves_like "it has an association", :has_many, :targets, :is_external_target_for, "Target"
|
8
|
+
it_behaves_like "a publishable object"
|
8
9
|
|
9
10
|
describe "legacy license information" do
|
10
11
|
before do
|
@@ -7,6 +7,7 @@ RSpec.describe Component, type: :model, components: true do
|
|
7
7
|
it_behaves_like "it has an association", :belongs_to, :parent, :is_part_of, "Item"
|
8
8
|
it_behaves_like "it has an association", :belongs_to, :target, :has_external_target, "Target"
|
9
9
|
it_behaves_like "a non-collection model"
|
10
|
+
it_behaves_like "a potentially publishable object"
|
10
11
|
|
11
12
|
describe "indexing" do
|
12
13
|
subject { FactoryGirl.build(:component) }
|
@@ -121,13 +121,6 @@ module Ddr::Models
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
describe "#publish" do
|
125
|
-
it "should publish the object" do
|
126
|
-
subject.publish
|
127
|
-
expect(subject).to be_published
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
124
|
describe "#publish!" do
|
132
125
|
it "should publish and persist the object" do
|
133
126
|
subject.publish!
|
@@ -135,14 +128,6 @@ module Ddr::Models
|
|
135
128
|
end
|
136
129
|
end
|
137
130
|
|
138
|
-
describe "#unpublish" do
|
139
|
-
before { subject.publish }
|
140
|
-
it "should unpublish the object" do
|
141
|
-
subject.unpublish
|
142
|
-
expect(subject).not_to be_published
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
131
|
describe "#unpublish!" do
|
147
132
|
before { subject.publish! }
|
148
133
|
it "should unpublish and persist the object" do
|
data/spec/models/item_spec.rb
CHANGED
@@ -6,6 +6,7 @@ RSpec.describe Item, type: :model do
|
|
6
6
|
it_behaves_like "it has an association", :belongs_to, :parent, :is_member_of_collection, "Collection"
|
7
7
|
it_behaves_like "it has an association", :has_many, :children, :is_part_of, "Component"
|
8
8
|
it_behaves_like "a non-collection model"
|
9
|
+
it_behaves_like "a potentially publishable object"
|
9
10
|
|
10
11
|
describe "indexing text" do
|
11
12
|
let(:children) { FactoryGirl.build_list(:component, 5) }
|
data/spec/models/target_spec.rb
CHANGED
@@ -7,5 +7,6 @@ RSpec.describe Target, type: :model, targets: true do
|
|
7
7
|
it_behaves_like "it has an association", :has_many, :components, :has_external_target, "Component"
|
8
8
|
it_behaves_like "it has an association", :belongs_to, :collection, :is_external_target_for, "Collection"
|
9
9
|
it_behaves_like "a non-collection model"
|
10
|
+
it_behaves_like "an unpublishable object"
|
10
11
|
|
11
12
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
RSpec.shared_examples 'a publishable object' do
|
2
|
+
describe '#publishable?' do
|
3
|
+
let(:object) { described_class.new }
|
4
|
+
it 'should be publishable' do
|
5
|
+
expect(object.publishable?).to be true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.shared_examples 'an unpublishable object' do
|
11
|
+
describe '#publishable?' do
|
12
|
+
let(:object) { described_class.new }
|
13
|
+
it 'should not be publishable' do
|
14
|
+
expect(object.publishable?).to be false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.shared_examples 'a potentially publishable object' do
|
20
|
+
describe "#publishable?" do
|
21
|
+
let(:object) { described_class.new }
|
22
|
+
context "has parent" do
|
23
|
+
before { allow(object).to receive(:parent) { parent } }
|
24
|
+
context "parent is published" do
|
25
|
+
let(:parent) { double(published?: true) }
|
26
|
+
it "should be publishable" do
|
27
|
+
expect(object.publishable?).to be true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "parent is not published" do
|
31
|
+
let(:parent) { double(published?: false) }
|
32
|
+
it "should not be publishable" do
|
33
|
+
expect(object.publishable?).to be false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context "does not have parent" do
|
38
|
+
it "should not be publishable" do
|
39
|
+
expect(object.publishable?).to be false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
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.
|
4
|
+
version: 2.4.11
|
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-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -406,6 +406,7 @@ files:
|
|
406
406
|
- lib/ddr/auth/ability_definitions/event_ability_definitions.rb
|
407
407
|
- lib/ddr/auth/ability_definitions/item_ability_definitions.rb
|
408
408
|
- lib/ddr/auth/ability_definitions/lock_ability_definitions.rb
|
409
|
+
- lib/ddr/auth/ability_definitions/publication_ability_definitions.rb
|
409
410
|
- lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
|
410
411
|
- lib/ddr/auth/ability_definitions/superuser_ability_definitions.rb
|
411
412
|
- lib/ddr/auth/ability_factory.rb
|
@@ -695,6 +696,7 @@ files:
|
|
695
696
|
- spec/support/shared_examples_for_has_content.rb
|
696
697
|
- spec/support/shared_examples_for_indexing.rb
|
697
698
|
- spec/support/shared_examples_for_non_collection_models.rb
|
699
|
+
- spec/support/shared_examples_for_publication.rb
|
698
700
|
- spec/support/shared_examples_for_role_sets.rb
|
699
701
|
- spec/support/structural_metadata_helper.rb
|
700
702
|
- spec/utils_spec.rb
|
@@ -870,6 +872,7 @@ test_files:
|
|
870
872
|
- spec/support/shared_examples_for_has_content.rb
|
871
873
|
- spec/support/shared_examples_for_indexing.rb
|
872
874
|
- spec/support/shared_examples_for_non_collection_models.rb
|
875
|
+
- spec/support/shared_examples_for_publication.rb
|
873
876
|
- spec/support/shared_examples_for_role_sets.rb
|
874
877
|
- spec/support/structural_metadata_helper.rb
|
875
878
|
- spec/utils_spec.rb
|