Class: Hyrax::EditPermissionsService
- Inherits:
-
Object
- Object
- Hyrax::EditPermissionsService
- Defined in:
- app/services/hyrax/edit_permissions_service.rb
Overview
Encapsulates the logic to determine which object permissions may be edited by a given user
- user is permitted to update any work permissions coming ONLY from collections they manage
- user is not permitted to update a work permission if it comes from a collection they do not manage, even if also from a managed collection
- user is permitted to update only non-manager permissions from any Collections
- user is permitted to update any non-collection permissions
Defined Under Namespace
Classes: BlockedPermissions, PermissionPresenter
Instance Attribute Summary collapse
-
#depositor ⇒ Object
readonly
Returns the value of attribute depositor.
-
#unauthorized_collection_managers ⇒ Object
readonly
Returns the value of attribute unauthorized_collection_managers.
Class Method Summary collapse
Instance Method Summary collapse
-
#cannot_edit_permissions?(permission_hash) ⇒ Boolean
private
True if user cannot edit the given permissions.
-
#excluded_permission?(permission_hash) ⇒ Boolean
private
True if given permissions are one of fixed exclusions.
-
#initialize(object:, ability:) ⇒ EditPermissionsService
constructor
A new instance of EditPermissionsService.
-
#with_applicable_permission(permission_hash:) { ... } ⇒ Object
This method either:.
Constructor Details
#initialize(object:, ability:) ⇒ EditPermissionsService
Returns a new instance of EditPermissionsService.
38 39 40 41 42 43 44 45 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 38 def initialize(object:, ability:) @object = object @ability = ability @depositor = object.depositor = @unauthorized_managers = . @unauthorized_collection_managers = . end |
Instance Attribute Details
#depositor ⇒ Object (readonly)
Returns the value of attribute depositor.
34 35 36 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 34 def depositor @depositor end |
#unauthorized_collection_managers ⇒ Object (readonly)
Returns the value of attribute unauthorized_collection_managers.
34 35 36 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 34 def @unauthorized_collection_managers end |
Class Method Details
.build_service_object_from(form:, ability:) ⇒ Hyrax::EditPermissionService
form object.class = SimpleForm::FormBuilder
For works (i.e. GenericWork):
- form object.object = Hyrax::GenericWorkForm
- form object.object.model = GenericWork
- use the work itself
For file_sets:
- form object.object.class = FileSet
- use work the file_set is in
No other object types are supported by this view. %>
26 27 28 29 30 31 32 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 26 def self.build_service_object_from(form:, ability:) if form.object.respond_to?(:model) && form.object.model.work? new(object: form.object, ability: ability) elsif form.object.file_set? new(object: form.object.in_works.first, ability: ability) end end |
Instance Method Details
#cannot_edit_permissions?(permission_hash) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
refactor this code to use “can_edit?”; Thinking in negations can be challenging.
Returns true if user cannot edit the given permissions.
52 53 54 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 52 def () .fetch(:access) == "edit" && @unauthorized_managers.include?(.fetch(:name)) end |
#excluded_permission?(permission_hash) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if given permissions are one of fixed exclusions.
60 61 62 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 60 def () exclude_from_display.include? .fetch(:name).downcase end |
#with_applicable_permission(permission_hash:) { ... } ⇒ Object
This method either:
-
returns false if the given permission_hash is part of the fixed exclusions.
-
yields a PermissionPresenter to provide additional logic and text for rendering
76 77 78 79 |
# File 'app/services/hyrax/edit_permissions_service.rb', line 76 def (permission_hash:) return false if () yield(PermissionPresenter.new(service: self, permission_hash: )) end |