Class: Hyrax::PermissionManager

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/permission_manager.rb

Overview

Provides setters and getters for the three most common permission modes:

- :discover
- :edit
- :read

Examples:

my_resource = Hyrax.persister.save(resource: Hyrax::Resource.new)
permissions = PermissionManager.new(resource: my_resource)

permissions.read_users # => []
permissions.read_users = ['a_user_key']
permissions.read_users # => ['a_user_key']
permissions.read_users += ['another_user_key']
permissions.read_users # => ['a_user_key', 'another_user_key']

permissions.acl.permissions
# => #<Set: {#<Hyrax::Permission access_to=#<Valkyrie::ID:0x00 @id="81dc73b1-f244-48a7-9c4c-24c7ef528291"> agent="a_user_key" mode=:read>,
        <Hyrax::Permission access_to=#<Valkyrie::ID:0x00 @id="81dc73b1-f244-48a7-9c4c-24c7ef528291"> agent="another_user_key" mode=:read>}>

permissions.read_users = []
permissions.read_users # => []
permissions.acl.permissions # => #<Set: {}>

permissions.acl.save

See Also:

Constant Summary collapse

DISCOVER =
:discover
EDIT =
:edit
READ =
:read

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, acl_class: Hyrax::AccessControlList) ⇒ PermissionManager

Returns a new instance of PermissionManager.

Parameters:

  • resource (Valkyrie::Resource)


47
48
49
# File 'app/services/hyrax/permission_manager.rb', line 47

def initialize(resource:, acl_class: Hyrax::AccessControlList)
  self.acl = acl_class.new(resource: resource)
end

Instance Attribute Details

#aclHyrax::AccessControlList



43
44
45
# File 'app/services/hyrax/permission_manager.rb', line 43

def acl
  @acl
end

Instance Method Details

#discover_groupsEnumerable<String>

Returns:

  • (Enumerable<String>)


53
54
55
# File 'app/services/hyrax/permission_manager.rb', line 53

def discover_groups
  groups_for(mode: DISCOVER)
end

#discover_groups=(groups) ⇒ Enumerable<String>

Parameters:

  • groups (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


61
62
63
64
# File 'app/services/hyrax/permission_manager.rb', line 61

def discover_groups=(groups)
  update_groups_for(mode: DISCOVER, groups: groups)
  discover_groups
end

#discover_usersEnumerable<String>

Returns:

  • (Enumerable<String>)


68
69
70
# File 'app/services/hyrax/permission_manager.rb', line 68

def discover_users
  users_for(mode: DISCOVER)
end

#discover_users=(users) ⇒ Enumerable<String>

Parameters:

  • users (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


76
77
78
79
# File 'app/services/hyrax/permission_manager.rb', line 76

def discover_users=(users)
  update_users_for(mode: DISCOVER, users: users)
  discover_users
end

#edit_groupsEnumerable<String>

Returns:

  • (Enumerable<String>)


83
84
85
# File 'app/services/hyrax/permission_manager.rb', line 83

def edit_groups
  groups_for(mode: EDIT)
end

#edit_groups=(groups) ⇒ Enumerable<String>

Parameters:

  • groups (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


91
92
93
94
# File 'app/services/hyrax/permission_manager.rb', line 91

def edit_groups=(groups)
  update_groups_for(mode: EDIT, groups: groups)
  edit_groups
end

#edit_usersEnumerable<String>

Returns:

  • (Enumerable<String>)


98
99
100
# File 'app/services/hyrax/permission_manager.rb', line 98

def edit_users
  users_for(mode: EDIT)
end

#edit_users=(users) ⇒ Enumerable<String>

Parameters:

  • users (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


106
107
108
109
# File 'app/services/hyrax/permission_manager.rb', line 106

def edit_users=(users)
  update_users_for(mode: EDIT, users: users)
  edit_users
end

#read_groupsEnumerable<String>

Returns:

  • (Enumerable<String>)


113
114
115
# File 'app/services/hyrax/permission_manager.rb', line 113

def read_groups
  groups_for(mode: READ)
end

#read_groups=(groups) ⇒ Enumerable<String>

Parameters:

  • groups (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


121
122
123
124
# File 'app/services/hyrax/permission_manager.rb', line 121

def read_groups=(groups)
  update_groups_for(mode: READ, groups: groups)
  read_groups
end

#read_usersEnumerable<String>

Returns:

  • (Enumerable<String>)


128
129
130
# File 'app/services/hyrax/permission_manager.rb', line 128

def read_users
  users_for(mode: READ)
end

#read_users=(users) ⇒ Enumerable<String>

Parameters:

  • users (Enumerable<#to_s>)

Returns:

  • (Enumerable<String>)


136
137
138
139
# File 'app/services/hyrax/permission_manager.rb', line 136

def read_users=(users)
  update_users_for(mode: READ, users: users)
  read_users
end