ddr-models 2.0.0.pre.1 → 2.0.0.pre.2
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/collection.rb +0 -10
- data/app/models/item.rb +1 -12
- data/lib/ddr/auth.rb +8 -2
- data/lib/ddr/auth/legacy/abstract_legacy_permissions.rb +17 -0
- data/lib/ddr/auth/legacy/legacy_authorization.rb +44 -0
- data/lib/ddr/auth/legacy/legacy_default_permissions.rb +33 -0
- data/lib/ddr/auth/legacy/legacy_permissions.rb +33 -0
- data/lib/ddr/auth/legacy/legacy_roles.rb +25 -0
- data/lib/ddr/auth/roles/role_set.rb +1 -1
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +2 -0
- data/lib/ddr/datastreams/structural_metadata_datastream.rb +3 -16
- data/lib/ddr/index_fields.rb +1 -0
- data/lib/ddr/jobs.rb +1 -0
- data/lib/ddr/jobs/migrate_legacy_authorization.rb +23 -0
- data/lib/ddr/models.rb +2 -0
- data/lib/ddr/models/access_controllable.rb +0 -1
- data/lib/ddr/models/base.rb +4 -0
- data/lib/ddr/models/has_admin_metadata.rb +2 -7
- data/lib/ddr/models/has_struct_metadata.rb +34 -31
- data/lib/ddr/models/indexing.rb +1 -0
- data/lib/ddr/models/solr_document.rb +4 -0
- data/lib/ddr/models/struct_div.rb +45 -0
- data/lib/ddr/models/structure.rb +52 -0
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/vocab.rb +1 -0
- data/lib/ddr/vocab/display.rb +11 -0
- data/spec/auth/legacy_authorization_spec.rb +94 -0
- data/spec/auth/legacy_default_permissions_spec.rb +37 -0
- data/spec/auth/legacy_permissions_spec.rb +14 -12
- data/spec/auth/legacy_roles_spec.rb +32 -0
- data/spec/factories/structure_factories.rb +27 -0
- data/spec/jobs/migrate_legacy_authorization_spec.rb +43 -0
- data/spec/models/has_admin_metadata_spec.rb +5 -0
- data/spec/models/has_struct_metadata_spec.rb +38 -0
- data/spec/models/item_spec.rb +0 -12
- data/spec/models/solr_document_spec.rb +5 -0
- data/spec/models/struct_div_spec.rb +65 -0
- data/spec/models/structure_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/structural_metadata_helper.rb +95 -0
- metadata +29 -4
- data/lib/ddr/auth/legacy_permissions.rb +0 -39
- data/lib/ddr/auth/legacy_roles.rb +0 -33
data/lib/ddr/models/indexing.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Ddr
|
2
|
+
module Models
|
3
|
+
class StructDiv
|
4
|
+
|
5
|
+
attr_accessor :id, :label, :order, :orderlabel, :type, :objs, :divs
|
6
|
+
|
7
|
+
def initialize(structmap_or_div_node)
|
8
|
+
@id = structmap_or_div_node['ID']
|
9
|
+
@label = structmap_or_div_node['LABEL']
|
10
|
+
@order = structmap_or_div_node['ORDER']
|
11
|
+
@orderlabel = structmap_or_div_node['ORDERLABEL']
|
12
|
+
@type = structmap_or_div_node['TYPE']
|
13
|
+
@objs = obj_pids(structmap_or_div_node) if structmap_or_div_node.node_name == "div"
|
14
|
+
@divs = subdivs(structmap_or_div_node).sort
|
15
|
+
end
|
16
|
+
|
17
|
+
def <=>(other)
|
18
|
+
self.order.to_i <=> other.order.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def objects?
|
22
|
+
objs.present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def object_pids
|
26
|
+
objs
|
27
|
+
end
|
28
|
+
|
29
|
+
def objects
|
30
|
+
objs.map { |pid| ActiveFedora::Base.find(pid) }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def obj_pids(div_node)
|
36
|
+
div_node.xpath('xmlns:fptr').map { |fptr_node| fptr_node["CONTENTIDS"].gsub('info:fedora/', '') }
|
37
|
+
end
|
38
|
+
|
39
|
+
def subdivs(structmap_or_div_node)
|
40
|
+
structmap_or_div_node.xpath('xmlns:div').map { |div_node| Ddr::Models::StructDiv.new(div_node) }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Ddr
|
2
|
+
module Models
|
3
|
+
#
|
4
|
+
# Wraps a Nokogiri (XML) Document
|
5
|
+
#
|
6
|
+
class Structure < SimpleDelegator
|
7
|
+
|
8
|
+
def initialize(xml_doc=nil)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def struct_divs
|
13
|
+
@struct_divs ||= build_struct_divs(structMaps)
|
14
|
+
end
|
15
|
+
|
16
|
+
def structMap(type='default')
|
17
|
+
xpath("//xmlns:structMap[@TYPE='#{type}']").first
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_xml_document
|
21
|
+
__getobj__
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def structMaps
|
27
|
+
xpath("//xmlns:structMap")
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_struct_divs(structMaps)
|
31
|
+
sdivs = {}
|
32
|
+
structMaps.each do |structMap|
|
33
|
+
type = structMap['TYPE'] || 'default'
|
34
|
+
raise StandardError, "Multiple '#{type}' structMaps" if sdivs[type].present?
|
35
|
+
sdivs[type] = Ddr::Models::StructDiv.new(structMap)
|
36
|
+
end
|
37
|
+
sdivs
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.template
|
41
|
+
Nokogiri::XML(
|
42
|
+
'<mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
|
43
|
+
<structMap TYPE="default" />
|
44
|
+
</mets>'
|
45
|
+
) do |config|
|
46
|
+
config.noblanks
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/ddr/models/version.rb
CHANGED
data/lib/ddr/vocab.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
module Ddr::Auth
|
2
|
+
RSpec.describe LegacyAuthorization do
|
3
|
+
|
4
|
+
subject { described_class.new(obj) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@deprecation_behavior = Deprecation.default_deprecation_behavior
|
8
|
+
Deprecation.default_deprecation_behavior = :silence
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Deprecation.default_deprecation_behavior = @deprecation_behavior
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe "with a Collection" do
|
17
|
+
let(:obj) { FactoryGirl.build(:collection) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
obj.permissions_attributes = [{access: "edit", type: "person", name: "bob@example.com"}]
|
21
|
+
obj.default_permissions = [{access: "edit", type: "group", name: "Editors"},
|
22
|
+
{access: "discover", type: "group", name: "public"},
|
23
|
+
{access: "read", type: "group", name: "registered"}]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should convert the legacy authorization data to roles" do
|
27
|
+
expect(subject.to_roles)
|
28
|
+
.to eq(Roles::DetachedRoleSet.new(
|
29
|
+
[ Roles::Role.build(type: "Curator", agent: "Editors", scope: "policy"),
|
30
|
+
Roles::Role.build(type: "Viewer", agent: "public", scope: "policy"),
|
31
|
+
Roles::Role.build(type: "Viewer", agent: "registered", scope: "policy"),
|
32
|
+
Roles::Role.build(type: "Editor", agent: "bob@example.com", scope: "resource") ]
|
33
|
+
))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should clear the legacy authorization data" do
|
37
|
+
subject.clear
|
38
|
+
expect(subject).to be_clear
|
39
|
+
expect(obj.permissions).to be_empty
|
40
|
+
expect(obj.default_permissions).to be_empty
|
41
|
+
expect(obj.adminMetadata.downloader).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should migrate the legacy authorization data" do
|
45
|
+
subject.migrate
|
46
|
+
expect(subject).to be_clear
|
47
|
+
expect(obj.roles)
|
48
|
+
.to eq(Roles::DetachedRoleSet.new(
|
49
|
+
[ Roles::Role.build(type: "Curator", agent: "Editors", scope: "policy"),
|
50
|
+
Roles::Role.build(type: "Viewer", agent: "public", scope: "policy"),
|
51
|
+
Roles::Role.build(type: "Viewer", agent: "registered", scope: "policy"),
|
52
|
+
Roles::Role.build(type: "Editor", agent: "bob@example.com", scope: "resource") ]
|
53
|
+
))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with a Component" do
|
58
|
+
let(:obj) { FactoryGirl.build(:component) }
|
59
|
+
|
60
|
+
before do
|
61
|
+
obj.permissions_attributes = [{access: "edit", type: "person", name: "bob@example.com"}]
|
62
|
+
obj.adminMetadata.downloader = ["Downloaders", "sally@example.com"]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should convert the legacy authorization to roles" do
|
66
|
+
expect(subject.to_roles)
|
67
|
+
.to eq(Roles::DetachedRoleSet.new(
|
68
|
+
[ Roles::Role.build(type: "Downloader", agent: "Downloaders", scope: "resource"),
|
69
|
+
Roles::Role.build(type: "Downloader", agent: "sally@example.com", scope: "resource"),
|
70
|
+
Roles::Role.build(type: "Editor", agent: "bob@example.com", scope: "resource") ]
|
71
|
+
))
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should clear the legacy authorization data" do
|
75
|
+
subject.clear
|
76
|
+
expect(subject).to be_clear
|
77
|
+
expect(obj.permissions).to be_empty
|
78
|
+
expect(obj.adminMetadata.downloader).to be_empty
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should migrate the legacy authorization data" do
|
82
|
+
subject.migrate
|
83
|
+
expect(subject).to be_clear
|
84
|
+
expect(obj.roles)
|
85
|
+
.to eq(Roles::DetachedRoleSet.new(
|
86
|
+
[ Roles::Role.build(type: "Downloader", agent: "Downloaders", scope: "resource"),
|
87
|
+
Roles::Role.build(type: "Downloader", agent: "sally@example.com", scope: "resource"),
|
88
|
+
Roles::Role.build(type: "Editor", agent: "bob@example.com", scope: "resource") ]
|
89
|
+
))
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Ddr::Auth
|
2
|
+
RSpec.describe LegacyDefaultPermissions do
|
3
|
+
|
4
|
+
subject { described_class.new(obj) }
|
5
|
+
|
6
|
+
let(:obj) { FactoryGirl.build(:collection) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
@deprecation_behavior = Deprecation.default_deprecation_behavior
|
10
|
+
Deprecation.default_deprecation_behavior = :silence
|
11
|
+
obj.default_permissions = [{access: "edit", type: "group", name: "Editors"},
|
12
|
+
{access: "discover", type: "group", name: "public"},
|
13
|
+
{access: "read", type: "person", name: "bob@example.com"}]
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Deprecation.default_deprecation_behavior = @deprecation_behavior
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should convert the default permissions to policy roles" do
|
21
|
+
expect(subject.to_roles)
|
22
|
+
.to eq(Roles::DetachedRoleSet.new(
|
23
|
+
[ Roles::Role.build(type: "Curator", agent: "Editors", scope: "policy"),
|
24
|
+
Roles::Role.build(type: "Viewer", agent: "public", scope: "policy"),
|
25
|
+
Roles::Role.build(type: "Viewer", agent: "bob@example.com", scope: "policy")
|
26
|
+
]
|
27
|
+
))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should clear the legacy default permissions" do
|
31
|
+
expect(obj.default_permissions).not_to be_empty
|
32
|
+
subject.clear
|
33
|
+
expect(obj.default_permissions).to be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ddr::Auth
|
2
2
|
RSpec.describe LegacyPermissions do
|
3
3
|
|
4
|
-
subject { described_class.new(obj
|
4
|
+
subject { described_class.new(obj) }
|
5
5
|
|
6
6
|
let(:obj) { FactoryGirl.build(:item) }
|
7
7
|
|
@@ -17,19 +17,21 @@ module Ddr::Auth
|
|
17
17
|
Deprecation.default_deprecation_behavior = @deprecation_behavior
|
18
18
|
end
|
19
19
|
|
20
|
-
it "should
|
21
|
-
expect(subject.
|
22
|
-
.to eq(Roles::DetachedRoleSet.new(
|
23
|
-
|
24
|
-
|
20
|
+
it "should convert the permissions to resource roles" do
|
21
|
+
expect(subject.to_roles)
|
22
|
+
.to eq(Roles::DetachedRoleSet.new(
|
23
|
+
[ Roles::Role.build(type: "Editor", agent: "Editors", scope: "resource"),
|
24
|
+
Roles::Role.build(type: "Viewer", agent: "public", scope: "resource"),
|
25
|
+
Roles::Role.build(type: "Viewer", agent: "bob@example.com", scope: "resource")
|
26
|
+
]
|
27
|
+
))
|
25
28
|
end
|
26
29
|
|
27
|
-
it "should
|
28
|
-
expect(
|
29
|
-
|
30
|
-
|
31
|
-
Roles::Role.build(type: "Viewer", agent: "bob@example.com", scope: "resource")]))
|
30
|
+
it "should clear the legacy permissions" do
|
31
|
+
expect(obj.permissions).not_to be_empty
|
32
|
+
subject.clear
|
33
|
+
expect(obj.permissions).to be_empty
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Ddr::Auth
|
2
|
+
RSpec.describe LegacyRoles do
|
3
|
+
|
4
|
+
subject { described_class.new(obj) }
|
5
|
+
|
6
|
+
let(:obj) { FactoryGirl.build(:component) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
@deprecation_behavior = Deprecation.default_deprecation_behavior
|
10
|
+
Deprecation.default_deprecation_behavior = :silence
|
11
|
+
obj.adminMetadata.downloader = ["bob@example.com", "Downloaders"]
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Deprecation.default_deprecation_behavior = @deprecation_behavior
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should convert the legacy roles to new roles" do
|
19
|
+
expect(subject.to_roles)
|
20
|
+
.to eq(Roles::DetachedRoleSet.new(
|
21
|
+
[ Roles::Role.build(type: "Downloader", agent: "Downloaders", scope: "resource"),
|
22
|
+
Roles::Role.build(type: "Downloader", agent: "bob@example.com", scope: "resource")
|
23
|
+
]
|
24
|
+
))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should clear the legacy roles" do
|
28
|
+
expect { subject.clear }.to change(obj.adminMetadata.downloader, :empty?).from(false).to(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'support/structural_metadata_helper'
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
|
5
|
+
factory :structure, class: Ddr::Models::Structure do
|
6
|
+
|
7
|
+
factory :simple_structure do
|
8
|
+
initialize_with do
|
9
|
+
new(simple_structure_document)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
factory :nested_structure do
|
14
|
+
initialize_with do
|
15
|
+
new(nested_structure_document)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
factory :multiple_struct_maps_structure do
|
20
|
+
initialize_with do
|
21
|
+
new(multiple_struct_maps_structure_document)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ddr::Jobs
|
2
|
+
RSpec.describe MigrateLegacyAuthorization do
|
3
|
+
|
4
|
+
let(:obj) { FactoryGirl.build(:collection) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@deprecation_behavior = Deprecation.default_deprecation_behavior
|
8
|
+
Deprecation.default_deprecation_behavior = :silence
|
9
|
+
obj.permissions_attributes = [{access: "edit", type: "person", name: "bob@example.com"}]
|
10
|
+
obj.adminMetadata.downloader = ["Downloaders", "sally@example.com"]
|
11
|
+
obj.default_permissions = [{access: "edit", type: "group", name: "Editors"},
|
12
|
+
{access: "discover", type: "group", name: "public"},
|
13
|
+
{access: "read", type: "group", name: "registered"}]
|
14
|
+
obj.save!
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
Deprecation.default_deprecation_behavior = @deprecation_behavior
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should migrate the authorization data to roles" do
|
22
|
+
Resque.enqueue(described_class, obj.pid)
|
23
|
+
obj.reload
|
24
|
+
expect(obj.legacy_authorization).to be_clear
|
25
|
+
expect(obj.roles)
|
26
|
+
.to eq(Ddr::Auth::Roles::DetachedRoleSet.new(
|
27
|
+
[ Ddr::Auth::Roles::Role.build(type: "Curator", agent: "Editors", scope: "policy"),
|
28
|
+
Ddr::Auth::Roles::Role.build(type: "Viewer", agent: "public", scope: "policy"),
|
29
|
+
Ddr::Auth::Roles::Role.build(type: "Viewer", agent: "registered", scope: "policy"),
|
30
|
+
Ddr::Auth::Roles::Role.build(type: "Editor", agent: "bob@example.com", scope: "resource"),
|
31
|
+
Ddr::Auth::Roles::Role.build(type: "Downloader", agent: "Downloaders", scope: "resource"),
|
32
|
+
Ddr::Auth::Roles::Role.build(type: "Downloader", agent: "sally@example.com", scope: "resource")
|
33
|
+
]
|
34
|
+
))
|
35
|
+
event = obj.update_events.last
|
36
|
+
expect(event).to be_success
|
37
|
+
expect(event.summary).to eq("Legacy authorization data migrated to roles")
|
38
|
+
expect(event.detail).to match(/LEGACY AUTHORIZATION DATA/)
|
39
|
+
expect(event.detail).to match(/ROLES/)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -101,9 +101,11 @@ module Ddr
|
|
101
101
|
describe "indexing" do
|
102
102
|
let(:permanent_id) { "ark:/99999/fk4zzz" }
|
103
103
|
let(:permanent_url) { "http://id.library.duke.edu/ark:/99999/fk4zzz" }
|
104
|
+
let(:display_format) { "Image" }
|
104
105
|
before do
|
105
106
|
subject.permanent_id = permanent_id
|
106
107
|
subject.permanent_url = permanent_url
|
108
|
+
subject.display_format = display_format
|
107
109
|
end
|
108
110
|
it "should index the permanent id value" do
|
109
111
|
expect(subject.to_solr[Ddr::IndexFields::PERMANENT_ID]).to eq(permanent_id)
|
@@ -111,6 +113,9 @@ module Ddr
|
|
111
113
|
it "should index the permanent url" do
|
112
114
|
expect(subject.to_solr[Ddr::IndexFields::PERMANENT_URL]).to eq(permanent_url)
|
113
115
|
end
|
116
|
+
it "should index the display format" do
|
117
|
+
expect(subject.to_solr[Ddr::IndexFields::DISPLAY_FORMAT]).to eq(display_format)
|
118
|
+
end
|
114
119
|
end
|
115
120
|
|
116
121
|
end
|