lib/hydra/datastream/rights_metadata.rb in hydra-access-controls-6.5.2 vs lib/hydra/datastream/rights_metadata.rb in hydra-access-controls-7.0.0.pre1
- old
+ new
@@ -1,10 +1,11 @@
require 'active_support/core_ext/string'
module Hydra
module Datastream
# Implements Hydra RightsMetadata XML terminology for asserting access permissions
class RightsMetadata < ActiveFedora::OmDatastream
+ extend Deprecation
set_terminology do |t|
t.root(:path=>"rightsMetadata", :xmlns=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1", :schema=>"http://github.com/projecthydra/schemas/tree/v1/rightsMetadata.xsd")
t.copyright {
## BEGIN possible delete, justin 2012-06-22
@@ -123,13 +124,18 @@
# @return Hash in format {group_name => group_permissions, group_name => group_permissions}
def groups
return quick_search_by_type(:group)
end
- # Reports on which groups have which permissions
- # @return Hash in format {person_name => person_permissions, person_name => person_permissions}
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
+
+ # Reports on which users have which permissions
+ # @return Hash in format {user_name => user_permissions, user_name => user_permissions}
+ def users
return quick_search_by_type(:person)
end
# Updates permissions for all of the persons and groups in a hash
# @param params ex. {"group"=>{"group1"=>"discover","group2"=>"edit"}, "person"=>{"person1"=>"read","person2"=>"discover"}}
@@ -145,11 +151,11 @@
def permissions= (params)
groups_for_update = params['group'] ? params['group'].keys : []
group_ids = groups.keys | groups_for_update
group_ids.each {|group_id| self.permissions({"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 = users.keys | users_for_update
user_ids.each {|person_id| self.permissions({"person"=>person_id}, params['person'].fetch(person_id, 'none'))}
end
# @param [Symbol] type (either :group or :person)
# @return
@@ -168,11 +174,11 @@
attr_reader :embargo_release_date
def embargo_release_date=(release_date)
release_date = release_date.to_s if release_date.is_a? Date
begin
- release_date.nil? || Date.parse(release_date)
+ Date.parse(release_date)
rescue
return "INVALID DATE"
end
self.update_values({[:embargo,:machine,:date]=>release_date})
end
@@ -187,25 +193,17 @@
(embargo_release_date && Date.today < embargo_release_date.to_date) ? true : false
end
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?
-
+ [:discover, :read, :edit].each do |access|
+ vals = send("#{access}_access").machine.group
+ solr_doc[Hydra.config[:permissions][access][:group]] = vals unless vals.empty?
+ vals = send("#{access}_access").machine.person
+ solr_doc[Hydra.config[:permissions][access][:individual]] = vals unless vals.empty?
+ end
if embargo_release_date
- embargo_release_date_solr_key_name = ActiveFedora::SolrService.solr_name("embargo_release_date", date_indexer)
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, embargo_release_date_solr_key_name , embargo_release_date(:format=>:solr_date))
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, Hydra.config[:permissions][:embargo_release_date], embargo_release_date(:format=>:solr_date))
end
solr_doc
end
def indexer