From cd5adc170b65ba8798d4ba7e48a08732c0d7d09e Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Thu, 17 Mar 2022 14:55:14 -0500 Subject: [PATCH 1/3] Enable citations button in dassie test app --- .dassie/config/initializers/hyrax.rb | 1 + 1 file changed, 1 insertion(+) 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| From f04e5fdba1992f105323376e84ccad5cb0fed7cc Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Thu, 17 Mar 2022 15:00:49 -0500 Subject: [PATCH 2/3] Remove SingularSubresourceController concern from CitationsController to enable citations for Valkyrie resources --- app/controllers/hyrax/citations_controller.rb | 1 - .../hyrax/citations_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/hyrax/citations_controller.rb b/app/controllers/hyrax/citations_controller.rb index a82d620aa2..f25a43fd8a 100644 --- a/app/controllers/hyrax/citations_controller.rb +++ b/app/controllers/hyrax/citations_controller.rb @@ -3,7 +3,6 @@ module Hyrax class CitationsController < ApplicationController include WorksControllerBehavior 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..a9a9f00996 100644 --- a/spec/controllers/hyrax/citations_controller_spec.rb +++ b/spec/controllers/hyrax/citations_controller_spec.rb @@ -29,6 +29,22 @@ 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) } From 549b1f0268a4217951a109b0a8e7ad09019f8909 Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Fri, 18 Mar 2022 11:09:06 -0500 Subject: [PATCH 3/3] Redirect to home page when user unauthorized --- app/controllers/hyrax/citations_controller.rb | 1 + .../hyrax/citations_controller_spec.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/hyrax/citations_controller.rb b/app/controllers/hyrax/citations_controller.rb index f25a43fd8a..ad1e02f081 100644 --- a/app/controllers/hyrax/citations_controller.rb +++ b/app/controllers/hyrax/citations_controller.rb @@ -2,6 +2,7 @@ module Hyrax class CitationsController < ApplicationController include WorksControllerBehavior + include DenyAccessOverrideBehavior include Breadcrumbs # Overrides decide_layout from WorksControllerBehavior diff --git a/spec/controllers/hyrax/citations_controller_spec.rb b/spec/controllers/hyrax/citations_controller_spec.rb index a9a9f00996..9828184a0f 100644 --- a/spec/controllers/hyrax/citations_controller_spec.rb +++ b/spec/controllers/hyrax/citations_controller_spec.rb @@ -22,7 +22,21 @@ 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."