Class: Hydra::Datastream::RightsMetadata
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Hydra::Datastream::RightsMetadata
- Defined in:
- lib/hydra/datastream/rights_metadata.rb
Overview
Implements Hydra RightsMetadata XML terminology for asserting access permissions
Direct Known Subclasses
Instance Attribute Summary collapse
-
#embargo_release_date(opts = {}) ⇒ Object
Returns the value of attribute embargo_release_date.
Class Method Summary collapse
- .date_indexer ⇒ Object
- .indexer ⇒ Object
-
.xml_template ⇒ Object
Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml).
Instance Method Summary collapse
-
#clear_permissions! ⇒ Object
Completely clear the permissions.
- #date_indexer ⇒ Object
-
#groups ⇒ Object
Reports on which groups have which permissions.
- #indexer ⇒ Object
-
#individuals ⇒ Object
Reports on which groups have which permissions.
-
#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=(params) ⇒ Object
Updates all permissions Restricts actor type to group or person.
-
#quick_search_by_type(type) ⇒ Object
This method limits the response to known access levels.
- #to_solr(solr_doc = Hash.new) ⇒ Object
- #under_embargo? ⇒ Boolean
-
#update_permissions(params) ⇒ Object
Updates permissions for all of the persons and groups in a hash Currently restricts actor type to group or person.
Instance Attribute Details
#embargo_release_date(opts = {}) ⇒ Object
Returns the value of attribute embargo_release_date.
169 170 171 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 169 def @embargo_release_date end |
Class Method Details
.date_indexer ⇒ Object
224 225 226 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 224 def self.date_indexer @date_indexer ||= Solrizer::Descriptor.new(:date, :stored, :indexed) end |
.indexer ⇒ Object
216 217 218 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 216 def self.indexer @indexer ||= Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued) end |
.xml_template ⇒ Object
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.rightsMetadata(: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.{ xml.human xml.machine } } end return builder.doc end |
Instance Method Details
#clear_permissions! ⇒ Object
Completely clear the permissions
229 230 231 232 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 229 def ({:person=>true}) ({:group=>true}) end |
#date_indexer ⇒ Object
220 221 222 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 220 def date_indexer self.class.date_indexer end |
#groups ⇒ Object
Reports on which groups have which permissions
124 125 126 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 124 def groups return quick_search_by_type(:group) end |
#indexer ⇒ Object
212 213 214 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 212 def indexer self.class.indexer end |
#individuals ⇒ Object
Reports on which groups have which permissions
130 131 132 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 130 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”
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 97 def (selector, new_access_level=nil) type = selector.keys.first.to_sym actor = selector.values.first if new_access_level.nil? xpath = xpath(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 (selector) if new_access_level == "none" self.content = self.to_xml else access_type_symbol = "#{new_access_level}_access".to_sym current_values = term_values(access_type_symbol, type) self.update_values([access_type_symbol, type] => current_values + [actor] ) end return new_access_level end end |
#permissions=(params) ⇒ Object
Updates all permissions Restricts actor type to group or person. Any others will be ignored
145 146 147 148 149 150 151 152 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 145 def (params) groups_for_update = params['group'] ? params['group'].keys : [] group_ids = groups.keys | groups_for_update group_ids.each {|group_id| self.({"group"=>group_id}, params['group'].fetch(group_id, 'none'))} users_for_update = params['person'] ? params['person'].keys : [] user_ids = individuals.keys | users_for_update user_ids.each {|person_id| self.({"person"=>person_id}, params['person'].fetch(person_id, 'none'))} end |
#quick_search_by_type(type) ⇒ Object
This method limits the response to known access levels. Probably runs a bit faster than .permissions().
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 157 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
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 190 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? if = ActiveFedora::SolrService.solr_name("embargo_release_date", date_indexer) ::Solrizer::Extractor.insert_solr_field_value(solr_doc, , (:format=>:solr_date)) end solr_doc end |
#under_embargo? ⇒ Boolean
186 187 188 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 186 def ( && Date.today < .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
137 138 139 140 |
# File 'lib/hydra/datastream/rights_metadata.rb', line 137 def (params) params.fetch("group", {}).each_pair {|group_id, access_level| self.({"group"=>group_id}, access_level)} params.fetch("person", {}).each_pair {|person_id, access_level| self.({"person"=>person_id}, access_level)} end |