Class: Hyrax::Collections::PermissionsCreateService
- Inherits:
-
Object
- Object
- Hyrax::Collections::PermissionsCreateService
- Defined in:
- app/services/hyrax/collections/permissions_create_service.rb
Class Method Summary collapse
-
.add_access(collection_id:, grants:) ⇒ Object
Add access grants to a collection.
-
.create_default(collection:, creating_user:, grants: []) ⇒ Hyrax::PermissionTemplate
Set the default permissions for a (newly created) collection.
Class Method Details
.add_access(collection_id:, grants:) ⇒ Object
Add access grants to a collection
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
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 |