Class: Hyrax::PermissionTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hyrax::PermissionTemplate
- Defined in:
- app/models/hyrax/permission_template.rb
Overview
write up what “default embargo behavior”, when it is applied, and how it interacts with embargoes specified by user input.
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.
The PermissionTemplate specifies:
-
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.
Additionally, the PermissionTemplate grants authority to perform actions that relate to the Administrative Set/Collection itself. Rules for who can deposit to, view(?!), or manage the admin set are governed by related PermissionTemplateAccess records. Administrat Sets should have a manager granted by some such record.
Constant Summary collapse
- RELEASE_TEXT_VALUE_FIXED =
Valid Release Period values
'fixed'
- RELEASE_TEXT_VALUE_NO_DELAY =
'now'
- RELEASE_TEXT_VALUE_BEFORE_DATE =
Valid Release Varies sub-options
'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'
- 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 Attribute Summary collapse
- #access_grants ⇒ Hyrax::PermissionTemplateAccess
- #active_workflow ⇒ Sipity::Workflow
- #available_workflows ⇒ Enumerable<Sipity::Workflow>
-
#source_id ⇒ String
Identifier for the Collection or AdministrativeSet to which this template applies.
Instance Method Summary collapse
-
#agent_ids_for(agent_type:, access:) ⇒ Array<String>
Retrieve the agent_ids associated with the given agent_type and access.
- #edit_groups ⇒ Array<String>
- #edit_users ⇒ Array<String>
- #read_groups ⇒ Array<String>
- #read_users ⇒ Array<String>
-
#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).
- #reset_access_controls_for(collection:, interpret_visibility: false) ⇒ Boolean
-
#source ⇒ Hyrax::Resource
The collection this template is associated with.
-
#source_model ⇒ AdminSet, ::Collection
A bit of an analogue for a ‘belongs_to :source_model` as it crosses from Fedora to the DB.
-
#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 Attribute Details
#access_grants ⇒ Hyrax::PermissionTemplateAccess
50 |
# File 'app/models/hyrax/permission_template.rb', line 50 has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy |
#active_workflow ⇒ Sipity::Workflow
50 |
# File 'app/models/hyrax/permission_template.rb', line 50 has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy |
#available_workflows ⇒ Enumerable<Sipity::Workflow>
50 |
# File 'app/models/hyrax/permission_template.rb', line 50 has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy |
#source_id ⇒ String
Returns identifier for the Collection or AdministrativeSet to which this template applies.
50 |
# File 'app/models/hyrax/permission_template.rb', line 50 has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy |
Instance Method Details
#agent_ids_for(agent_type:, access:) ⇒ Array<String>
Retrieve the agent_ids associated with the given agent_type and access
68 69 70 |
# File 'app/models/hyrax/permission_template.rb', line 68 def agent_ids_for(agent_type:, access:) access_grants.where(agent_type: agent_type, access: access).pluck(:agent_id) end |
#edit_groups ⇒ Array<String>
179 180 181 |
# File 'app/models/hyrax/permission_template.rb', line 179 def edit_groups agent_ids_for(access: 'manage', agent_type: 'group') end |
#edit_users ⇒ Array<String>
173 174 175 |
# File 'app/models/hyrax/permission_template.rb', line 173 def edit_users agent_ids_for(access: 'manage', agent_type: 'user') end |
#read_groups ⇒ Array<String>
192 193 194 195 196 |
# File 'app/models/hyrax/permission_template.rb', line 192 def read_groups (agent_ids_for(access: 'view', agent_type: 'group') + agent_ids_for(access: 'deposit', agent_type: 'group')).uniq - [::Ability.registered_group_name, ::Ability.public_group_name] end |
#read_users ⇒ Array<String>
185 186 187 188 |
# File 'app/models/hyrax/permission_template.rb', line 185 def read_users (agent_ids_for(access: 'view', agent_type: 'user') + agent_ids_for(access: 'deposit', agent_type: 'user')).uniq 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
127 128 129 130 |
# File 'app/models/hyrax/permission_template.rb', line 127 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.
143 144 145 146 147 148 149 150 151 152 |
# File 'app/models/hyrax/permission_template.rb', line 143 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
116 117 118 |
# File 'app/models/hyrax/permission_template.rb', line 116 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
134 135 136 137 |
# File 'app/models/hyrax/permission_template.rb', line 134 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)
121 122 123 |
# File 'app/models/hyrax/permission_template.rb', line 121 def release_no_delay? release_period == RELEASE_TEXT_VALUE_NO_DELAY end |
#reset_access_controls_for(collection:, interpret_visibility: false) ⇒ Boolean
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'app/models/hyrax/permission_template.rb', line 203 def reset_access_controls_for(collection:, interpret_visibility: false) # rubocop:disable Metrics/MethodLength interpreted_read_groups = read_groups if interpret_visibility visibilities = Hyrax.config.visibility_map interpreted_read_groups -= visibilities.deletions_for(visibility: collection.visibility) interpreted_read_groups += visibilities.additions_for(visibility: collection.visibility) end case collection when Valkyrie::Resource collection..edit_groups = edit_groups collection..edit_users = edit_users collection..read_groups = interpreted_read_groups collection..read_users = read_users collection..acl.save else collection.update!(edit_users: edit_users, edit_groups: edit_groups, read_users: read_users, read_groups: interpreted_read_groups.uniq) end end |
#source ⇒ Hyrax::Resource
this is a convenience method for Hyrax.query_service.find_by(id: template.source_id)
Returns the collection this template is associated with.
76 77 78 |
# File 'app/models/hyrax/permission_template.rb', line 76 def source Hyrax.query_service.find_by(id: source_id) end |
#source_model ⇒ AdminSet, ::Collection
This method will eventually be replaced by #source which returns a Hyrax::Resource object. Many methods are equally able to process both Hyrax::Resource and ActiveFedora::Base. Only call this method if you need the ActiveFedora::Base object.
A bit of an analogue for a ‘belongs_to :source_model` as it crosses from Fedora to the DB
88 89 90 91 92 |
# File 'app/models/hyrax/permission_template.rb', line 88 def source_model ActiveFedora::Base.find(source_id) rescue ActiveFedora::ObjectNotFoundError raise Hyrax::ObjectNotFoundError end |
#valid_release_date?(date) ⇒ Boolean
Determines whether a given release date is valid based on this template’s requirements
156 157 158 159 |
# File 'app/models/hyrax/permission_template.rb', line 156 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
163 164 165 166 167 168 169 |
# File 'app/models/hyrax/permission_template.rb', line 163 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 |