Class: Sufia::AdminSetCreateService
- Inherits:
-
Object
- Object
- Sufia::AdminSetCreateService
- Defined in:
- app/services/sufia/admin_set_create_service.rb
Overview
Creates AdminSets
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_name ⇒ Object
readonly
Returns the value of attribute workflow_name.
Class Method Summary collapse
Instance Method Summary collapse
- #access_grants_attributes ⇒ Object
-
#create ⇒ TrueClass, FalseClass
Creates an admin set, setting the creator and the default access controls.
- #create_permission_template ⇒ Object
-
#initialize(admin_set, creating_user, workflow_name) ⇒ AdminSetCreateService
constructor
A new instance of AdminSetCreateService.
Constructor Details
#initialize(admin_set, creating_user, workflow_name) ⇒ AdminSetCreateService
19 20 21 22 23 |
# File 'app/services/sufia/admin_set_create_service.rb', line 19 def initialize(admin_set, creating_user, workflow_name) @admin_set = admin_set @creating_user = creating_user @workflow_name = workflow_name || AdminSet::DEFAULT_WORKFLOW_NAME end |
Instance Attribute Details
#admin_set ⇒ Object (readonly)
Returns the value of attribute admin_set.
25 26 27 |
# File 'app/services/sufia/admin_set_create_service.rb', line 25 def admin_set @admin_set end |
#creating_user ⇒ Object (readonly)
Returns the value of attribute creating_user.
25 26 27 |
# File 'app/services/sufia/admin_set_create_service.rb', line 25 def creating_user @creating_user end |
#workflow_name ⇒ Object (readonly)
Returns the value of attribute workflow_name.
25 26 27 |
# File 'app/services/sufia/admin_set_create_service.rb', line 25 def workflow_name @workflow_name end |
Class Method Details
.create_default! ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/services/sufia/admin_set_create_service.rb', line 4 def self.create_default! return if AdminSet.exists?(AdminSet::DEFAULT_ID) admin_set = AdminSet.new(id: AdminSet::DEFAULT_ID, title: ['Default Admin Set']) begin new(admin_set, nil, AdminSet::DEFAULT_WORKFLOW_NAME).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
#access_grants_attributes ⇒ Object
38 39 40 41 |
# File 'app/services/sufia/admin_set_create_service.rb', line 38 def access_grants_attributes return [] unless creating_user [{ agent_type: 'user', agent_id: creating_user.user_key, access: 'manage' }] end |
#create ⇒ TrueClass, FalseClass
Creates an admin set, setting the creator and the default access controls.
29 30 31 32 33 34 35 36 |
# File 'app/services/sufia/admin_set_create_service.rb', line 29 def create admin_set.read_groups = ['public'] admin_set.edit_groups = ['admin'] admin_set.creator = [creating_user.user_key] if creating_user admin_set.save.tap do |result| if result end end |
#create_permission_template ⇒ Object
43 44 45 46 47 |
# File 'app/services/sufia/admin_set_create_service.rb', line 43 def PermissionTemplate.create!(admin_set_id: admin_set.id, access_grants_attributes: access_grants_attributes, workflow_name: workflow_name) end |