ddr-models 3.0.0.beta.13 → 3.0.0.beta.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd624d042a8843b603251a3e2335de11250c7cc7
4
- data.tar.gz: 475629a158b74fcf445d2e75bc6a02df8df0eaab
3
+ metadata.gz: fa7faeec493c42d29c2ac9af03f8db073c700678
4
+ data.tar.gz: 9688fa99bde0eaffc03946d490e0f0413fa58ce0
5
5
  SHA512:
6
- metadata.gz: b9b86d95736d6d52758b5c9102fba56ec686a2e6c7d2e03904d52917009b002b4e6e533c51df410d6ef6ed2922fb38c36ffe7bcdacbeb607c6f6140e26818e10
7
- data.tar.gz: 9bc4aab3edea2950ae8115ba3948eb976cb368b2dccb513eace66fb59bc8798e4963e0aea3560a0ec093354485c7a91c9688fefc3f6d9262ded9be1874f71e70
6
+ metadata.gz: 383c3cfc797bdf3a6665fb5cf1c275eb4447e85b51cda3c9ff89f2405dfc079cc4a06f679500a1ec68abade1d0908393adc599e46a62e40976c7d580cd46aa0e
7
+ data.tar.gz: 1763c37c4f8e28444ebe303de40e0a85c87411943c28694205e3957e8b0a12c10822f3224669ba52139b4ca39909c3b4ca085eacf030724c6e5b11594b5b5ae9
@@ -3,11 +3,11 @@ module Ddr
3
3
  class PublicationAbilityDefinitions < AbilityDefinitions
4
4
 
5
5
  def call
6
- can :publish, Ddr::Models::Base do |obj|
7
- !obj.published? && obj.publishable?
6
+ cannot :publish, Ddr::Models::Base do |obj|
7
+ obj.published? || !obj.publishable?
8
8
  end
9
- can :unpublish, Ddr::Models::Base do |obj|
10
- obj.published?
9
+ cannot :unpublish, Ddr::Models::Base do |obj|
10
+ !obj.published?
11
11
  end
12
12
  end
13
13
 
@@ -76,6 +76,7 @@ module Ddr::Index
76
76
  TECHMD_WELL_FORMED = Field.new :techmd_well_formed, :symbol
77
77
  TITLE = Field.new :title, :stored_sortable
78
78
  TYPE_FACET = Field.new :type_facet, :facetable
79
+ UNIQUE_ID = Field.new :unique_id, :searchable, type: :symbol
79
80
  WORKFLOW_STATE = Field.new :workflow_state, :stored_sortable
80
81
  YEAR_FACET = Field.new :year_facet, solr_name: "year_facet_iim"
81
82
 
@@ -22,10 +22,32 @@ module Ddr::Models
22
22
  end
23
23
  end
24
24
 
25
+ def self.find_by_unique_id(unique_id)
26
+ if result = where(Ddr::Index::Fields::UNIQUE_ID => unique_id).first
27
+ result
28
+ else
29
+ raise ActiveFedora::ObjectNotFoundError,
30
+ "#{self} not found having unique id #{unique_id.inspect}."
31
+ end
32
+ end
33
+
34
+ def unique_ids
35
+ [id, permanent_id, permanent_id_suffix].compact
36
+ end
37
+
25
38
  def inspect
26
39
  "#<#{model_and_id}, uri: \"#{uri}\">"
27
40
  end
28
41
 
