Class: Hyrax::Collections::PermissionsService
- Inherits:
-
Object
- Object
- Hyrax::Collections::PermissionsService
- Defined in:
- app/services/hyrax/collections/permissions_service.rb
Overview
rubocop:disable Metrics/ClassLength
Class Method Summary collapse
-
.can_deposit_in_collection?(collection_id:, ability:) ⇒ Boolean
Determine if the given user has permissions to deposit into the given collection.
-
.can_manage_any_admin_set?(ability:) ⇒ Boolean
Determine if the given user has permissions to manage at least one admin set.
-
.can_manage_any_collection?(ability:) ⇒ Boolean
Determine if the given user has permissions to manage at least one collection.
-
.can_view_admin_show_for_any_admin_set?(ability:) ⇒ Boolean
Determine if the given user has permissions to view the admin show page for at least one admin set.
-
.can_view_admin_show_for_any_collection?(ability:) ⇒ Boolean
Determine if the given user has permissions to view the admin show page for at least one collection.
-
.can_view_admin_show_for_collection?(collection_id:, ability:) ⇒ Boolean
Determine if the given user has permissions to view the admin show page for the collection.
-
.collection_ids_for_deposit(ability:) ⇒ Array<String>
IDs of collections into which a user can deposit.
-
.collection_ids_for_user(access:, ability:) ⇒ Array<String>
IDs of collections a user can access based on participant roles.
-
.collection_ids_for_view(ability:) ⇒ Array<String>
IDs of collections which the user can view.
-
.manage_access_to_collection?(collection_id:, ability:, exclude_groups: []) ⇒ Boolean
Determine if the given user has :manage access for the given collection.
-
.source_ids_for_deposit(ability:, source_type: nil, exclude_groups: []) ⇒ Array<String>
IDs of collections and/or admin_sets into which a user can deposit.
-
.source_ids_for_manage(ability:, source_type: nil) ⇒ Array<String>
IDs of collections and/or admin_sets that a user can manage.
Class Method Details
.can_deposit_in_collection?(collection_id:, ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to deposit into the given collection
189 190 191 192 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 189 def self.can_deposit_in_collection?(collection_id:, ability:) deposit_access_to_collection?(collection_id: collection_id, ability: ability) || manage_access_to_collection?(collection_id: collection_id, ability: ability) end |
.can_manage_any_admin_set?(ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to manage at least one admin set
TODO: MOVE TO ABILITY
177 178 179 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 177 def self.can_manage_any_admin_set?(ability:) admin_set_ids_for_user(ability: ability, access: [Hyrax::PermissionTemplateAccess::MANAGE]).present? end |
.can_manage_any_collection?(ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to manage at least one collection
164 165 166 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 164 def self.can_manage_any_collection?(ability:) collection_ids_for_user(ability: ability, access: [Hyrax::PermissionTemplateAccess::MANAGE]).present? end |
.can_view_admin_show_for_any_admin_set?(ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to view the admin show page for at least one admin set
TODO: MOVE TO ABILITY
151 152 153 154 155 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 151 def self.can_view_admin_show_for_any_admin_set?(ability:) admin_set_ids_for_user(ability: ability, access: [Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::DEPOSIT, Hyrax::PermissionTemplateAccess::VIEW]).present? end |
.can_view_admin_show_for_any_collection?(ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to view the admin show page for at least one collection
137 138 139 140 141 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 137 def self.can_view_admin_show_for_any_collection?(ability:) collection_ids_for_user(ability: ability, access: [Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::DEPOSIT, Hyrax::PermissionTemplateAccess::VIEW]).present? end |
.can_view_admin_show_for_collection?(collection_id:, ability:) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has permissions to view the admin show page for the collection
202 203 204 205 206 207 208 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 202 def self.can_view_admin_show_for_collection?(collection_id:, ability:) exclude_groups = [::Ability.registered_group_name, ::Ability.public_group_name] manage_access_to_collection?(collection_id: collection_id, ability: ability) || deposit_access_to_collection?(collection_id: collection_id, ability: ability, exclude_groups: exclude_groups) || view_access_to_collection?(collection_id: collection_id, ability: ability, exclude_groups: exclude_groups) end |
.collection_ids_for_deposit(ability:) ⇒ Array<String>
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
IDs of collections into which a user can deposit.
113 114 115 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 113 def self.collection_ids_for_deposit(ability:) source_ids_for_deposit(ability: ability, source_type: 'collection') end |
.collection_ids_for_user(access:, ability:) ⇒ Array<String>
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
IDs of collections a user can access based on participant roles.
75 76 77 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 75 def self.collection_ids_for_user(access:, ability:) source_ids_for_user(access: access, ability: ability, source_type: 'collection') end |
.collection_ids_for_view(ability:) ⇒ Array<String>
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
IDs of collections which the user can view.
124 125 126 127 128 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 124 def self.collection_ids_for_view(ability:) collection_ids_for_user(ability: ability, access: [Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::DEPOSIT, Hyrax::PermissionTemplateAccess::VIEW]) end |
.manage_access_to_collection?(collection_id:, ability:, exclude_groups: []) ⇒ Boolean
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
Determine if the given user has :manage access for the given collection
233 234 235 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 233 def self.manage_access_to_collection?(collection_id:, ability:, exclude_groups: []) access_to_collection?(collection_id: collection_id, access: 'manage', ability: ability, exclude_groups: exclude_groups) end |
.source_ids_for_deposit(ability:, source_type: nil, exclude_groups: []) ⇒ Array<String>
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
IDs of collections and/or admin_sets into which a user can deposit.
88 89 90 91 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 88 def self.source_ids_for_deposit(ability:, source_type: nil, exclude_groups: []) access = [Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::DEPOSIT] source_ids_for_user(access: access, ability: ability, source_type: source_type, exclude_groups: exclude_groups) end |
.source_ids_for_manage(ability:, source_type: nil) ⇒ Array<String>
Several checks get the user’s groups from the user’s ability. The same values can be retrieved directly from a passed in ability.
IDs of collections and/or admin_sets that a user can manage.
101 102 103 104 |
# File 'app/services/hyrax/collections/permissions_service.rb', line 101 def self.source_ids_for_manage(ability:, source_type: nil) access = [Hyrax::PermissionTemplateAccess::MANAGE, Hyrax::PermissionTemplateAccess::MANAGE] source_ids_for_user(access: access, ability: ability, source_type: source_type) end |