From 69231a015cee59d5e69f7f937da54773ffda55e8 Mon Sep 17 00:00:00 2001 From: Ben Pennell Date: Thu, 26 Oct 2023 17:13:06 -0400 Subject: [PATCH] Add a test for WorksControllerBehavior override to ensure that admins get exempted from visibility restrictions --- .../hyrax/works_controller_behavior_spec.rb | 65 +++++++++++++++++++ spec/factories/permission_templates.rb | 16 +++++ 2 files changed, 81 insertions(+) create mode 100644 spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb diff --git a/spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb b/spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb new file mode 100644 index 000000000..f0306e02a --- /dev/null +++ b/spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.describe Hyrax::WorksControllerBehavior, type: :controller do + let(:paths) { controller.main_app } + + controller(ApplicationController) do + include Hyrax::WorksControllerBehavior # rubocop:disable RSpec/DescribedClass + + self.curation_concern_type = General + end + + describe '#available_admin_sets' do + context 'with a logged in user' do + before { sign_in user } + + context 'admin set limited to public and no embargoes' do + let(:admin_set) { Hyrax::AdminSetCreateService.find_or_create_default_admin_set } + + let!(:permission_template) do + FactoryBot.create(:permission_template, + source_id: admin_set.id, + release_period: Hyrax::PermissionTemplate::RELEASE_TEXT_VALUE_NO_DELAY) + end + + let!(:permission_template_access) do + FactoryBot.create(:permission_template_access, + :deposit, + permission_template: permission_template, + agent_type: 'user', + agent_id: user.user_key) + end + + let!(:workflow) do + Sipity::Workflow.create(name: 'test', allows_access_grant: true, active: true, + permission_template_id: permission_template.id) + end + + context 'as a regular user' do + let(:user) { FactoryBot.create(:user) } + + it 'populates allowed admin sets with configured visibility restrictions' do + admin_sets = controller.available_admin_sets + options = admin_sets.select_options + + expect(options).to contain_exactly( + ['Default Admin Set', admin_set.id.to_s, {'data-release-no-delay'=>true, 'data-sharing'=>true}]) + end + end + + context 'as an admin user' do + let(:user) { FactoryBot.create(:admin) } + + it 'populates allowed admin sets without visibility restrictions' do + admin_sets = controller.available_admin_sets + options = admin_sets.select_options + + expect(options).to contain_exactly( + ['Default Admin Set', admin_set.id.to_s, {'data-sharing'=>true}]) + end + end + end + end + end +end diff --git a/spec/factories/permission_templates.rb b/spec/factories/permission_templates.rb index b038aebf4..b2ab6d93e 100644 --- a/spec/factories/permission_templates.rb +++ b/spec/factories/permission_templates.rb @@ -66,6 +66,22 @@ view_groups { nil } end end + + factory :permission_template_access, class: Hyrax::PermissionTemplateAccess do + permission_template + trait :manage do + access { 'manage' } + end + + trait :deposit do + access { 'deposit' } + end + + trait :view do + access { 'view' } + end + end + # rubocop:disable Lint/ConstantDefinitionInBlock class AccessHelper def self.create_access(permission_template_id, agent_type, access, agent_ids)