Module: Hydra::ModelMixins::RightsMetadata

Included in:
AdminPolicy
Defined in:
lib/hydra/model_mixins/rights_metadata.rb

Instance Method Summary collapse

Instance Method Details

#discover_groupsObject

Return a list of groups that have discover permission



41
42
43
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 41

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


52
53
54
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 52

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

#discover_groups_stringObject

Display the groups a comma delimeted string



68
69
70
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 68

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


63
64
65
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 63

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

#discover_usersObject



91
92
93
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 91

def discover_users
  .individuals.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']


102
103
104
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 102

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

#discover_users_stringObject

Display the users as a comma delimeted string



118
119
120
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 118

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


113
114
115
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 113

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

#edit_groupsObject

Return a list of groups that have edit permission



244
245
246
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 244

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


255
256
257
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 255

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

#edit_groups_stringObject

Display the groups a comma delimeted string



271
272
273
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 271

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


266
267
268
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 266

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

#edit_usersObject



294
295
296
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 294

def edit_users
  .individuals.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']


305
306
307
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 305

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

#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
38
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 34

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

end

#permissions=(params) ⇒ Object

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

Examples:

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


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 10

def permissions=(params)
  perm_hash = {'person' => .individuals, 'group'=> .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
  
  .update_permissions(perm_hash)
end

#read_groupsObject

Return a list of groups that have discover permission



142
143
144
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 142

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


153
154
155
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 153

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

#read_groups_stringObject

Display the groups a comma delimeted string



169
170
171
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 169

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


164
165
166
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 164

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

#read_usersObject



192
193
194
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 192

def read_users
  .individuals.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']


203
204
205
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 203

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

#read_users_stringObject

Display the users as a comma delimeted string



219
220
221
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 219

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


214
215
216
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 214

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


87
88
89
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 87

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


137
138
139
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 137

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


290
291
292
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 290

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


324
325
326
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 324

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


188
189
190
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 188

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


238
239
240
# File 'lib/hydra/model_mixins/rights_metadata.rb', line 238

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