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 +4 -4
- data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +4 -4
- data/lib/ddr/index/fields.rb +1 -0
- data/lib/ddr/models/base.rb +22 -4
- data/lib/ddr/models/indexing.rb +1 -0
- data/lib/ddr/models/version.rb +1 -1
- data/spec/auth/ability_spec.rb +31 -14
- data/spec/models/indexing_spec.rb +24 -11
- data/spec/support/shared_examples_for_ddr_models.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7faeec493c42d29c2ac9af03f8db073c700678
|
4
|
+
data.tar.gz: 9688fa99bde0eaffc03946d490e0f0413fa58ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
|
6
|
+
cannot :publish, Ddr::Models::Base do |obj|
|
7
|
+
obj.published? || !obj.publishable?
|
8
8
|
end
|
9
|
-
|
10
|
-
obj.published?
|
9
|
+
cannot :unpublish, Ddr::Models::Base do |obj|
|
10
|
+
!obj.published?
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/ddr/index/fields.rb
CHANGED
@@ -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
|
|
data/lib/ddr/models/base.rb
CHANGED
@@ -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.")
|
data/lib/ddr/models/indexing.rb
CHANGED
data/lib/ddr/models/version.rb
CHANGED
data/spec/auth/ability_spec.rb
CHANGED
@@ -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
|
152
|
-
before
|
153
|
-
|
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
|
161
|
-
before { allow(obj).to receive(:
|
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
|
169
|
-
before
|
170
|
-
|
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
|
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.
|
23
|
-
obj.
|
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]) {
|
31
|
-
|
32
|
-
|
33
|
-
its([Indexing::
|
34
|
-
|
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
|
-
|
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.
|
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-
|
12
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|