Class: FedoraMigrate::RightsMetadata
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- FedoraMigrate::RightsMetadata
- Extended by:
- Deprecation
- Defined in:
- lib/fedora_migrate/rights_metadata.rb
Overview
Implements Hydra RightsMetadata XML terminology for asserting access permissions
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
- #active_lease? ⇒ Boolean
-
#clear_permissions! ⇒ Object
Completely clear the permissions.
- #date_indexer ⇒ Object
-
#groups ⇒ Object
Reports on which groups have which permissions.
- #indexer ⇒ Object
- #individuals ⇒ Object
-
#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 = {}) ⇒ 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.
-
#users ⇒ Object
Reports on which users have which permissions.
Class Method Details
.date_indexer ⇒ Object
242 243 244 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 242 def self.date_indexer @date_indexer ||= Solrizer::Descriptor.new(:date, :stored, :indexed) end |
.indexer ⇒ Object
234 235 236 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 234 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)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 77 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") do xml.copyright do xml.human(type: 'title') xml.human(type: 'description') xml.machine(type: 'uri') end xml.access(type: "discover") do xml.human xml.machine end xml.access(type: "read") do xml.human xml.machine end xml.access(type: "edit") do xml.human xml.machine end xml. do xml.machine end xml.lease do xml.machine end end end builder.doc end |
Instance Method Details
#active_lease? ⇒ Boolean
202 203 204 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 202 def active_lease? lease_expiration_date.present? && Date.today < lease_expiration_date.first end |
#clear_permissions! ⇒ Object
Completely clear the permissions
247 248 249 250 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 247 def (person: true) (group: true) end |
#date_indexer ⇒ Object
238 239 240 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 238 def date_indexer self.class.date_indexer end |
#groups ⇒ Object
Reports on which groups have which permissions
148 149 150 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 148 def groups quick_search_by_type(:group) end |
#indexer ⇒ Object
230 231 232 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 230 def indexer self.class.indexer end |
#individuals ⇒ Object
152 153 154 155 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 152 def individuals Deprecation.warn(RightsMetadata, "The method `individuals' is deprecated and will be removed from Hydra::Datastream::RightsMetadata in hydra-head 8.0. Use `users' instead.", caller) users 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”
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 122 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 = 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 = to_xml else access_type_symbol = "#{new_access_level}_access".to_sym current_values = term_values(access_type_symbol, type) 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
174 175 176 177 178 179 180 181 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 174 def (params) groups_for_update = params['group'] ? params['group'].keys : [] group_ids = groups.keys | groups_for_update group_ids.each { |group_id| ({ "group" => group_id }, params['group'].fetch(group_id, 'none')) } users_for_update = params['person'] ? params['person'].keys : [] user_ids = users.keys | users_for_update user_ids.each { |person_id| ({ "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().
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 186 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 find_by_terms(*[access_level, type]).each do |entry| result[entry.text] = access_level_name end end result end |
#to_solr(solr_doc = {}) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 206 def to_solr(solr_doc = {}) [:discover, :read, :edit].each do |access| vals = send("#{access}_access").machine.group solr_doc[Hydra.config.[access].group] = vals unless vals.empty? vals = send("#{access}_access").machine.person solr_doc[Hydra.config.[access].individual] = vals unless vals.empty? end if .present? key = Hydra.config...release_date.sub(/_[^_]+$/, '') # Strip off the suffix ::Solrizer.insert_field(solr_doc, key, , :stored_sortable) end if lease_expiration_date.present? key = Hydra.config..lease.expiration_date.sub(/_[^_]+$/, '') # Strip off the suffix ::Solrizer.insert_field(solr_doc, key, lease_expiration_date, :stored_sortable) end solr_doc[::Solrizer.solr_name("visibility_during_embargo", :symbol)] = unless .nil? solr_doc[::Solrizer.solr_name("visibility_after_embargo", :symbol)] = unless .nil? solr_doc[::Solrizer.solr_name("visibility_during_lease", :symbol)] = visibility_during_lease unless visibility_during_lease.nil? solr_doc[::Solrizer.solr_name("visibility_after_lease", :symbol)] = visibility_after_lease unless visibility_after_lease.nil? solr_doc[::Solrizer.solr_name("embargo_history", :symbol)] = unless .nil? solr_doc[::Solrizer.solr_name("lease_history", :symbol)] = lease_history unless lease_history.nil? solr_doc end |
#under_embargo? ⇒ Boolean
198 199 200 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 198 def (.present? && Date.today < .first) ? 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
166 167 168 169 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 166 def (params) params.fetch("group", {}).each_pair { |group_id, access_level| ({ "group" => group_id }, access_level) } params.fetch("person", {}).each_pair { |person_id, access_level| ({ "person" => person_id }, access_level) } end |
#users ⇒ Object
Reports on which users have which permissions
159 160 161 |
# File 'lib/fedora_migrate/rights_metadata.rb', line 159 def users quick_search_by_type(:person) end |