Class: AdminSet

Inherits:
ActiveFedora::Base
  • Object
show all
Includes:
Hydra::AccessControls::WithAccessRight, 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'.freeze
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

Class Method Details

.default_set?(id) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

Instance Method Details

#active_workflowSipity::Workflow

Returns:

Raises:

  • (ActiveRecord::RecordNotFound)


81
82
83
# File 'app/models/admin_set.rb', line 81

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

#default_set?Boolean

Returns:

  • (Boolean)


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

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)


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

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

#to_sObject



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

def to_s
  title.present? ? title : 'No Title'
end

#update_access_controls!Object

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



87
88
89
90
# File 'app/models/admin_set.rb', line 87

def update_access_controls!
  update!(edit_users: permission_template.agent_ids_for(access: 'manage', agent_type: 'user'),
          edit_groups: permission_template.agent_ids_for(access: 'manage', agent_type: 'group'))
end