diff --git a/.dassie/config/initializers/hyrax.rb b/.dassie/config/initializers/hyrax.rb index 733fc63a99..51b5629d27 100644 --- a/.dassie/config/initializers/hyrax.rb +++ b/.dassie/config/initializers/hyrax.rb @@ -16,6 +16,7 @@ config.iiif_image_server = true config.work_requires_files = false + config.citations = true # Returns a URL that resolves to an image provided by a IIIF image server config.iiif_image_url_builder = lambda do |file_id, base_url, size, format| diff --git a/app/controllers/hyrax/citations_controller.rb b/app/controllers/hyrax/citations_controller.rb index a82d620aa2..ad1e02f081 100644 --- a/app/controllers/hyrax/citations_controller.rb +++ b/app/controllers/hyrax/citations_controller.rb @@ -2,8 +2,8 @@ module Hyrax class CitationsController < ApplicationController include WorksControllerBehavior + include DenyAccessOverrideBehavior include Breadcrumbs - include SingularSubresourceController # Overrides decide_layout from WorksControllerBehavior with_themed_layout '1_column' diff --git a/spec/controllers/hyrax/citations_controller_spec.rb b/spec/controllers/hyrax/citations_controller_spec.rb index 7c9448a26f..9828184a0f 100644 --- a/spec/controllers/hyrax/citations_controller_spec.rb +++ b/spec/controllers/hyrax/citations_controller_spec.rb @@ -22,13 +22,43 @@ end context "with an unauthenticated user" do - it "is not successful" do + let(:second_user) { FactoryBot.create(:user) } + + before do + sign_in second_user + end + + it "redirects to the home page" do + get :work, params: { id: work } + expect(response).to redirect_to main_app.root_path(locale: 'en') + expect(flash[:alert]).to eq "You are not authorized to access this page." + end + end + + context "when a user is not logged in" do + it "redirects to the user login page" do get :work, params: { id: work } expect(response).to redirect_to main_app.new_user_session_path(locale: 'en') expect(flash[:alert]).to eq "You are not authorized to access this page." expect(session['user_return_to']).to eq request.url end end + + context "with a Valkyrie resource" do + let(:work) { FactoryBot.valkyrie_create(:monograph, edit_users: [user]) } + before do + sign_in user + end + + it "is successful" do + expect(controller).to receive(:add_breadcrumb).with('Home', Hyrax::Engine.routes.url_helpers.root_path(locale: 'en')) + expect(controller).to receive(:add_breadcrumb).with('Dashboard', Hyrax::Engine.routes.url_helpers.dashboard_path(locale: 'en')) + get :work, params: { id: work } + expect(response).to be_successful + expect(response).to render_template('layouts/hyrax/1_column') + expect(assigns(:presenter)).to be_kind_of Hyrax::WorkShowPresenter + end + end end describe "#file" do let(:user) { create(:user) }