Class: Hyrax::AdminSetCreateService
- Inherits:
-
Object
- Object
- Hyrax::AdminSetCreateService
- Defined in:
- app/services/hyrax/admin_set_create_service.rb
Overview
Responsible for creating a Hyrax::AdministrativeSet and its corresponding data.
-
An associated permission template
-
Available workflows
-
An active workflow
Constant Summary collapse
- DEFAULT_ID =
rubocop:disable Metrics/ClassLength
'admin_set/default'
- DEFAULT_TITLE =
['Default Admin Set'].freeze
Instance Attribute Summary collapse
-
#admin_set ⇒ Object
readonly
Returns the value of attribute admin_set.
-
#creating_user ⇒ Object
readonly
Returns the value of attribute creating_user.
-
#workflow_importer ⇒ Object
readonly
Returns the value of attribute workflow_importer.
Class Method Summary collapse
- .call(admin_set:, creating_user:, **kwargs) ⇒ TrueClass, FalseClass deprecated Deprecated.
-
.call!(admin_set:, creating_user:, **kwargs) ⇒ Hyrax::AdministrativeSet
Creates a non-default Hyrax::AdministrativeSet and corresponding data.
-
.default_admin_set?(id:) ⇒ Boolean
True if the id is for the default admin set; otherwise, false.
-
.find_or_create_default_admin_set ⇒ Hyrax::AdministrativeSet
Finds the default AdministrativeSet if it exists; otherwise, creates it and corresponding data.
Instance Method Summary collapse
- #create ⇒ TrueClass, FalseClass deprecated Deprecated.
-
#create! ⇒ Hyrax::AdministrativeSet
Creates an admin set, setting the creator and the default access controls.
-
#initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer, default_admin_set: false) ⇒ AdminSetCreateService
constructor
A new instance of AdminSetCreateService.
Constructor Details
#initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer, default_admin_set: false) ⇒ AdminSetCreateService
Returns a new instance of AdminSetCreateService.
156 157 158 159 160 161 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 156 def initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer, default_admin_set: false) @admin_set = Hyrax::AdminSetCreateService.send(:admin_set_resource, admin_set) @creating_user = creating_user @workflow_importer = workflow_importer @default_admin_set = default_admin_set end |
Instance Attribute Details
#admin_set ⇒ Object (readonly)
Returns the value of attribute admin_set.
163 164 165 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 163 def admin_set @admin_set end |
#creating_user ⇒ Object (readonly)
Returns the value of attribute creating_user.
163 164 165 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 163 def creating_user @creating_user end |
#workflow_importer ⇒ Object (readonly)
Returns the value of attribute workflow_importer.
163 164 165 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 163 def workflow_importer @workflow_importer end |
Class Method Details
.call(admin_set:, creating_user:, **kwargs) ⇒ TrueClass, FalseClass
Creates a non-default Hyrax::AdministrativeSet and corresponding data
46 47 48 49 50 51 52 53 54 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 46 def call(admin_set:, creating_user:, **kwargs) Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ "Warning: This method may hide runtime errors. " \ "Instead, use 'Hyrax::AdminSetCreateService.call!'. ") call!(admin_set: admin_set_resource(admin_set), creating_user: creating_user, **kwargs).present? rescue RuntimeError => err raise err if default_admin_set?(id: admin_set.id) false end |
.call!(admin_set:, creating_user:, **kwargs) ⇒ Hyrax::AdministrativeSet
Creates a non-default Hyrax::AdministrativeSet and corresponding data
64 65 66 67 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 64 def call!(admin_set:, creating_user:, **kwargs) raise "Use .find_or_create_default_admin_set to create a default admin set" if default_admin_set?(id: admin_set.id) new(admin_set: admin_set, creating_user: creating_user, **kwargs).create! end |
.default_admin_set?(id:) ⇒ Boolean
Returns true if the id is for the default admin set; otherwise, false.
33 34 35 36 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 33 def default_admin_set?(id:) return false if id.blank? id.to_s == default_admin_set_id end |
.find_or_create_default_admin_set ⇒ Hyrax::AdministrativeSet
Finds the default AdministrativeSet if it exists; otherwise, creates it and corresponding data
26 27 28 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 26 def find_or_create_default_admin_set find_default_admin_set || create_default_admin_set! end |
Instance Method Details
#create ⇒ TrueClass, FalseClass
Creates an admin set, setting the creator and the default access controls.
168 169 170 171 172 173 174 175 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 168 def create Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \ "Warning: This method may hide runtime errors. " \ "Instead, use 'Hyrax::AdminSetCreateService.create!'. ") create!.persisted? rescue RuntimeError => _err false end |
#create! ⇒ Hyrax::AdministrativeSet
Creates an admin set, setting the creator and the default access controls.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 180 def create! admin_set.creator = [creating_user.user_key] if creating_user updated_admin_set = Hyrax.persister.save(resource: admin_set).tap do |result| if result ActiveRecord::Base.transaction do = PermissionTemplate.find_by(source_id: result.id.to_s) || .create_default(collection: result, creating_user: creating_user) workflow = create_workflows_for(permission_template: ) create_default_access_for(permission_template: , workflow: workflow) if default_admin_set? end end end Hyrax.publisher.publish('collection.metadata.updated', collection: updated_admin_set, user: creating_user) updated_admin_set end |