Class: Hyrax::PermissionTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hyrax::PermissionTemplate
- Defined in:
- app/models/hyrax/permission_template.rb
Overview
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
There is an interplay between an AdminSet and a PermissionTemplate.
Constant Summary collapse
- RELEASE_TEXT_VALUE_FIXED =
Valid Release Period values
'fixed'.freeze
- RELEASE_TEXT_VALUE_NO_DELAY =
'now'.freeze
- RELEASE_TEXT_VALUE_BEFORE_DATE =
Valid Release Varies sub-options
'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_EMBARGO_PERIODS =
Key/value pair of valid embargo periods. Values are number of months embargoed.
{ RELEASE_TEXT_VALUE_6_MONTHS => 6, RELEASE_TEXT_VALUE_1_YEAR => 12, RELEASE_TEXT_VALUE_2_YEARS => 24, RELEASE_TEXT_VALUE_3_YEARS => 36 }.freeze
Instance Method Summary collapse
-
#admin_set ⇒ AdminSet
A bit of an analogue for a ‘belongs_to :admin_set` as it crosses from Fedora to the DB.
-
#agent_ids_for(agent_type:, access:) ⇒ Array<String>
Retrieve the agent_ids associated with the given agent_type and access.
-
#release_before_date? ⇒ Boolean
Does this permission template require a date (or embargo) that all works are released before NOTE: date will be in release_date.
-
#release_date ⇒ Object
Override release_date getter to return a dynamically calculated date of release based one release requirements.
-
#release_fixed_date? ⇒ Boolean
Does this permission template require a specific date of release for all works NOTE: date will be in release_date.
-
#release_max_embargo? ⇒ Boolean
Is there a maximum embargo period specified by this permission template NOTE: latest embargo date returned by release_date, maximum embargo period will be in release_period.
-
#release_no_delay? ⇒ Boolean
Does this permission template require no release delays (i.e. no embargoes allowed).
-
#valid_release_date?(date) ⇒ Boolean
Determines whether a given release date is valid based on this template’s requirements.
-
#valid_visibility?(value) ⇒ Boolean
Determines whether a given visibility setting is valid based on this template’s requirements.
Instance Method Details
#admin_set ⇒ AdminSet
A bit of an analogue for a ‘belongs_to :admin_set` as it crosses from Fedora to the DB
34 35 36 |
# File 'app/models/hyrax/permission_template.rb', line 34 def admin_set AdminSet.find(admin_set_id) end |
#agent_ids_for(agent_type:, access:) ⇒ Array<String>
Retrieve the agent_ids associated with the given agent_type and access
21 22 23 |
# File 'app/models/hyrax/permission_template.rb', line 21 def agent_ids_for(agent_type:, access:) access_grants.where(agent_type: agent_type, access: access).pluck(:agent_id) end |
#release_before_date? ⇒ Boolean
Does this permission template require a date (or embargo) that all works are released before NOTE: date will be in release_date
71 72 73 74 |
# File 'app/models/hyrax/permission_template.rb', line 71 def release_before_date? # All PermissionTemplate embargoes are dynamically determined release before dates release_period == RELEASE_TEXT_VALUE_BEFORE_DATE || end |
#release_date ⇒ Object
Override release_date getter to return a dynamically calculated date of release based one release requirements. Returns embargo date when release_max_embargo?==true. Returns today’s date when release_no_delay?==true.
87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/hyrax/permission_template.rb', line 87 def release_date # If no release delays allowed, return today's date as release date return Time.zone.today if release_no_delay? # If this isn't an embargo, just return release_date from database return self[:release_date] unless # Otherwise (if an embargo), return latest embargo date by adding specified months to today's date Time.zone.today + RELEASE_EMBARGO_PERIODS.fetch(release_period).months end |
#release_fixed_date? ⇒ Boolean
Does this permission template require a specific date of release for all works NOTE: date will be in release_date
60 61 62 |
# File 'app/models/hyrax/permission_template.rb', line 60 def release_fixed_date? release_period == RELEASE_TEXT_VALUE_FIXED end |
#release_max_embargo? ⇒ Boolean
Is there a maximum embargo period specified by this permission template NOTE: latest embargo date returned by release_date, maximum embargo period will be in release_period
78 79 80 81 |
# File 'app/models/hyrax/permission_template.rb', line 78 def # Is it a release period in one of our valid embargo periods? RELEASE_EMBARGO_PERIODS.key?(release_period) end |
#release_no_delay? ⇒ Boolean
Does this permission template require no release delays (i.e. no embargoes allowed)
65 66 67 |
# File 'app/models/hyrax/permission_template.rb', line 65 def release_no_delay? release_period == RELEASE_TEXT_VALUE_NO_DELAY end |
#valid_release_date?(date) ⇒ Boolean
Determines whether a given release date is valid based on this template’s requirements
100 101 102 103 |
# File 'app/models/hyrax/permission_template.rb', line 100 def valid_release_date?(date) # Validate date against all release date requirements check_no_delay_requirements(date) && check_before_date_requirements(date) && check_fixed_date_requirements(date) end |
#valid_visibility?(value) ⇒ Boolean
Determines whether a given visibility setting is valid based on this template’s requirements
107 108 109 110 111 112 113 |
# File 'app/models/hyrax/permission_template.rb', line 107 def valid_visibility?(value) # If template doesn't specify a visiblity (i.e. is "varies"), then any visibility is valid return true if visibility.blank? # Validate that passed in value matches visibility requirement exactly visibility == value end |