Module: Hydra::AccessControls::Permissions

Extended by:
ActiveSupport::Concern, Deprecation
Includes:
Visibility
Included in:
WithAccessRight, Hydra::AdminPolicy
Defined in:
app/models/concerns/hydra/access_controls/permissions.rb

Instance Method Summary collapse

Methods included from Visibility

#visibility, #visibility=, #visibility_changed?

Instance Method Details

#discover_groupsObject

Return a list of groups that have discover permission



66
67
68
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 66

def discover_groups
  .groups.map {|k, v| k if v == 'discover'}.compact
end

#discover_groups=(groups) ⇒ Object

Grant discover permissions to the groups specified. Revokes discover permission for all other groups. @param groups a list of group names

Examples:

r.discover_groups= ['one', 'two', 'three']
r.discover_groups 
=> ['one', 'two', 'three']


77
78
79
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 77

def discover_groups=(groups)
  set_discover_groups(groups, discover_groups)
end

#discover_groups_stringObject

Display the groups a comma delimeted string



93
94
95
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 93

def discover_groups_string
  self.discover_groups.join(', ')
end

#discover_groups_string=(groups) ⇒ Object

Grant discover permissions to the groups specified. Revokes discover permission for all other groups. @param groups a list of group names

Examples:

r.discover_groups_string= 'one, two, three'
r.discover_groups 
=> ['one', 'two', 'three']


88
89
90
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 88

def discover_groups_string=(groups)
  self.discover_groups=groups.split(/[\s,]+/)
end

#discover_usersObject



116
117
118
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 116

def discover_users
  .users.map {|k, v| k if v == 'discover'}.compact
end

#discover_users=(users) ⇒ Object

Grant discover permissions to the users specified. Revokes discover permission for all other users. @param users a list of usernames

Examples:

r.discover_users= ['one', 'two', 'three']
r.discover_users 
=> ['one', 'two', 'three']


127
128
129
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 127

def discover_users=(users)
  set_discover_users(users, discover_users)
end

#discover_users_stringObject

Display the users as a comma delimeted string



143
144
145
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 143

def discover_users_string
  self.discover_users.join(', ')
end

#discover_users_string=(users) ⇒ Object

Grant discover permissions to the groups specified. Revokes discover permission for all other users. @param users a list of usernames

Examples:

r.discover_users_string= 'one, two, three'
r.discover_users 
=> ['one', 'two', 'three']


138
139
140
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 138

def discover_users_string=(users)
  self.discover_users=users.split(/[\s,]+/)
end

#edit_groupsObject

Return a list of groups that have edit permission



269
270
271
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 269

def edit_groups
  .groups.map {|k, v| k if v == 'edit'}.compact
end

#edit_groups=(groups) ⇒ Object

Grant edit permissions to the groups specified. Revokes edit permission for all other groups. @param groups a list of group names

Examples:

r.edit_groups= ['one', 'two', 'three']
r.edit_groups 
=> ['one', 'two', 'three']


280
281
282
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 280

def edit_groups=(groups)
  set_edit_groups(groups, edit_groups)
end

#edit_groups_stringObject

Display the groups a comma delimeted string



296
297
298
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 296

def edit_groups_string
  self.edit_groups.join(', ')
end

#edit_groups_string=(groups) ⇒ Object

Grant edit permissions to the groups specified. Revokes edit permission for all other groups. @param groups a list of group names

Examples:

r.edit_groups_string= 'one, two, three'
r.edit_groups 
=> ['one', 'two', 'three']


291
292
293
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 291

def edit_groups_string=(groups)
  self.edit_groups=groups.split(/[\s,]+/)
end

#edit_usersObject



319
320
321
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 319

def edit_users
  .users.map {|k, v| k if v == 'edit'}.compact
end

#edit_users=(users) ⇒ Object

Grant edit permissions to the groups specified. Revokes edit permission for all other groups. @param users a list of usernames

Examples:

r.edit_users= ['one', 'two', 'three']
r.edit_users 
=> ['one', 'two', 'three']


330
331
332
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 330

def edit_users=(users)
  set_edit_users(users, edit_users)
end

