Class: Hyrax::Collections::PermissionsCreateService

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

Class Method Summary collapse

Class Method Details

.add_access(collection_id:, grants:) ⇒ Object

Add access grants to a collection

Examples:

grants

[ { agent_type: Hyrax::PermissionTemplateAccess::GROUP,
    agent_id: 'my_group_name',
    access: Hyrax::PermissionTemplateAccess::DEPOSIT } ]

Parameters:

  • collection_id (String)

    id of a collection

  • grants (Array<Hash>)

    array of grants to add to the collection

See Also:


31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/hyrax/collections/permissions_create_service.rb', line 31

def self.add_access(collection_id:, grants:)
  collection = Collection.find(collection_id)
  template = Hyrax::PermissionTemplate.find_by!(source_id: collection_id)
  grants.each do |grant|
    Hyrax::PermissionTemplateAccess.find_or_create_by(permission_template_id: template.id,
                                                      agent_type: grant[:agent_type],
                                                      agent_id: grant[:agent_id],
                                                      access: grant[:access])
  end
  collection.reset_access_controls!
end

.create_default(collection:, creating_user:, grants: []) ⇒ Hyrax::PermissionTemplate

Set the default permissions for a (newly created) collection

Parameters:

  • collection (Collection)

    the collection the new permissions will act on

  • creating_user (User)

    the user that created the collection

  • grants (Array<Hash>) (defaults to: [])

    additional grants to apply to the new collection

Returns:


12
13
14
15
16
17
18
# File 'app/services/hyrax/collections/permissions_create_service.rb', line 12

def self.create_default(collection:, creating_user:, grants: [])
  collection_type = Hyrax::CollectionType.find_by_gid!(collection.collection_type_gid)
  access_grants = access_grants_attributes(collection_type: collection_type, creating_user: creating_user, grants: grants)
  PermissionTemplate.create!(source_id: collection.id,
                             access_grants_attributes: access_grants.uniq)
  collection.reset_access_controls!
end