From 38d4059bf2f301896c27fea83d635b496c218a0a Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Wed, 20 Dec 2023 19:30:33 +1100 Subject: [PATCH] fix: ensure we send indexing and eula details in viewer and submissions --- app/helpers/turn_it_in.rb | 2 ++ .../turn_it_in/tii_action_upload_submission.rb | 13 ++++++++++--- app/models/turn_it_in/user_tii_module.rb | 4 ++++ test/models/tii_model_test.rb | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/helpers/turn_it_in.rb b/app/helpers/turn_it_in.rb index fba7eb2d8..041ce9ae0 100644 --- a/app/helpers/turn_it_in.rb +++ b/app/helpers/turn_it_in.rb @@ -16,6 +16,8 @@ class TurnItIn def self.load_config(config) config.tii_enabled = ENV['TII_ENABLED'].present? && (ENV['TII_ENABLED'].to_s.downcase == "true" || ENV['TII_ENABLED'].to_i == 1) + config.tii_add_submissions_to_index = ENV['TII_INDEX_SUBMISSIONS'].present? && (ENV['TII_INDEX_SUBMISSIONS'].to_s.downcase == "true" || ENV['TII_INDEX_SUBMISSIONS'].to_i == 1) + if config.tii_enabled # Turn-it-in TII configuration require 'tca_client' diff --git a/app/models/turn_it_in/tii_action_upload_submission.rb b/app/models/turn_it_in/tii_action_upload_submission.rb index 716bd5a93..20b7d6c63 100644 --- a/app/models/turn_it_in/tii_action_upload_submission.rb +++ b/app/models/turn_it_in/tii_action_upload_submission.rb @@ -182,7 +182,7 @@ def fetch_tii_submission_id save_and_reschedule # If we had to indicate the eula was accepted, then we need to update the user - unless submitted_by_user.tii_eula_version_confirmed + unless submitted_by_user.eula_accepted_and_confirmed? submitted_by_user.confirm_eula_version(TurnItIn.eula_version, DateTime.now) end @@ -218,7 +218,7 @@ def tii_submission_data end # Add eula acceptance details to submission, if required - if submitted_by_user.accepted_tii_eula? && !submitted_by_user.tii_eula_version_confirmed + if submitted_by_user.accepted_tii_eula? && !submitted_by_user.eula_accepted_and_confirmed? result.eula = TCAClient::EulaAcceptRequest.new( user_id: submitted_by_user.username, language: 'en-us', @@ -299,11 +299,18 @@ def request_similarity_report ] exec_tca_call "TiiSubmission #{entity.id} - requesting similarity report", error_code do + add_to_index = Rails.env.production? && Doubtfire::Application.config.tii_add_submissions_to_index + data = TCAClient::SimilarityPutRequest.new( + indexing_settings: + TCAClient::IndexingSettings.new( + add_to_index: add_to_index, + ), generation_settings: TCAClient::SimilarityGenerationSettings.new( search_repositories: TiiActionFetchFeaturesEnabled.search_repositories, - auto_exclude_self_matching_scope: 'GROUP_CONTEXT' + auto_exclude_self_matching_scope: 'GROUP_CONTEXT', + priority: 'LOW' ) ) diff --git a/app/models/turn_it_in/user_tii_module.rb b/app/models/turn_it_in/user_tii_module.rb index 2867bf857..bb183f4f4 100644 --- a/app/models/turn_it_in/user_tii_module.rb +++ b/app/models/turn_it_in/user_tii_module.rb @@ -24,6 +24,10 @@ def accepted_tii_eula? tii_eula_version == TurnItIn.eula_version end + def eula_accepted_and_confirmed? + accepted_tii_eula? && tii_eula_version_confirmed + end + def confirm_eula_version(version, timestamp) update( tii_eula_version_confirmed: true, diff --git a/test/models/tii_model_test.rb b/test/models/tii_model_test.rb index dd41064e0..de7e14eef 100644 --- a/test/models/tii_model_test.rb +++ b/test/models/tii_model_test.rb @@ -395,7 +395,7 @@ def test_tii_process similarity_request = stub_request(:put, "https://#{ENV['TCA_HOST']}/api/v1/submissions/1223/similarity"). with(tii_headers). with( - body: "{\"generation_settings\":{\"search_repositories\":[\"INTERNET\",\"SUBMITTED_WORK\",\"PUBLICATION\",\"CROSSREF\",\"CROSSREF_POSTED_CONTENT\"],\"auto_exclude_self_matching_scope\":\"GROUP_CONTEXT\"}}", + body: "{\"indexing_settings\":{\"add_to_index\":false},\"generation_settings\":{\"search_repositories\":[\"INTERNET\",\"SUBMITTED_WORK\",\"PUBLICATION\",\"CROSSREF\",\"CROSSREF_POSTED_CONTENT\"],\"auto_exclude_self_matching_scope\":\"GROUP_CONTEXT\",\"priority\":\"LOW\"}}", ). to_return(status: 200, body: "", headers: {}) @@ -486,7 +486,7 @@ def test_tii_process similarity_request = stub_request(:put, "https://#{ENV['TCA_HOST']}/api/v1/submissions/1222/similarity"). with(tii_headers). with( - body: "{\"generation_settings\":{\"search_repositories\":[\"INTERNET\",\"SUBMITTED_WORK\",\"PUBLICATION\",\"CROSSREF\",\"CROSSREF_POSTED_CONTENT\"],\"auto_exclude_self_matching_scope\":\"GROUP_CONTEXT\"}}", + body: "{\"indexing_settings\":{\"add_to_index\":false},\"generation_settings\":{\"search_repositories\":[\"INTERNET\",\"SUBMITTED_WORK\",\"PUBLICATION\",\"CROSSREF\",\"CROSSREF_POSTED_CONTENT\"],\"auto_exclude_self_matching_scope\":\"GROUP_CONTEXT\",\"priority\":\"LOW\"}}", ). to_return(status: 200, body: "", headers: {})