Class: Hyrax::AdminSetCreateService
- Inherits:
-
Object
- Object
- Hyrax::AdminSetCreateService
- Defined in:
- app/services/hyrax/admin_set_create_service.rb
Overview
Responsible for creating an AdminSet and its corresponding data:
-
An associated permission template
-
Available workflows
-
An active workflow
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
Creates a non-default AdminSet and corresponding data.
-
.create_default_admin_set(admin_set_id:, title:) ⇒ TrueClass
Creates the default AdminSet and corresponding data.
Instance Method Summary collapse
-
#create ⇒ TrueClass, FalseClass
Creates an admin set, setting the creator and the default access controls.
-
#initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer) ⇒ AdminSetCreateService
constructor
A new instance of AdminSetCreateService.
Constructor Details
#initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer) ⇒ AdminSetCreateService
Returns a new instance of AdminSetCreateService.
45 46 47 48 49 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 45 def initialize(admin_set:, creating_user:, workflow_importer: default_workflow_importer) @admin_set = admin_set @creating_user = creating_user @workflow_importer = workflow_importer end |
Instance Attribute Details
#admin_set ⇒ Object (readonly)
Returns the value of attribute admin_set.
51 52 53 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 51 def admin_set @admin_set end |
#creating_user ⇒ Object (readonly)
Returns the value of attribute creating_user.
51 52 53 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 51 def creating_user @creating_user end |
#workflow_importer ⇒ Object (readonly)
Returns the value of attribute workflow_importer.
51 52 53 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 51 def workflow_importer @workflow_importer end |
Class Method Details
.call(admin_set:, creating_user:, **kwargs) ⇒ TrueClass, FalseClass
Creates a non-default AdminSet and corresponding data
37 38 39 40 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 37 def self.call(admin_set:, creating_user:, **kwargs) raise "Use .create_default_admin_set to create a default admin set" if admin_set.default_set? new(admin_set: admin_set, creating_user: creating_user, **kwargs).create end |
.create_default_admin_set(admin_set_id:, title:) ⇒ TrueClass
Creates the default AdminSet and corresponding data
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 18 def self.create_default_admin_set(admin_set_id:, title:) admin_set = AdminSet.new(id: admin_set_id, title: Array.wrap(title)) begin new(admin_set: admin_set, creating_user: nil).create rescue ActiveFedora::IllegalOperation # It is possible that another thread created the AdminSet just before this method # was called, so ActiveFedora will raise IllegalOperation. In this case we can safely # ignore the error. Rails.logger.error("AdminSet ID=#{AdminSet::DEFAULT_ID} may or may not have been created due to threading issues.") end end |
Instance Method Details
#create ⇒ TrueClass, FalseClass
Creates an admin set, setting the creator and the default access controls.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/services/hyrax/admin_set_create_service.rb', line 55 def create admin_set.edit_groups = [admin_group_name] admin_set.creator = [creating_user.user_key] if creating_user admin_set.save.tap do |result| if result ActiveRecord::Base.transaction do = workflow = create_workflows_for(permission_template: ) create_default_access_for(permission_template: , workflow: workflow) if admin_set.default_set? end end end end |