Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Full-Text Search Indexing button to works' show page. #2189

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/assets/stylesheets/_work_show_page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.second-row-buttons {
form {padding-left: 0.5rem;}
display: inline-flex;
margin: 0;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/curate.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import 'search_results';
@import 'archivesspace_button';
@import 'work_show_page';

.ui-autocomplete-loading {
background: #fff url("/assets/loading.gif") right center no-repeat;
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/full_text_indexing_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class FullTextIndexingController < ApplicationController
before_action :authenticate_user!

def full_text_index
CompileFullTextJob.perform_later(work_id: params[:work_id], user_id: params[:user_id].to_i)
redirect_to hyrax_curate_generic_work_path(params[:work_id]), notice: "Full-Text Indexing has been queued for this work."
end
end
5 changes: 4 additions & 1 deletion app/views/hyrax/base/_show_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
<% end %>
<% if current_user.admin? %>
<%= link_to t('.delete'), [main_app, presenter], class: 'btn btn-danger', data: { confirm: t('.confirm_delete', work_type: presenter.human_readable_type) }, method: :delete %>
<div><%= button_to t('.regen_manifest'), "/concern/curate_generic_works/#{@presenter.id}/regen_manifest", class: 'btn btn-primary' %></div>
<div class="row second-row-buttons">
<%= button_to t('.regen_manifest'), "/concern/curate_generic_works/#{@presenter.id}/regen_manifest", class: 'btn btn-primary' %>
<%= button_to 'Index for Full-Text Search', "/concern/curate_generic_works/#{@presenter.id}/full_text_index?user_id=#{current_user.id}", class: 'btn btn-primary' %>
</div>
<% end %>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
post "/concern/file_sets/:file_set_id/clean_up", to: "derivatives#clean_up"
post '/concern/file_sets/:file_set_id/re_characterize', to: 'characterization#re_characterize', as: 'file_set_re_characterization'
post "/concern/curate_generic_works/:work_id/regen_manifest", to: "manifest_regeneration#regen_manifest", as: 'regen_manifest'
post "/concern/curate_generic_works/:work_id/full_text_index", to: "full_text_indexing#full_text_index", as: 'full_text_index'

# Deprecation warning: Zizia will be removed with Curate v3.
get 'csv_import_details/index'
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/full_text_indexing_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe FullTextIndexingController, type: :controller, clean: true do
let(:admin) { FactoryBot.create(:admin) }
let(:work) { FactoryBot.create(:public_generic_work, user: admin) }

context "when signed in" do
describe "POST full_text_index" do
before do
sign_in admin
end

it "queues up compile full text job" do
expect(CompileFullTextJob).to receive(:perform_later).with(work_id: work.id, user_id: admin.id)
post :full_text_index, params: { work_id: work.id, user_id: admin.id }, xhr: true
expect(response).to be_successful
end
end
end

context "when not signed in" do
describe "POST full_text_index" do
it "returns 401" do
post :full_text_index, params: { work_id: work.id, user_id: admin.id }, xhr: true
expect(response.code).to eq '401'
end
end
end
end
15 changes: 15 additions & 0 deletions spec/routing/full_text_indexing_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "routes for full-text indexing", type: :routing do
it "routes full-text indexing requests to the full_text_indexing#full_text_index controller" do
expect(post("/concern/curate_generic_works/1/full_text_index?user_id=1"))
.to route_to(
"controller" => "full_text_indexing",
"action" => "full_text_index",
"work_id" => "1",
"user_id" => "1"
)
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
require 'coveralls'
require 'active_fedora/cleaner'
require 'webmock/rspec'
require 'webdrivers/chromedriver'

WebMock.disable_net_connect!(allow: [
'127.0.0.1',
'chromedriver.storage.googleapis.com',
'id.loc.gov'
],
net_http_connect_on_start: true)
Coveralls.wear!('rails')
Webdrivers::Chromedriver.required_version = "114.0.5735.90" unless ENV['CI']
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down
10 changes: 10 additions & 0 deletions spec/system/viewing_a_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
expect(page).to have_selector("input[value='delete_all']", visible: false)
expect(page).to have_css('button', text: 'Add to collection')
end

it 'has a full-text search indexing button' do
visit "/concern/curate_generic_works/#{user_work.id}"
expect(page).to have_selector('input[value="Index for Full-Text Search"]')
end
end

context 'when logged in as a non-admin user' do
Expand Down Expand Up @@ -177,6 +182,11 @@
expect(page).not_to have_css('button', text: 'Add to collection')
end

it 'does not have a full-text search indexing button' do
visit "/concern/curate_generic_works/#{user_work.id}"
expect(page).not_to have_selector('input[value="Index for Full-Text Search"]')
end

context 'viewer role' do
let(:user) do
User.create(
Expand Down