app/models/hyrax/permission_template.rb in hyrax-3.0.0.pre.rc1 vs app/models/hyrax/permission_template.rb in hyrax-3.0.0.pre.rc2
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
module Hyrax
# Defines behavior that is applied to objects added as members of an AdminSet
#
# * access rights to stamp on each object
# * calculate embargo/lease release dates
@@ -21,55 +22,59 @@
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, foreign_key: :permission_template_id
+ 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
# A bit of an analogue for a `belongs_to :source_model` as it crosses from Fedora to the DB
- # @return [AdminSet | Collection]
+ # @return [AdminSet, ::Collection]
# @raise [Hyrax::ObjectNotFoundError] when neither an AdminSet or Collection is found
def source_model
- admin_set
- rescue Hyrax::ObjectNotFoundError
- collection
+ ActiveFedora::Base.find(source_id)
+ rescue ActiveFedora::ObjectNotFoundError
+ raise Hyrax::ObjectNotFoundError
end
# A bit of an analogue for a `belongs_to :admin_set` as it crosses from Fedora to the DB
+ # @deprecated Use #source_model instead
# @return [AdminSet]
# @raise [Hyrax::ObjectNotFoundError] when the we cannot find the AdminSet
def admin_set
+ Deprecation.warn('Use #source_model instead')
return AdminSet.find(source_id) if AdminSet.exists?(source_id)
raise Hyrax::ObjectNotFoundError
rescue ActiveFedora::ActiveFedoraError # TODO: remove the rescue when active_fedora issue #1276 is fixed
raise Hyrax::ObjectNotFoundError
end
# A bit of an analogue for a `belongs_to :collection` as it crosses from Fedora to the DB
+ # @deprecated Use #source_model instead
# @return [Collection]
# @raise [Hyrax::ObjectNotFoundError] when the we cannot find the Collection
def collection
- return Collection.find(source_id) if Collection.exists?(source_id)
+ Deprecation.warn('Use #source_model instead')
+ return ::Collection.find(source_id) if ::Collection.exists?(source_id)
raise Hyrax::ObjectNotFoundError
rescue ActiveFedora::ActiveFedoraError # TODO: remove the rescue when active_fedora issue #1276 is fixed
raise Hyrax::ObjectNotFoundError
end
# Valid Release Period values
- RELEASE_TEXT_VALUE_FIXED = 'fixed'.freeze
- RELEASE_TEXT_VALUE_NO_DELAY = 'now'.freeze
+ RELEASE_TEXT_VALUE_FIXED = 'fixed'
+ RELEASE_TEXT_VALUE_NO_DELAY = 'now'
# Valid Release Varies sub-options
- RELEASE_TEXT_VALUE_BEFORE_DATE = 'before'.freeze
- RELEASE_TEXT_VALUE_EMBARGO = 'embargo'.freeze
- RELEASE_TEXT_VALUE_6_MONTHS = '6mos'.freeze
- RELEASE_TEXT_VALUE_1_YEAR = '1yr'.freeze
- RELEASE_TEXT_VALUE_2_YEARS = '2yrs'.freeze
- RELEASE_TEXT_VALUE_3_YEARS = '3yrs'.freeze
+ RELEASE_TEXT_VALUE_BEFORE_DATE = 'before'
+ RELEASE_TEXT_VALUE_EMBARGO = 'embargo'
+ RELEASE_TEXT_VALUE_6_MONTHS = '6mos'
+ RELEASE_TEXT_VALUE_1_YEAR = '1yr'
+ RELEASE_TEXT_VALUE_2_YEARS = '2yrs'
+ RELEASE_TEXT_VALUE_3_YEARS = '3yrs'
# Key/value pair of valid embargo periods. Values are number of months embargoed.
RELEASE_EMBARGO_PERIODS = {
RELEASE_TEXT_VALUE_6_MONTHS => 6,
RELEASE_TEXT_VALUE_1_YEAR => 12,
@@ -134,24 +139,24 @@
visibility == value
end
private
- # If template requires no delays, check if date is exactly today
- def check_no_delay_requirements(date)
- return true unless release_no_delay?
- date == Time.zone.today
- end
+ # If template requires no delays, check if date is exactly today
+ def check_no_delay_requirements(date)
+ return true unless release_no_delay?
+ date == Time.zone.today
+ end
- # If template requires a release before a specific date, check this date is valid
- def check_before_date_requirements(date)
- return true unless release_before_date? && release_date.present?
- date <= release_date
- end
+ # If template requires a release before a specific date, check this date is valid
+ def check_before_date_requirements(date)
+ return true unless release_before_date? && release_date.present?
+ date <= release_date
+ end
- # If template requires an exact date, check this date matches
- def check_fixed_date_requirements(date)
- return true unless release_fixed_date? && release_date.present?
- date == release_date
- end
+ # If template requires an exact date, check this date matches
+ def check_fixed_date_requirements(date)
+ return true unless release_fixed_date? && release_date.present?
+ date == release_date
+ end
end
end