Class: Hyrax::CollectionTypes::CreateService
- Inherits:
-
Object
- Object
- Hyrax::CollectionTypes::CreateService
- Defined in:
- app/services/hyrax/collection_types/create_service.rb
Overview
Responsible for creating a CollectionType. If no params are given,the default user collection is assumed as defined by:
-
Hyrax::CollectionType::USER_COLLECTION_MACHINE_ID
-
Hyrax::CollectionType::USER_COLLECTION_DEFAULT_TITLE
-
DEFAULT_OPTIONS
Defined Under Namespace
Classes: InvalidParticipantError
Constant Summary collapse
- DEFAULT_OPTIONS =
{ description: '', nestable: true, brandable: true, discoverable: true, sharable: true, share_applies_to_new_works: true, allow_multiple_membership: true, require_membership: false, assigns_workflow: false, assigns_visibility: false, badge_color: "#663333", participants: [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS }, { agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.registered_group_name, access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }] }.freeze
- USER_COLLECTION_MACHINE_ID =
Hyrax::CollectionType::USER_COLLECTION_MACHINE_ID
- USER_COLLECTION_TITLE =
Hyrax::CollectionType::USER_COLLECTION_DEFAULT_TITLE
- USER_COLLECTION_OPTIONS =
{ description: I18n.t('hyrax.collection_types.create_service.default_description'), nestable: true, brandable: true, discoverable: true, sharable: true, share_applies_to_new_works: false, allow_multiple_membership: true, require_membership: false, assigns_workflow: false, assigns_visibility: false, badge_color: "#705070", participants: [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS }, { agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.registered_group_name, access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }] }.freeze
- ADMIN_SET_MACHINE_ID =
Hyrax::CollectionType::ADMIN_SET_MACHINE_ID
- ADMIN_SET_TITLE =
Hyrax::CollectionType::ADMIN_SET_DEFAULT_TITLE
- ADMIN_SET_OPTIONS =
{ description: I18n.t('hyrax.collection_types.create_service.admin_set_description'), nestable: false, brandable: false, discoverable: false, sharable: true, share_applies_to_new_works: true, allow_multiple_membership: false, require_membership: true, assigns_workflow: true, assigns_visibility: true, badge_color: "#405060", participants: [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS }, { agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }] }.freeze
Class Method Summary collapse
-
.add_default_participants(collection_type_id) ⇒ Object
Add the default participants to a collection_type.
-
.add_participants(collection_type_id, participants) ⇒ Object
Add a participants to a collection_type.
-
.create_admin_set_type ⇒ Hyrax::CollectionType
Create admin set collection type.
-
.create_collection_type(machine_id:, title:, options: {}) ⇒ Hyrax::CollectionType
Create a new collection type.
-
.create_user_collection_type ⇒ Hyrax::CollectionType
Create user collection type.
Class Method Details
.add_default_participants(collection_type_id) ⇒ Object
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability. If calling from Abilities, pass the ability. If you try to get the ability from the user, you end up in an infinit loop.
Add the default participants to a collection_type.
120 121 122 123 124 125 126 127 128 129 |
# File 'app/services/hyrax/collection_types/create_service.rb', line 120 def self.add_default_participants(collection_type_id) return unless collection_type_id default_participants = [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS }, { agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.registered_group_name, access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }] add_participants(collection_type_id, default_participants) end |
.add_participants(collection_type_id, participants) ⇒ Object
Add a participants to a collection_type.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/services/hyrax/collection_types/create_service.rb', line 142 def self.add_participants(collection_type_id, participants) raise(InvalidParticipantError, participants) unless participants.all? { |p| p.key?(:agent_type) && p.key?(:agent_id) && p.key?(:access) } participants.each do |p| Hyrax::CollectionTypeParticipant.create!(hyrax_collection_type_id: collection_type_id, agent_type: p.fetch(:agent_type), agent_id: p.fetch(:agent_id), access: p.fetch(:access)) end rescue InvalidParticipantError => error Rails.logger.error "Participants not created for collection type " \ " #{collection_type_id}: #{error.}" raise error end |
.create_admin_set_type ⇒ Hyrax::CollectionType
Create admin set collection type.
100 101 102 |
# File 'app/services/hyrax/collection_types/create_service.rb', line 100 def self.create_admin_set_type create_collection_type(machine_id: ADMIN_SET_MACHINE_ID, title: ADMIN_SET_TITLE, options: ADMIN_SET_OPTIONS) end |
.create_collection_type(machine_id:, title:, options: {}) ⇒ Hyrax::CollectionType
Create a new collection type.
87 88 89 90 91 92 93 |
# File 'app/services/hyrax/collection_types/create_service.rb', line 87 def self.create_collection_type(machine_id:, title:, options: {}) opts = DEFAULT_OPTIONS.merge().except(:participants) ct = Hyrax::CollectionType.create!(opts.merge(machine_id: machine_id, title: title)) participants = [:participants].presence || DEFAULT_OPTIONS[:participants] add_participants(ct.id, participants) ct end |
.create_user_collection_type ⇒ Hyrax::CollectionType
Create user collection type.
109 110 111 |
# File 'app/services/hyrax/collection_types/create_service.rb', line 109 def self.create_user_collection_type create_collection_type(machine_id: USER_COLLECTION_MACHINE_ID, title: USER_COLLECTION_TITLE, options: USER_COLLECTION_OPTIONS) end |