app/models/admin_set.rb in hyrax-3.0.0.pre.rc1 vs app/models/admin_set.rb in hyrax-3.0.0.pre.rc2
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
# There is an interplay between an AdminSet and a PermissionTemplate. Given
# that AdminSet is an ActiveFedora::Base and PermissionTemplate is ActiveRecord::Base
# we don't have the usual :has_many or :belongs_to methods to assist in defining that
# relationship. However, from a conceptual standpoint:
#
@@ -19,36 +20,25 @@
include Hydra::AccessControls::WithAccessRight
include Hyrax::Noid
include Hyrax::HumanReadableType
include Hyrax::HasRepresentative
- DEFAULT_ID = 'admin_set/default'.freeze
+ DEFAULT_ID = 'admin_set/default'
DEFAULT_TITLE = ['Default Admin Set'].freeze
DEFAULT_WORKFLOW_NAME = Hyrax.config.default_active_workflow_name
validates_with Hyrax::HasOneTitleValidator
class_attribute :human_readable_short_description
self.indexer = Hyrax::AdminSetIndexer
- property :title, predicate: ::RDF::Vocab::DC.title do |index|
- index.as :stored_searchable, :facetable
- end
- property :alt_title, predicate: ::RDF::Vocab::DC.alternative do |index|
- index.as :stored_searchable
- end
-
- property :description, predicate: ::RDF::Vocab::DC.description do |index|
- index.as :stored_searchable
- end
-
- property :creator, predicate: ::RDF::Vocab::DC11.creator do |index|
- index.as :symbol
- end
+ property :title, predicate: ::RDF::Vocab::DC.title
+ property :alternative_title, predicate: ::RDF::Vocab::DC.alternative
+ property :description, predicate: ::RDF::Vocab::DC.description
+ property :creator, predicate: ::RDF::Vocab::DC11.creator
has_many :members,
- predicate: Hyrax.config.admin_set_predicate,
+ predicate: Hyrax.config.admin_set_predicate,
class_name: 'ActiveFedora::Base'
- # rubocop:enable Rails/HasManyOrHasOneDependent
before_destroy :check_if_not_default_set, :check_if_empty
after_destroy :destroy_permission_template
def self.default_set?(id)
@@ -64,11 +54,11 @@
Hyrax::AdminSetCreateService.create_default_admin_set(admin_set_id: DEFAULT_ID, title: DEFAULT_TITLE) unless exists?(DEFAULT_ID)
DEFAULT_ID
end
def to_s
- title.present? ? title : 'No Title'
+ title.presence || 'No Title'
end
# @api public
# A bit of an analogue for a `has_one :admin_set` as it crosses from Fedora to the DB
# @return [Hyrax::PermissionTemplate]
@@ -96,42 +86,42 @@
read_groups: permission_template_read_groups)
end
private
- def permission_template_edit_users
- permission_template.agent_ids_for(access: 'manage', agent_type: 'user')
- end
+ def permission_template_edit_users
+ permission_template.agent_ids_for(access: 'manage', agent_type: 'user')
+ end
- def permission_template_edit_groups
- permission_template.agent_ids_for(access: 'manage', agent_type: 'group')
- end
+ def permission_template_edit_groups
+ permission_template.agent_ids_for(access: 'manage', agent_type: 'group')
+ end
- def permission_template_read_users
- (permission_template.agent_ids_for(access: 'view', agent_type: 'user') +
- permission_template.agent_ids_for(access: 'deposit', agent_type: 'user')).uniq
- end
+ def permission_template_read_users
+ (permission_template.agent_ids_for(access: 'view', agent_type: 'user') +
+ permission_template.agent_ids_for(access: 'deposit', agent_type: 'user')).uniq
+ end
- def permission_template_read_groups
- (permission_template.agent_ids_for(access: 'view', agent_type: 'group') +
- permission_template.agent_ids_for(access: 'deposit', agent_type: 'group')).uniq -
- [::Ability.registered_group_name, ::Ability.public_group_name]
- end
+ def permission_template_read_groups
+ (permission_template.agent_ids_for(access: 'view', agent_type: 'group') +
+ permission_template.agent_ids_for(access: 'deposit', agent_type: 'group')).uniq -
+ [::Ability.registered_group_name, ::Ability.public_group_name]
+ end
- def destroy_permission_template
- permission_template.destroy
- rescue ActiveRecord::RecordNotFound
- true
- end
+ def destroy_permission_template
+ permission_template.destroy
+ rescue ActiveRecord::RecordNotFound
+ true
+ end
- def check_if_empty
- return true if members.empty?
- errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_not_empty')
- throw :abort
- end
+ def check_if_empty
+ return true if members.empty?
+ errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_not_empty')
+ throw :abort
+ end
- def check_if_not_default_set
- return true unless default_set?
- errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_default_set')
- throw :abort
- end
+ def check_if_not_default_set
+ return true unless default_set?
+ errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_default_set')
+ throw :abort
+ end
end