ddr-models 2.4.10 → 2.4.11

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: cdb63bca20c6403cb271efc0fbef7a69e9639bd0
4
- data.tar.gz: a2ed58e92914138708aee15495f447396fbc1242
3
+ metadata.gz: 9f6ac7dc1bb1835e59f99ca9b246644a70fc4d24
4
+ data.tar.gz: 0cd424492af393a1855e072a89badf9a5d7c3147
5
5
  SHA512:
6
- metadata.gz: 1d6f7995169176b2705b96e2503af57a18e16c4490d6a3940b20b35881b5e1fdfa0d4655be1cbddd56217c42b4a3e2341f946cb3081651a9a395385dca757bdf
7
- data.tar.gz: 44ec9729ef02ac1bba6dd9a3390fded3583ea656c58936138498e03f8ca3695cb252120b41a5290102d8c8faded0bb1ad0222217ed309e3519949cd8956ea2f5
6
+ metadata.gz: 4c05eac1799eb32e833cb9e627f219a8d62dab865818c8b8845bc435f00883b528654e570f5f3d73a2669e945ce32f5f5e26e6315dac688b2363ac5d92e039fa
7
+ data.tar.gz: 5514e0c5c3946b10f23c57ef2af02ed8014e2989e1930e205d4944ddcc0e6cb7423a7c03ab18b64a301c0ff4e68809415c131193bc0f88cc676abf557a5a116b
@@ -9,4 +9,8 @@ class Attachment < Ddr::Models::Base
9
9
 
10
10
  belongs_to :attached_to, property: :is_attached_to, class_name: 'ActiveFedora::Base'
11
11
 
12
+ def publishable?
13
+ false
14
+ end
15
+
12
16
  end
@@ -49,6 +49,10 @@ class Collection < Ddr::Models::Base
49
49
  roles.grant type: Ddr::Auth::Roles::CURATOR, agent: creator.agent, scope: Ddr::Auth::Roles::POLICY_SCOPE
50
50
  end
51
51
 
52
+ def publishable?
53
+ true
54
+ end
55
+
52
56
  private
53
57
 
54
58
  def set_admin_policy
@@ -25,6 +25,10 @@ class Component < Ddr::Models::Base
25
25
  self.collection.internal_uri rescue nil
26
26
  end
27
27
 
28
+ def publishable?
29
+ parent.present? && parent.published?
30
+ end
31
+
28
32
  def index_parent
29
33
  Resque.enqueue(Ddr::Jobs::UpdateIndex, parent_id)
30
34
  end
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
@@ -12,4 +12,8 @@ class Target < Ddr::Models::Base
12
12
  has_many :components, property: :has_external_target, class_name: 'Component'
13
13
  belongs_to :collection, property: :is_external_target_for, class_name: 'Collection'
14
14
 
15
+ def publishable?
16
+ false
17
+ end
18
+
15
19
  end
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
@@ -10,6 +10,7 @@ module Ddr
10
10
  RoleBasedAbilityDefinitions,
11
11
  DatastreamAbilityDefinitions,
12
12
  EventAbilityDefinitions,
13
+ PublicationAbilityDefinitions,
13
14
  LockAbilityDefinitions ]
14
15
 
15
16
  end
@@ -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
@@ -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
@@ -102,6 +102,10 @@ module Ddr
102
102
  moved
103
103
  end
104
104
 
105
+ def publishable?
106
+ raise NotImplementedError, "Must be implemented by subclasses"
107
+ end
108
+
105
109
  end
106
110
  end
107
111
  end
@@ -25,7 +25,7 @@ module Ddr::Models
25
25
  datastream: "adminMetadata",
26
26
  multiple: false
27
27
 
28
- delegate :publish, :publish!, :unpublish, :unpublish!, :published?, to: :workflow
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?"
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.4.10"
3
+ VERSION = "2.4.11"
4
4
  end
5
5
  end
@@ -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
@@ -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) }
@@ -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.10
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-04-19 00:00:00.000000000 Z
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