Class: Hydra::RightsMetadata

Inherits:
ActiveFedora::NokogiriDatastream
  • Object
show all
Defined in:
vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) xml_template

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



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
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 37

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
      }
      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

- (Object) groups

Reports on which groups have which permissions



104
105
106
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 104

def groups
  return quick_search_by_type(:group)
end

- (Object) individuals

Reports on which groups have which permissions



110
111
112
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 110

def individuals
  return quick_search_by_type(:person)
end

- (Object) permissions(selector, new_access_level = nil)

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(Hydra::RightsMetadata.:person=>&:person=>“person123&:person=>“person123”)

> Hydra::RightsMetadata.&“person123&“person123”=>&“person123”=>“edit&“person123”=>“edit”

permissions(Hydra::RightsMetadata.:person=>&:person=>“person123&:person=>“person123”, “read”)

> Hydra::RightsMetadata.&“person123&“person123”=>&“person123”=>“read&“person123”=>“read”

permissions(Hydra::RightsMetadata.:person=>&:person=>“person123&:person=>“person123”)

> Hydra::RightsMetadata.&“person123&“person123”=>&“person123”=>“read&“person123”=>“read”



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 78

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
    self.dirty = true
    return new_access_level
  end
    
end

- (Object) quick_search_by_type(type)

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



125
126
127
128
129
130
131
132
133
134
135
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 125

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

- (Object) update_permissions(params)

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



117
118
119
120
# File 'vendor/plugins/hydra_repository/lib/hydra/rights_metadata.rb', line 117

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