#permissionsObject

Returns a list with all the permissions on the object.



47
48
49
50
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 47

def permissions
  (.groups.map {|x| Permission.new(type: 'group', access: x[1], name: x[0] )} + 
    .users.map {|x|  Permission.new(type: 'user', access: x[1], name: x[0] )})
end

#permissions=(values) ⇒ Object

Parameters:

  • values (Array<Permission>)

    a list of permission objects to set



53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 53

def permissions= values
  perm_hash = {'person' => {}, 'group'=> {}}
  values.each do |perm|
    if perm.type == 'user'
      perm_hash['person'][perm.name] = perm.access
    else
      perm_hash['group'][perm.name] = perm.access
    end
  end
  .permissions = perm_hash
end

#permissions_attributes=(attributes_collection) ⇒ Object

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

Examples:

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


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 16

def permissions_attributes= attributes_collection
  perm_hash = {'person' => .users, 'group'=> .groups}

  if attributes_collection.is_a? Hash
    attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
  end

  attributes_collection.each do |row|
    row = row.with_indifferent_access
    if row[:type] == 'user' || row[:type] == 'person'
      if has_destroy_flag? row
        perm_hash['person'].delete(row[:name])
      else
        perm_hash['person'][row[:name]] = row[:access]
      end
    elsif row[:type] == 'group'
      perm_hash['group'][row[:name]] = row[:access]
      if has_destroy_flag? row
        perm_hash['group'].delete(row[:name])
      else
        perm_hash['group'][row[:name]] = row[:access]
      end
    else
      raise ArgumentError, "Permission type must be 'user', 'person' (alias for 'user'), or 'group'"
    end
  end
  
  .permissions = perm_hash
end

#read_groupsObject

Return a list of groups that have discover permission



167
168
169
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 167

def read_groups
  .groups.map {|k, v| k if v == 'read'}.compact
end

#read_groups=(groups) ⇒ Object

Grant read permissions to the groups specified. Revokes read permission for all other groups. @param groups a list of group names

Examples:

r.read_groups= ['one', 'two', 'three']
r.read_groups 
=> ['one', 'two', 'three']


178
179
180
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 178

def read_groups=(groups)
  set_read_groups(groups, read_groups)
end

#read_groups_stringObject

Display the groups a comma delimeted string



194
195
196
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 194

def read_groups_string
  self.read_groups.join(', ')
end

#read_groups_string=(groups) ⇒ Object

Grant read permissions to the groups specified. Revokes read permission for all other groups. @param groups a list of group names

Examples:

r.read_groups_string= 'one, two, three'
r.read_groups 
=> ['one', 'two', 'three']


189
190
191
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 189

def read_groups_string=(groups)
  self.read_groups=groups.split(/[\s,]+/)
end

#read_usersObject



217
218
219
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 217

def read_users
  .users.map {|k, v| k if v == 'read'}.compact
end

#read_users=(users) ⇒ Object

Grant read permissions to the users specified. Revokes read permission for all other users. @param users a list of usernames

Examples:

r.read_users= ['one', 'two', 'three']
r.read_users 
=> ['one', 'two', 'three']


228
229
230
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 228

def read_users=(users)
  set_read_users(users, read_users)
end

#read_users_stringObject

Display the users as a comma delimeted string



244
245
246
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 244

def read_users_string
  self.read_users.join(', ')
end

#read_users_string=(users) ⇒ Object

Grant read permissions to the groups specified. Revokes read permission for all other users. @param users a list of usernames

Examples:

r.read_users_string= 'one, two, three'
r.read_users 
=> ['one', 'two', 'three']


239
240
241
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 239

def read_users_string=(users)
  self.read_users=users.split(/[\s,]+/)
end

#set_discover_groups(groups, eligible_groups) ⇒ Object

Grant discover permissions to the groups specified. Revokes discover permission for any of the eligible_groups that are not in groups. This may be used when different users are responsible for setting different groups. Supply the groups the current user is responsible for as the ‘eligible_groups’ @param groups a list of groups @param eligible_groups the groups that are eligible to have their discover permssion revoked.

Examples:

