Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some documentation for Hyrax::PermissionTemplate #5038

Merged
merged 1 commit into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions app/models/hyrax/permission_template.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
# frozen_string_literal: true
module Hyrax
##
# Defines behavior that is applied to objects added as members of an AdminSet
# Holds policy data about the workflow and permissions applied objects when
# they are deposited through an Administrative Set or a Collection. Each
# template record has a {#source} (through {#source_id}); the template's
# rules inform the behavior of objects deposited through that {#source_model}.
#
# * access rights to stamp on each object
# * calculate embargo/lease release dates
# The {PermissionTemplate} specifies:
#
# There is an interplay between an AdminSet and a PermissionTemplate.
# - an {#active_workflow} that the object will enter and be processed through.
# - {#access_grants} that can be applied to each object (especially at deposit
# time).
# - an embargo configuration ({#release_date} {#release_period}) for default
# embargo behavior.
#
# @see Hyrax::AdminSet for further discussion
class PermissionTemplate < ActiveRecord::Base
# @todo write up what "default embargo behavior", when it is applied, and how
# it interacts with embargoes specified by user input.
#
# @see Hyrax::AdministrativeSet
class PermissionTemplate < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
self.table_name = 'permission_templates'

##
# @!attribute [rw] source_id
# @return [String] identifier for the {Collection} or {AdministrativeSet}
# to which this template applies.
# @!attribute [rw] access_grants
# @return [Hyrax::PermissionTemplateAccess]
# @!attribute [rw] active_workflow
# @return [Sipity::Workflow]
# @!attribute [rw] available_workflows
# @return [Enumerable<Sipity::Workflow>]
has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy
accepts_nested_attributes_for :access_grants, reject_if: :all_blank

# The list of workflows that could be activated; It includes the active workflow
has_many :available_workflows, class_name: 'Sipity::Workflow', dependent: :destroy

# In a perfect world, there would be a join table that enforced uniqueness on the ID.
has_one :active_workflow, -> { where(active: true) }, class_name: 'Sipity::Workflow', foreign_key: :permission_template_id

##
# @api public
#
Expand All @@ -28,12 +53,6 @@ def agent_ids_for(agent_type:, access:)
access_grants.where(agent_type: agent_type, access: access).pluck(:agent_id)
end

# The list of workflows that could be activated; It includes the active workflow
has_many :available_workflows, class_name: 'Sipity::Workflow', dependent: :destroy

# In a perfect world, there would be a join table that enforced uniqueness on the ID.
has_one :active_workflow, -> { where(active: true) }, class_name: 'Sipity::Workflow', foreign_key: :permission_template_id

##
# @note this is a convenience method for +Hyrax.query_service.find_by(id: template.source_id)+
#
Expand Down
6 changes: 6 additions & 0 deletions app/models/sipity.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

##
# {Sipity} is a workflow/state engine.
module Sipity
##
# Cast a given input (e.g. a +::User+ or {Hyrax::Group} to a {Sipity::Agent}).
#
# @param input [Object]
def Agent(input, &block) # rubocop:disable Naming/MethodName
result = case input
when Sipity::Agent
Expand Down
1 change: 1 addition & 0 deletions app/models/sipity/workflow.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
module Sipity
##
# A named workflow for processing an entity. Originally I had thought of
# calling this a Type, but once I extracted the Processing submodule,
# type felt to much of a noun, not conveying potentiality. Workflow
Expand Down
21 changes: 21 additions & 0 deletions spec/indexers/hyrax/valkyrie_administrative_set_indexer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'hyrax/specs/shared_specs'

RSpec.describe Hyrax::AdministrativeSetIndexer do
subject(:service) { described_class.new(resource: admin_set) }
let(:admin_set) { FactoryBot.valkyrie_create(:hyrax_admin_set, title: [admin_set_title]) }
let(:admin_set_title) { 'An Admin Set' }

it 'is resolved from an admin set' do
expect(Hyrax::ValkyrieIndexer.for(resource: admin_set))
.to be_a described_class
end

describe '#to_solr' do
it 'includes default attributes ' do
expect(subject.to_solr)
.to include 'generic_type_si' => 'Admin Set', 'title_tesim' => [admin_set_title]
end
end
end