This repository has been archived by the owner on May 11, 2022. It is now read-only.
/
governable.rb
65 lines (56 loc) · 1.93 KB
/
governable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
module Dor
module Governable
extend ActiveSupport::Concern
included do
belongs_to :admin_policy_object, property: :is_governed_by, class_name: 'Dor::AdminPolicyObject'
has_and_belongs_to_many :collections, property: :is_member_of_collection, class_name: 'Dor::Collection'
has_and_belongs_to_many :sets, property: :is_member_of, class_name: 'Dor::Collection'
end
def reset_to_apo_default
rightsMetadata.content = admin_policy_object.rightsMetadata.ng_xml
end
def set_read_rights(rights)
rightsMetadata.set_read_rights(rights)
unshelve_and_unpublish if rights == 'dark'
end
def unshelve_and_unpublish
if respond_to? :contentMetadata
content_ds = datastreams['contentMetadata']
unless content_ds.nil?
content_ds.ng_xml.xpath('/contentMetadata/resource//file').each_with_index do |file_node, index|
content_ds.ng_xml_will_change! if index == 0
file_node['publish'] = 'no'
file_node['shelve'] = 'no'
end
end
end
end
def add_collection(collection_or_druid)
collection =
case collection_or_druid
when String
Dor::Collection.find(collection_or_druid)
when Dor::Collection
collection_or_druid
end
collections << collection
sets << collection
end
def remove_collection(collection_or_druid)
collection =
case collection_or_druid
when String
Dor::Collection.find(collection_or_druid)
when Dor::Collection
collection_or_druid
end
collections.delete(collection)
sets.delete(collection)
end
# set the rights metadata datastream to the content of the APO's default object rights
def reapplyAdminPolicyObjectDefaults
rightsMetadata.content = admin_policy_object.datastreams['defaultObjectRights'].content
end
end
end