42
+ def permanent_id_suffix
43
+ permanent_id && permanent_id.sub(/\Aark:\/\d+\//, "")
44
+ end
45
+
46
+ # @see ActiveModel::Conversion
47
+ def to_key
48
+ (key = permanent_id_suffix) ? [key] : super
49
+ end
50
+
29
51
  def model_and_id
30
52
  "#{self.class} id: #{id.inspect || '[NEW]'}"
31
53
  end
@@ -116,10 +138,6 @@ module Ddr::Models
116
138
  false
117
139
  end
118
140
 
119
- def adminMetadata
120
- self
121
- end
122
-
123
141
  def datastreams_to_validate
124
142
  Deprecation.warn(FixityCheckable, "`datastreams_to_validate` is deprecated." \
125
143
  " Use `attached_files_having_content` instead.")
@@ -45,6 +45,7 @@ module Ddr
45
45
  SUBJECT_FACET => desc_metadata.values('subject'),
46
46
  TITLE => title_display,
47
47
  TYPE_FACET => desc_metadata.type,
48
+ UNIQUE_ID => unique_ids,
48
49
  WORKFLOW_STATE => workflow_state,
49
50
  YEAR_FACET => year_facet,
50
51
  }
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "3.0.0.beta.13"
3
+ VERSION = "3.0.0.beta.14"
4
4
  end
5
5
  end
@@ -148,28 +148,45 @@ module Ddr::Auth
148
148
  let(:obj) { Ddr::Models::Base.new }
149
149
 
150
150
  describe "publish" do
151
- describe "when the object is published" do
152
- before { allow(obj).to receive(:published?) { true } }
153
- it { should_not be_able_to(:publish, obj) }
154
- end
155
- describe "when the object is not published" do
156
- describe "when the object is publishable" do
157
- before { allow(obj).to receive(:publishable?) { true } }
158
- it { should be_able_to(:publish, obj) }
151
+ describe "when role-based permissions permit publish" do
152
+ before do
153
+ allow(obj).to receive(:effective_permissions) { [ Permissions::PUBLISH ] }
159
154
  end
160
- describe "when the object is not publishable" do
161
- before { allow(obj).to receive(:publishable?) { false } }
155
+ describe "when the object is published" do
156
+ before { allow(obj).to receive(:published?) { true } }
162
157
  it { should_not be_able_to(:publish, obj) }
163
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) }
164
173
  end
165
174
  end
166
175
 
167
176
  describe "unpublish" do
168
- describe "when the object is published" do
169
- before { allow(obj).to receive(:published?) { true } }
170
- it { should be_able_to(:unpublish, obj) }
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
171
188
  end
172
- describe "when the object is not published" do
189
+ describe "when role-based permissions do not permit unpublish" do
173
190
  it { should_not be_able_to(:unpublish, obj) }
174
191
  end
175
192
  end
@@ -12,28 +12,41 @@ module Ddr::Models
12
12
  let(:role4) { FactoryGirl.build(:role, :editor, :person, :policy) }
13
13
 
14
14
  before do
15
+ obj.aspace_id = "aspace_dccea43034e1b8261e14cf999e86449d"
16
+ obj.display_format = "Image"
17
+ obj.doi << "http://doi.org/10.1000/182"
18
+ obj.fcrepo3_pid = "duke:1"
15
19
  obj.license = "cc-by-nc-nd-40"
16
20
  obj.local_id = "foo"
17
- obj.doi << "http://doi.org/10.1000/182"
18
21
  obj.permanent_id = "ark:/99999/fk4zzz"
19
22
  obj.permanent_url = "http://id.library.duke.edu/ark:/99999/fk4zzz"
20
- obj.display_format = "Image"
21
23
  obj.roles.grant role1, role2, role3, role4
22
- obj.aspace_id = "aspace_dccea43034e1b8261e14cf999e86449d"
23
- obj.fcrepo3_pid = "duke:1"
24
+ obj.save
25
+ obj.reload
24
26
  end
25
27
 
28
+ its([Indexing::ACCESS_ROLE]) { is_expected.to eq(obj.roles.to_json) }
29
+ its([Indexing::ASPACE_ID]) { is_expected.to eq("aspace_dccea43034e1b8261e14cf999e86449d") }
30
+ its([Indexing::DISPLAY_FORMAT]) { is_expected.to eq("Image") }
31
+ its([Indexing::DOI]) { is_expected.to eq(["http://doi.org/10.1000/182"]) }
32
+ its([Indexing::FCREPO3_PID]) { is_expected.to eq("duke:1") }
26
33
  its([Indexing::LICENSE]) { is_expected.to eq("cc-by-nc-nd-40") }
