Module: Hydra::AdminPolicyBehavior

Extended by:
ActiveSupport::Concern
Included in:
AdminPolicy
Defined in:
app/models/concerns/hydra/admin_policy_behavior.rb

Instance Method Summary collapse

Instance Method Details

#default_permissions=(params) ⇒ Object

Updates those permissions that are provided to it. Does not replace any permissions unless they are provided

Examples:

obj.default_permissions= [{:name=>"group1", :access=>"discover", :type=>'group'},
{:name=>"group2", :access=>"discover", :type=>'group'}]


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/hydra/admin_policy_behavior.rb', line 39

def default_permissions=(params)
  perm_hash = {'person' => defaultRights.users, 'group'=> defaultRights.groups}
  params.each do |row|
    if row[:type] == 'user' || row[:type] == 'person'
      perm_hash['person'][row[:name]] = row[:access]
    elsif row[:type] == 'group'
      perm_hash['group'][row[:name]] = row[:access]
    else
      raise ArgumentError, "Permission type must be 'user', 'person' (alias for 'user'), or 'group'"
    end
  end
  defaultRights.update_permissions(perm_hash)
end

#merged_policiesObject



24
25
26
27
28
29
30
31
32
# File 'app/models/concerns/hydra/admin_policy_behavior.rb', line 24

def merged_policies
  # Workaround for https://github.com/projecthydra/active_fedora/issues/775
  default_permissions.to_a.uniq.each_with_object({}) do |permission, h|
    args = permission.to_hash
    h[args[:access]] ||= {}
    h[args[:access]][args[:type]] ||= []
    h[args[:access]][args[:type]] << args[:name]
  end
end

#to_solr(solr_doc = Hash.new) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/concerns/hydra/admin_policy_behavior.rb', line 10

def to_solr(solr_doc=Hash.new)
  f = merged_policies
  super.tap do |doc|
    ['discover'.freeze, 'read'.freeze, 'edit'.freeze].each do |access|
      doc[Hydra.config.permissions.inheritable[access.to_sym][:group]] = f[access]['group'.freeze] if f[access]
      doc[Hydra.config.permissions.inheritable[access.to_sym][:individual]] = f[access]['person'.freeze] if f[access]
    end
    if default_embargo
      key = Hydra.config.permissions.inheritable.embargo.release_date.sub(/_[^_]+$/, '') #Strip off the suffix
      ::Solrizer.insert_field(doc, key, default_embargo.embargo_release_date, :stored_sortable)
    end
  end
end