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_permissionsObject

Returns a list with all the permissions on the object.

Examples:

[{:name=>"group1", :access=>"discover", :type=>'group'},
{:name=>"group2", :access=>"discover", :type=>'group'},
{:name=>"user2", :access=>"read", :type=>'user'},
{:name=>"user1", :access=>"edit", :type=>'user'},
{:name=>"user3", :access=>"read", :type=>'user'}]


34
35
36
37
# File 'app/models/concerns/hydra/admin_policy_behavior.rb', line 34

def default_permissions
  (defaultRights.groups.map {|x| {:type=>'group', :access=>x[1], :name=>x[0] }} + 
   defaultRights.users.map {|x| {:type=>'user', :access=>x[1], :name=>x[0]}})
end

#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'}]


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/concerns/hydra/admin_policy_behavior.rb', line 13

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