Module: Dor::Governable

Extended by:
ActiveSupport::Concern
Includes:
ActiveFedora::Relationships
Included in:
AdminPolicyObject, BasicItem, Collection, Publishable, Set, WorkflowObject
Defined in:
lib/dor/models/governable.rb

Instance Method Summary collapse

Instance Method Details

#add_collection(collection_or_druid) ⇒ Object


78
79
80
81
82
83
84
85
86
87
# File 'lib/dor/models/governable.rb', line 78

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
  self.collections << collection
  self.sets << collection
end

#can_manage_content?(roles) ⇒ Boolean


159
160
161
# File 'lib/dor/models/governable.rb', line 159

def can_manage_content? roles
  intersect roles, groups_which_manage_content
end

#can_manage_desc_metadata?(roles) ⇒ Boolean


153
154
155
# File 'lib/dor/models/governable.rb', line 153

def can_manage_desc_metadata? roles
  intersect roles, 
end

#can_manage_embargo?(roles) ⇒ Boolean


165
166
167
# File 'lib/dor/models/governable.rb', line 165

def can_manage_embargo? roles
  intersect roles, groups_which_manage_embargo
end

#can_manage_item?(roles) ⇒ Boolean


150
151
152
# File 'lib/dor/models/governable.rb', line 150

def can_manage_item? roles
  intersect roles, groups_which_manage_item
end

#can_manage_rights?(roles) ⇒ Boolean


162
163
164
# File 'lib/dor/models/governable.rb', line 162

def can_manage_rights? roles
  intersect roles, groups_which_manage_rights
end

#can_manage_system_metadata?(roles) ⇒ Boolean


156
157
158
# File 'lib/dor/models/governable.rb', line 156

def can_manage_system_metadata? roles
  intersect roles, 
end

#can_view_content?(roles) ⇒ Boolean


168
169
170
# File 'lib/dor/models/governable.rb', line 168

def can_view_content? roles
  intersect roles, groups_which_view_content
end

#can_view_metadata?(roles) ⇒ Boolean


171
172
173
# File 'lib/dor/models/governable.rb', line 171

def can_view_metadata? roles
  intersect roles, 
end

#default_workflow_laneString

Returns the default lane_id from the item's APO. Will return 'default' if the item does not have

and APO, or if the APO does not have a default_lane

19
20
21
22
23
24
25
26
27
# File 'lib/dor/models/governable.rb', line 19

def default_workflow_lane
  return 'default' if self.admin_policy_object.nil?  # TODO log warning?

  admin_md = admin_policy_object.datastreams['administrativeMetadata']
  return 'default' unless admin_md.respond_to? :default_workflow_lane
  lane = admin_md.default_workflow_lane
  return 'default' if lane.nil? or lane.strip == ''
  lane
end

#groups_which_manage_contentObject


132
133
134
# File 'lib/dor/models/governable.rb', line 132

def groups_which_manage_content
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor']
end

#groups_which_manage_desc_metadataObject


126
127
128
# File 'lib/dor/models/governable.rb', line 126

def 
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor', 'dor-apo-metadata']
end

#groups_which_manage_embargoObject


138
139
140
# File 'lib/dor/models/governable.rb', line 138

def groups_which_manage_embargo
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor']
end

#groups_which_manage_itemObject


123
124
125
# File 'lib/dor/models/governable.rb', line 123

def groups_which_manage_item
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor']
end

#groups_which_manage_rightsObject


135
136
137
# File 'lib/dor/models/governable.rb', line 135

def groups_which_manage_rights
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor']
end

#groups_which_manage_system_metadataObject


129
130
131
# File 'lib/dor/models/governable.rb', line 129

def 
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor']
end

#groups_which_view_contentObject


141
142
143
# File 'lib/dor/models/governable.rb', line 141

def groups_which_view_content
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor', 'dor-viewer', 'sdr-viewer']
end

#groups_which_view_metadataObject


144
145
146
# File 'lib/dor/models/governable.rb', line 144

def 
  ['dor-administrator', 'sdr-administrator', 'dor-apo-manager', 'dor-apo-depositor', 'dor-viewer', 'sdr-viewer']
end

#initiate_apo_workflow(name) ⇒ Object


12
13
14
# File 'lib/dor/models/governable.rb', line 12

def initiate_apo_workflow(name)
  self.initialize_workflow(name, 'dor', !self.new_object?)
end

#intersect(arr1, arr2) ⇒ Object


147
148
149
# File 'lib/dor/models/governable.rb', line 147

def intersect arr1, arr2
  return (arr1 & arr2).length > 0
end

#reapplyAdminPolicyObjectDefaultsObject

set the rights metadata datastream to the content of the APO's default object rights


102
103
104
# File 'lib/dor/models/governable.rb', line 102

def reapplyAdminPolicyObjectDefaults
  .content=admin_policy_object.datastreams['defaultObjectRights'].content
end

#remove_collection(collection_or_druid) ⇒ Object


89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/dor/models/governable.rb', line 89

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

  self.collections.delete(collection)
  self.sets.delete(collection)
end

#reset_to_apo_defaultObject


29
30
31
32
33
34
35
# File 'lib/dor/models/governable.rb', line 29

def reset_to_apo_default()
   = self.
  #get the apo for this object
  apo_druid=obj..adminPolicy.first
  apo_obj=Dor::Item.find(apo_druid, :lightweight => true)
  .content=apo_obj..ng_xml
end

#rightsObject


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dor/models/governable.rb', line 105

def rights
    return nil unless self.respond_to? :rightsMetadata
    xml=self..ng_xml
    return nil if xml.search('//rightsMetadata').length != 1
    if xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length == 1
      'Stanford'
    else
      if xml.search('//rightsMetadata/access[@type=\'read\']/machine/world').length ==1
        'World'
      else
        if xml.search('//rightsMetadata/access[@type=\'discover\']/machine/none').length == 1
          'Dark'
        else
          'None'
        end
      end
  end
end

#set_read_rights(rights) ⇒ Object


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
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dor/models/governable.rb', line 37

def set_read_rights(rights)
  return if not ['world','stanford','none', 'dark'].include? rights
   = self.
  rights_xml=.ng_xml
  if(rights_xml.search('//rightsMetadata/access[@type=\'read\']').length==0)
    raise ('The rights metadata stream doesnt contain an entry for machine read permissions. Consider populating it from the APO before trying to change it.')
  end
  rights_xml.search('//rightsMetadata/access[@type=\'discover\']/machine').each do |node|
    node.children.remove
    if rights=='dark'
        world_node=Nokogiri::XML::Node.new('none',rights_xml)
        node.add_child(world_node)
    else
        world_node=Nokogiri::XML::Node.new('world',rights_xml)
      node.add_child(world_node)
    end
  end
  rights_xml.search('//rightsMetadata/access[@type=\'read\']').each do |node|
    node.children.remove
    machine_node=Nokogiri::XML::Node.new('machine',rights_xml)
    if(rights=='world')
      world_node=Nokogiri::XML::Node.new(rights,rights_xml)
      node.add_child(machine_node)
      machine_node.add_child(world_node)
    end
    if rights=='stanford'
      world_node=Nokogiri::XML::Node.new(rights,rights_xml)
      node.add_child(machine_node)
      group_node=Nokogiri::XML::Node.new('group',rights_xml)
      group_node.content="Stanford"
      node.add_child(machine_node)
      machine_node.add_child(group_node)
    end
    if rights=='none' or rights == 'dark'
      none_node=Nokogiri::XML::Node.new('none',rights_xml)
      node.add_child(machine_node)
      machine_node.add_child(none_node)
    end
  end
end