r.discover_groups = ['one', 'two', 'three']
r.discover_groups 
=> ['one', 'two', 'three']
r.set_discover_groups(['one'], ['three'])
r.discover_groups
=> ['one', 'two']  ## 'two' was not eligible to be removed


112
113
114
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 112

def set_discover_groups(groups, eligible_groups)
  set_entities(:discover, :group, groups, eligible_groups)
end

#set_discover_users(users, eligible_users) ⇒ Object

Grant discover permissions to the users specified. Revokes discover permission for any of the eligible_users that are not in users. This may be used when different users are responsible for setting different users. Supply the users the current user is responsible for as the ‘eligible_users’ @param users a list of users @param eligible_users the users that are eligible to have their discover permssion revoked.

Examples:

r.discover_users = ['one', 'two', 'three']
r.discover_users 
=> ['one', 'two', 'three']
r.set_discover_users(['one'], ['three'])
r.discover_users
=> ['one', 'two']  ## 'two' was not eligible to be removed


162
163
164
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 162

def set_discover_users(users, eligible_users)
  set_entities(:discover, :person, users, eligible_users)
end

#set_edit_groups(groups, eligible_groups) ⇒ Object

Grant edit permissions to the groups specified. Revokes edit permission for any of the eligible_groups that are not in groups. This may be used when different users are responsible for setting different groups. Supply the groups the current user is responsible for as the ‘eligible_groups’ @param groups a list of groups @param eligible_groups the groups that are eligible to have their edit permssion revoked.

Examples:

r.edit_groups = ['one', 'two', 'three']
r.edit_groups 
=> ['one', 'two', 'three']
r.set_edit_groups(['one'], ['three'])
r.edit_groups
=> ['one', 'two']  ## 'two' was not eligible to be removed


315
316
317
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 315

def set_edit_groups(groups, eligible_groups)
  set_entities(:edit, :group, groups, eligible_groups)
end

#set_edit_users(users, eligible_users) ⇒ Object

Grant edit permissions to the users specified. Revokes edit permission for any of the eligible_users that are not in users. This may be used when different users are responsible for setting different users. Supply the users the current user is responsible for as the ‘eligible_users’ @param users a list of users @param eligible_users the users that are eligible to have their edit permssion revoked.

Examples:

r.edit_users = ['one', 'two', 'three']
r.edit_users 
=> ['one', 'two', 'three']
r.set_edit_users(['one'], ['three'])
r.edit_users
=> ['one', 'two']  ## 'two' was not eligible to be removed


349
350
351
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 349

def set_edit_users(users, eligible_users)
  set_entities(:edit, :person, users, eligible_users)
end

#set_read_groups(groups, eligible_groups) ⇒ Object

Grant read permissions to the groups specified. Revokes read permission for any of the eligible_groups that are not in groups. This may be used when different users are responsible for setting different groups. Supply the groups the current user is responsible for as the ‘eligible_groups’ @param groups a list of groups @param eligible_groups the groups that are eligible to have their read permssion revoked.

Examples:

r.read_groups = ['one', 'two', 'three']
r.read_groups 
=> ['one', 'two', 'three']
r.set_read_groups(['one'], ['three'])
r.read_groups
=> ['one', 'two']  ## 'two' was not eligible to be removed


213
214
215
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 213

def set_read_groups(groups, eligible_groups)
  set_entities(:read, :group, groups, eligible_groups)
end

#set_read_users(users, eligible_users) ⇒ Object

Grant read permissions to the users specified. Revokes read permission for any of the eligible_users that are not in users. This may be used when different users are responsible for setting different users. Supply the users the current user is responsible for as the ‘eligible_users’ @param users a list of users @param eligible_users the users that are eligible to have their read permssion revoked.

Examples:

r.read_users = ['one', 'two', 'three']
r.read_users 
=> ['one', 'two', 'three']
r.set_read_users(['one'], ['three'])
r.read_users
=> ['one', 'two']  ## 'two' was not eligible to be removed


263
264
265
# File 'app/models/concerns/hydra/access_controls/permissions.rb', line 263

def set_read_users(users, eligible_users)
  set_entities(:read, :person, users, eligible_users)
end