Class: Hydra::Datastream::RightsMetadata

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Defined in:
lib/hydra/datastream/rights_metadata.rb

Overview

Implements Hydra RightsMetadata XML terminology for asserting access permissions

Direct Known Subclasses

InheritableRightsMetadata

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#embargo_release_date(opts = {}) ⇒ Object

Returns the value of attribute embargo_release_date.



154
155
156
# File 'lib/hydra/datastream/rights_metadata.rb', line 154

def embargo_release_date
  @embargo_release_date
end

Class Method Details

.date_indexerObject



206
207
208
# File 'lib/hydra/datastream/rights_metadata.rb', line 206

def self.date_indexer
  @date_indexer ||= Solrizer::Descriptor.new(:date, :stored, :indexed)
end

.indexerObject



198
199
200
# File 'lib/hydra/datastream/rights_metadata.rb', line 198

def self.indexer
  @indexer ||= Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued)
end

.xml_templateObject

Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hydra/datastream/rights_metadata.rb', line 53

def self.xml_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.(:version=>"0.1", "xmlns"=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1") {
      xml.copyright {
        xml.human(:type=>'title')
        xml.human(:type=>'description')
        xml.machine(:type=>'uri')
        
      }
      xml.access(:type=>"discover") {
        xml.human
        xml.machine
      }
      xml.access(:type=>"read") {
        xml.human 
        xml.machine
      }
      xml.access(:type=>"edit") {
        xml.human
        xml.machine
      }
      xml.embargo{
        xml.human
        xml.machine
      }        
    }
  end
  return builder.doc
end

Instance Method Details

#clear_permissions!Object

Completely clear the permissions



211
212
213
214
# File 'lib/hydra/datastream/rights_metadata.rb', line 211

def clear_permissions!
  remove_all_permissions({:person=>true})
  remove_all_permissions({:group=>true})
end

#date_indexerObject



202
203
204
# File 'lib/hydra/datastream/rights_metadata.rb', line 202

def date_indexer
  self.class.date_indexer
end

#groupsObject

Reports on which groups have which permissions

Returns:

  • Hash in format => group_permissions, group_name => group_permissions



121
122
123
# File 'lib/hydra/datastream/rights_metadata.rb', line 121

def groups
  return quick_search_by_type(:group)
end

#indexerObject



194
195
196
# File 'lib/hydra/datastream/rights_metadata.rb', line 194

def indexer
  self.class.indexer
end

#individualsObject

Reports on which groups have which permissions

Returns:

  • Hash in format => person_permissions, person_name => person_permissions



127
128
129
# File 'lib/hydra/datastream/rights_metadata.rb', line 127

def individuals
  return quick_search_by_type(:person)
end

#permissions(selector, new_access_level = nil) ⇒ Object

Returns the permissions for the selected person/group If new_access_level is provided, updates the selected person/group access_level to the one specified A new_access_level of “none” will remove all access_levels for the selected person/group ie. permissions(:person=>“person123”)

> “person123”=>“edit”

permissions(:person=>“person123”, “read”)

> “person123”=>“read”

permissions(:person=>“person123”)

> “person123”=>“read”

Parameters:

  • selector (Hash)

    hash in format => identifier

  • new_access_level (default nil) (defaults to: nil)

Returns:

  • Hash in format => access_level.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/hydra/datastream/rights_metadata.rb', line 97

def permissions(selector, new_access_level=nil)
  type = selector.keys.first.to_sym
  actor = selector.values.first
  if new_access_level.nil?
    xpath = self.class.terminology.xpath_for(:access, type, actor)
    nodeset = self.find_by_terms(xpath)
    if nodeset.empty?
      return "none"
    else
      return nodeset.first.ancestors("access").first.attributes["type"].text
    end
  else
    remove_all_permissions(selector)
    unless new_access_level == "none" 
      access_type_symbol = "#{new_access_level}_access".to_sym
      result = self.update_values([access_type_symbol, type] => {"-1"=>actor})
    end
    return new_access_level
  end
    
end

#quick_search_by_type(type) ⇒ Object

This method limits the response to known access levels. Probably runs a bit faster than .permissions().

Parameters:

  • type (Symbol)

    (either :group or :person)

Returns:



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/hydra/datastream/rights_metadata.rb', line 142

def quick_search_by_type(type)
  result = {}
  [{:discover_access=>"discover"},{:read_access=>"read"},{:edit_access=>"edit"}].each do |access_levels_hash|
    access_level = access_levels_hash.keys.first
    access_level_name = access_levels_hash.values.first
    self.find_by_terms(*[access_level, type]).each do |entry|
      result[entry.text] = access_level_name
    end
  end
  return result
end

#to_solr(solr_doc = Hash.new) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/hydra/datastream/rights_metadata.rb', line 175

def to_solr(solr_doc=Hash.new)
  super(solr_doc)
  vals = edit_access.machine.group
  solr_doc[ActiveFedora::SolrService.solr_name('edit_access_group', indexer)] = vals unless vals.empty?
  vals = discover_access.machine.group
  solr_doc[ActiveFedora::SolrService.solr_name('discover_access_group', indexer)] = vals unless vals.empty?
  vals = read_access.machine.group
  solr_doc[ActiveFedora::SolrService.solr_name('read_access_group', indexer)] = vals unless vals.empty?
  vals = edit_access.machine.person
  solr_doc[ActiveFedora::SolrService.solr_name('edit_access_person', indexer)] = vals unless vals.empty?
  vals = discover_access.machine.person
  solr_doc[ActiveFedora::SolrService.solr_name('discover_access_person', indexer)] = vals unless vals.empty?
  vals = read_access.machine.person
  solr_doc[ActiveFedora::SolrService.solr_name('read_access_person', indexer)] = vals unless vals.empty?

  ::Solrizer::Extractor.insert_solr_field_value(solr_doc, "embargo_release_date_dt", embargo_release_date(:format=>:solr_date)) if embargo_release_date
  solr_doc
end

#under_embargo?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/hydra/datastream/rights_metadata.rb', line 171

def under_embargo?
  (embargo_release_date && Date.today < embargo_release_date.to_date) ? true : false
end

#update_permissions(params) ⇒ Object

Updates permissions for all of the persons and groups in a hash Currently restricts actor type to group or person. Any others will be ignored

Parameters:

  • params

    ex. “group”=>{“group1”=>“discover”,“group2”=>“edit”, “person”=>“person1”=>“read”,“person2”=>“discover”}



134
135
136
137
# File 'lib/hydra/datastream/rights_metadata.rb', line 134

def update_permissions(params)
  params.fetch("group", {}).each_pair {|group_id, access_level| self.permissions({"group"=>group_id}, access_level)}
  params.fetch("person", {}).each_pair {|group_id, access_level| self.permissions({"person"=>group_id}, access_level)}
end