27
34
  its([Indexing::LOCAL_ID]) { is_expected.to eq("foo") }
28
- its([Indexing::DOI]) { is_expected.to eq(["http://doi.org/10.1000/182"]) }
29
35
  its([Indexing::PERMANENT_ID]) { is_expected.to eq("ark:/99999/fk4zzz") }
30
- its([Indexing::PERMANENT_URL]) { is_expected.to eq("http://id.library.duke.edu/ark:/99999/fk4zzz") }
31
- its([Indexing::DISPLAY_FORMAT]) { is_expected.to eq("Image") }
32
- its([Indexing::ACCESS_ROLE]) { is_expected.to eq(obj.roles.to_json) }
33
- its([Indexing::ASPACE_ID]) { is_expected.to eq("aspace_dccea43034e1b8261e14cf999e86449d") }
34
- its([Indexing::POLICY_ROLE]) { is_expected.to contain_exactly(role2.agent, role3.agent, role4.agent) }
36
+ its([Indexing::PERMANENT_URL]) {
37
+ is_expected.to eq("http://id.library.duke.edu/ark:/99999/fk4zzz")
38
+ }
39
+ its([Indexing::POLICY_ROLE]) {
40
+ is_expected.to contain_exactly(role2.agent, role3.agent, role4.agent)
41
+ }
35
42
  its([Indexing::RESOURCE_ROLE]) { is_expected.to contain_exactly(role1.agent) }
36
- its([Indexing::FCREPO3_PID]) { is_expected.to eq("duke:1") }
43
+
44
+ describe "when it doesn't have a permanent id" do
45
+ before {
46
+ obj.permanent_id = nil
47
+ }
48
+ its([Indexing::UNIQUE_ID]) { is_expected.to eq([obj.id]) }
49
+ end
37
50
  end
38
51
 
39
52
  describe "content-bearing object indexing" do
@@ -6,6 +6,38 @@ RSpec.shared_examples "a DDR model" do
6
6
  it_behaves_like "an object that has identifiers"
7
7
  it_behaves_like "a fixity checkable object"
8
8
 
9
+ describe "#to_param" do
10
+ before {
11
+ subject.save(validate: false) if subject.new_record?
12
+ }
13
+ describe "when it has a permanent id" do
14
+ before {
15
+ subject.permanent_id = "ark:/99999/fk4rx95k8w"
16
+ }
17
+ its(:to_param) { is_expected.to eq("fk4rx95k8w") }
18
+ end
19
+ describe "when it does not have a permanent id" do
20
+ its(:to_param) { is_expected.to_not be_nil }
21
+ its(:to_param) { is_expected.to eq(subject.id) }
22
+ end
23
+ end
24
+
25
+ describe ".find_by_unique_id" do
26
+ before {
27
+ subject.permanent_id = "ark:/99999/fk4rx95k8w"
28
+ subject.save(validate: false)
29
+ }
30
+ it "finds by Fedora id" do
31
+ expect(described_class.find_by_unique_id(subject.id)).to eq(subject)
32
+ end
33
+ it "finds by permanent id" do
34
+ expect(described_class.find_by_unique_id("ark:/99999/fk4rx95k8w")).to eq(subject)
35
+ end
36
+ it "finds by permanent id suffix" do
37
+ expect(described_class.find_by_unique_id("fk4rx95k8w")).to eq(subject)
38
+ end
39
+ end
40
+
9
41
  describe "events" do
10
42
  describe "on deletion with #destroy" do
11
43
  before { subject.save(validate: false) }
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.13
4
+ version: 3.0.0.beta.14
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-02-25 00:00:00.000000000 Z
12
+ date: 2016-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails