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:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/hyrax/collections/permissions_create_service.rb', line 35

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

  template.reset_access_controls_for(collection: collection, interpret_visibility: true)
end

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

Set the default permissions for a (newly created) collection

Parameters:

  • collection (#collection_type_gid || Hyrax::AdministrativeSet)

    the collection or admin set 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:



14
15
16
17
18
19
20
21
22
# File 'app/services/hyrax/collections/permissions_create_service.rb', line 14

def 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)
  template = Hyrax::PermissionTemplate.create!(source_id: collection.id.to_s,
                                               access_grants_attributes: access_grants.uniq)

  template.reset_access_controls_for(collection: collection, interpret_visibility: true)
  template
end