From e8bb682f76dac2690a918adbee6a534feba171e3 Mon Sep 17 00:00:00 2001 From: Piet Schijven Date: Fri, 13 Oct 2023 10:45:36 +0200 Subject: [PATCH] We now only allow consistent concepts and collections to be sent for review. --- .../collections/versions_controller.rb | 15 +++++++++++---- app/controllers/concepts/versions_controller.rb | 15 +++++++++++---- test/integration/create_concept_test.rb | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/controllers/collections/versions_controller.rb b/app/controllers/collections/versions_controller.rb index 5d462983f..4f0769d31 100644 --- a/app/controllers/collections/versions_controller.rb +++ b/app/controllers/collections/versions_controller.rb @@ -95,10 +95,17 @@ def to_review last! authorize! :send_to_review, collection - collection.to_review - collection.save! - flash[:success] = t('txt.controllers.versioning.to_review_success') - redirect_to collection_path(collection, published: 0) + # Only send the concept to review if it is publishable (e.g. consistency check is OK) + if collection.publishable? + collection.to_review + + collection.save! + flash[:success] = t('txt.controllers.versioning.to_review_success') + redirect_to collection_path(collection, published: 0) + else + flash[:error] = t('txt.controllers.versioning.consistency_check_error') + redirect_to edit_collection_path(collection, published: 0, full_consistency_check: '1') + end end end diff --git a/app/controllers/concepts/versions_controller.rb b/app/controllers/concepts/versions_controller.rb index f3f17bb09..4641a95d6 100644 --- a/app/controllers/concepts/versions_controller.rb +++ b/app/controllers/concepts/versions_controller.rb @@ -109,10 +109,17 @@ def to_review last! authorize! :send_to_review, concept - concept.to_review - concept.save! - flash[:success] = t('txt.controllers.versioning.to_review_success') - redirect_to concept_path(published: 0, id: concept) + # Only send the concept to review if it is publishable (e.g. consistency check is OK) + if concept.publishable? + concept.to_review + concept.save! + + flash[:success] = t('txt.controllers.versioning.to_review_success') + redirect_to concept_path(published: 0, id: concept) + else + flash[:error] = t('txt.controllers.versioning.consistency_check_error') + redirect_to concept_path(published: 0, id: concept, full_consistency_check: '1') + end end end diff --git a/test/integration/create_concept_test.rb b/test/integration/create_concept_test.rb index 96222120d..5802f8998 100644 --- a/test/integration/create_concept_test.rb +++ b/test/integration/create_concept_test.rb @@ -30,6 +30,21 @@ class CreateConceptTest < ActionDispatch::IntegrationTest save_check_and_publish end + test 'send to review with inconsistent concept' do + login('administrator') + visit dashboard_path(lang: 'en') + click_link_or_button 'New Concept' + + # Create invalid preflabel + fill_in 'concept_labelings_by_text_labeling_skos_pref_labels_en', with: 'Foo,Foo' + click_link_or_button 'Save' + + # Consistency check should run when sending the concept to review. + click_link_or_button 'Send to review' + assert page.has_content? 'Instance is inconsistent.' + assert page.has_content? 'There must be only one preferred Label per language.' + end + private def save_check_and_publish