Skip to content

Commit

Permalink
add feature tests for creating admin sets and collections
Browse files Browse the repository at this point in the history
Extended testing for admin sets:
* add feature tests for creating admin sets and collections

Changes in the controller test…
* specify more precisely failures redirects and flash messages
* test abilities of admin set collection type managers and creators to manipulate admin sets through the controller.

This extended testing confirms that abilities are sufficient to control access to admin sets.

Unexpected behaviors that are fixed in this PR:
* Admin sets were not copying over manager permissions.
* path `/admin/admin_sets` did not forward to `/dashboard/my/collections`

The behavioral changes these fixes impart were discussed in the tech call and approved by Hyrax PO.
  • Loading branch information
elrayle committed Sep 9, 2021
1 parent 7c2a2bf commit dbaec48
Show file tree
Hide file tree
Showing 8 changed files with 709 additions and 197 deletions.
21 changes: 2 additions & 19 deletions app/controllers/hyrax/admin/admin_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Admin::AdminSetsController < ApplicationController
include Hyrax::CollectionsControllerBehavior

before_action :authenticate_user!
before_action :ensure_manager!, except: [:show]
load_and_authorize_resource
before_action :ensure_viewer!, only: [:show]

# Catch permission errors
rescue_from Hydra::AccessDenied, CanCan::AccessDenied, with: :deny_adminset_access
Expand Down Expand Up @@ -43,10 +41,8 @@ def show
end

def index
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.admin_sets'), hyrax.admin_admin_sets_path
@admin_sets = Hyrax::AdminSetService.new(self).search_results(:edit)
# admin sets are listed with collections
redirect_to hyrax.my_collections_url
end

def new
Expand Down Expand Up @@ -106,19 +102,6 @@ def update_referer
hyrax.edit_admin_admin_set_path(@admin_set) + (params[:referer_anchor] || '')
end

def ensure_manager!
# TODO: Review for possible removal. Doesn't appear to apply anymore.
# Even though the user can view this admin set, they may not be able to view
# it on the admin page.
authorize! :manage_any, AdminSet
end

def ensure_viewer!
# Even though the user can view this admin set, they may not be able to view
# it on the admin page if access is granted as a public or registered user only.
authorize! :view_admin_show, @admin_set
end

def create_admin_set
admin_set_create_service.call(admin_set: @admin_set, creating_user: current_user)
end
Expand Down
17 changes: 16 additions & 1 deletion app/services/hyrax/admin_set_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ def access_grants_attributes
].tap do |attribute_list|
# Grant manage access to the creating_user if it exists. Should exist for all but default Admin Set
attribute_list << { agent_type: 'user', agent_id: creating_user.user_key, access: Hyrax::PermissionTemplateAccess::MANAGE } if creating_user
end + managers_of_admin_set
end

def managers_of_admin_set
admin_set_type = Hyrax::CollectionType.find_or_create_admin_set_type
attribute_list = []
user_managers = Hyrax::CollectionTypes::PermissionsService.user_edit_grants_for_collection_of_type(collection_type: admin_set_type)
user_managers.each do |user|
attribute_list << { agent_type: 'user', agent_id: user, access: Hyrax::PermissionTemplateAccess::MANAGE }
end
group_managers = Hyrax::CollectionTypes::PermissionsService.group_edit_grants_for_collection_of_type(collection_type: admin_set_type)
group_managers.each do |group|
attribute_list << { agent_type: 'group', agent_id: group, access: Hyrax::PermissionTemplateAccess::MANAGE }
end
attribute_list
end

def admin_group_name
Expand All @@ -84,7 +98,8 @@ def admin_group_name
##
# @return [PermissionTemplate]
def create_permission_template
permission_template = PermissionTemplate.create!(source_id: admin_set.id, access_grants_attributes: access_grants_attributes)
permission_template = PermissionTemplate.create!(source_id: admin_set.id,
access_grants_attributes: access_grants_attributes.uniq)
permission_template.reset_access_controls_for(collection: admin_set)
permission_template
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% @collection_type_list_presenter.each do |row_presenter| %>
<div class="radio radio-button-list">
<label>
<input type="radio" name="collection_type"
<input type="radio" name="collection_type" value="<%= row_presenter.title.gsub(/\s+/, '') %>"
<% if row_presenter.admin_set? %>
data-path="<%= new_admin_admin_set_path %>"
<% else %>
Expand Down
Loading

0 comments on commit dbaec48

Please sign in to comment.