Class: AdminSet

Inherits:
ActiveFedora::Base show all
Includes:
Hydra::AccessControls::Permissions, Hyrax::HasRepresentative, Hyrax::HumanReadableType, Hyrax::Noid
Defined in:
app/models/admin_set.rb

Overview

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:

  • An AdminSet has_one :permission_tempate

  • A PermissionTemplate belongs_to :admin_set

When an object is added as a member of an AdminSet, the AdminSet's associated PermissionTemplate is applied to that object (e.g. some of the object's attributes are updated as per the rules of the permission template)

See Also:

Constant Summary collapse

DEFAULT_ID =
'admin_set/default'
DEFAULT_TITLE =
['Default Admin Set'].freeze
DEFAULT_WORKFLOW_NAME =
Hyrax.config.default_active_workflow_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hyrax::HumanReadableType

#human_readable_type, #to_solr

Methods included from Hyrax::Noid

#assign_id

Methods inherited from ActiveFedora::Base

supports_property?

Class Method Details

.default_set?(id) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
# File 'app/models/admin_set.rb', line 44

def self.default_set?(id)
  id == DEFAULT_ID
end

.find_or_create_default_admin_set_idObject

Creates the default AdminSet and an associated PermissionTemplate with workflow


53
54
55
56
# File 'app/models/admin_set.rb', line 53

def self.find_or_create_default_admin_set_id
  Hyrax::AdminSetCreateService.create_default_admin_set(admin_set_id: DEFAULT_ID, title: DEFAULT_TITLE) unless exists?(DEFAULT_ID)
  DEFAULT_ID
end

Instance Method Details

#active_workflowSipity::Workflow

Returns:

Raises:

  • (ActiveRecord::RecordNotFound)

74
75
76
# File 'app/models/admin_set.rb', line 74

def active_workflow
  Sipity::Workflow.find_active_workflow_for(admin_set_id: id)
end

#default_set?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'app/models/admin_set.rb', line 48

def default_set?
  self.class.default_set?(id)
end

#permission_templateHyrax::PermissionTemplate

A bit of an analogue for a `has_one :admin_set` as it crosses from Fedora to the DB

Returns:

Raises:

  • (ActiveRecord::RecordNotFound)

66
67
68
# File 'app/models/admin_set.rb', line 66

def permission_template
  Hyrax::PermissionTemplate.find_by!(source_id: id)
end

#reset_access_controls!Object

Calculate and update who should have edit access based on who has “manage” access in the PermissionTemplateAccess


80
81
82
83
84
85
86
87
# File 'app/models/admin_set.rb', line 80

def reset_access_controls!
  # NOTE: This is different from Collections in that it doesn't update read access based on visibility.
  #       See also app/models/concerns/hyrax/collection_behavior.rb#reset_access_controls!
  update!(edit_users: permission_template_edit_users,
          edit_groups: permission_template_edit_groups,
          read_users: permission_template_read_users,
          read_groups: permission_template_read_groups)
end

#to_sObject


58
59
60
# File 'app/models/admin_set.rb', line 58

def to_s
  title.presence || 'No Title'
end