From 31fdc56e011fc6fd39a860da33064167198823de Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 23 Jan 2025 10:10:51 +0000 Subject: [PATCH] Add a change note step This allows the user to select if the change was major and add a change note if it was. --- .../concerns/workflow/show_methods.rb | 13 +++- .../concerns/workflow/update_methods.rb | 13 ++++ .../content_block_manager/base_controller.rb | 2 + .../editions/workflow/change_note.html.erb | 67 +++++++++++++++++++ .../features/edit_object.feature | 9 ++- .../features/reschedule_object.feature | 5 ++ .../features/schedule_object.feature | 5 ++ .../content_block_manager_steps.rb | 12 ++++ .../content_block/workflow_test.rb | 54 +++++++++++++++ 9 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb diff --git a/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb b/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb index 3eabfa24c86..015dab89f52 100644 --- a/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb +++ b/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb @@ -6,6 +6,7 @@ module Workflow::ShowMethods review_links: :review_links, schedule_publishing: :schedule_publishing, internal_note: :internal_note, + change_note: :change_note, review: :review, review_update: :review_update, confirmation: :confirmation, @@ -51,13 +52,23 @@ def internal_note render :internal_note end + def change_note + @content_block_document = @content_block_edition.document + @back_path = content_block_manager.content_block_manager_content_block_workflow_path( + @content_block_edition, + step: :internal_note, + ) + + render :change_note + end + def review_update @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id]) @url = review_update_url @back_path = content_block_manager.content_block_manager_content_block_workflow_path( @content_block_edition, - step: :internal_note, + step: :change_note, ) render :review diff --git a/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb b/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb index 02909143a40..f1bf0af07de 100644 --- a/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb +++ b/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb @@ -7,6 +7,7 @@ module Workflow::UpdateMethods review_links: :redirect_to_schedule, schedule_publishing: :validate_schedule, internal_note: :update_internal_note, + change_note: :update_change_note, review_update: :validate_review_page, review: :validate_review_page, }.freeze @@ -34,10 +35,22 @@ def validate_schedule def update_internal_note @content_block_edition.update!(internal_change_note: edition_params[:internal_change_note]) + redirect_to content_block_manager.content_block_manager_content_block_workflow_path( + id: @content_block_edition.id, + step: :change_note, + ) + end + + def update_change_note + @content_block_edition.assign_attributes(change_note: edition_params[:change_note], major_change: edition_params[:major_change]) + @content_block_edition.save!(context: :change_note) + redirect_to content_block_manager.content_block_manager_content_block_workflow_path( id: @content_block_edition.id, step: :review_update, ) + rescue ActiveRecord::RecordInvalid + render :change_note end def validate_review_page diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb index 66288fab446..248859b8de6 100644 --- a/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb +++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb @@ -27,6 +27,8 @@ def edition_params "scheduled_publication(5i)", :title, :internal_change_note, + :change_note, + :major_change, document_attributes: %w[block_type], details: @schema.permitted_params, ) diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb new file mode 100644 index 00000000000..ed6c8389a72 --- /dev/null +++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb @@ -0,0 +1,67 @@ +<% content_for :context, context %> +<% content_for :title, "Do users have to know the content has changed?" %> +<% content_for :title_margin_bottom, 4 %> +<% content_for :back_link do %> + <%= render "govuk_publishing_components/components/back_link", { + href: @back_path, + } %> +<% end %> + +<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @content_block_edition)) %> + +
+
+ <%= form_with url: content_block_manager.content_block_manager_content_block_workflow_path( + @content_block_edition, + step: :change_note, + ), method: :put do %> + + <%= render "govuk_publishing_components/components/radio", { + name: "content_block/edition[major_change]", + id: "content_block_manager_content_block_edition_major_change", + error_items: errors_for(@content_block_edition.errors, :major_change), + items: [ + { + value: "1", + checked: @content_block_edition.major_change === true, + text: "Yes - information has been added, updated or removed", + hint_text: "A change note will be published on the page and emailed to users subscribed to email alerts. The 'last updated' date will change.", + bold: true, + conditional: render("govuk_publishing_components/components/textarea", { + label: { + text: "Describe the edit for users", + }, + name: "content_block/edition[change_note]", + id: "content_block_manager_content_block_edition_change_note", + error_items: errors_for(@content_block_edition.errors, :change_note), + value: @content_block_edition.change_note, + hint: (tag.p('Tell users what has changed, where and why. Write in full sentences, leading with the most important words. For example, "College A has been removed from the registered sponsors list because its licence has been suspended."', class: "govuk-!-margin-bottom-0 govuk-!-margin-top-0") + + link_to("Guidance about change notes (opens in a new tab)", "https://www.gov.uk/guidance/content-design/writing-for-gov-uk#change-notes", target: "_blank", class: "govuk-link", rel: "noopener")).html_safe, + }), + }, + { + value: "0", + checked: @content_block_edition.major_change === false, + text: "No - it's a minor edit that does not change the meaning", + hint_text: "This includes fixing a typo or broken link, a style change or similar. Users signed up to email alerts will not get notified and the 'last updated' date will not change.", + bold: true, + }, + ], + } %> + +
+ <%= render "govuk_publishing_components/components/button", { + text: "Save and continue", + name: "save_and_continue", + value: "Save and continue", + type: "submit", + } %> + <%= render "govuk_publishing_components/components/button", { + text: "Cancel", + href: @back_path, + secondary_solid: true, + } %> +
+ <% end %> +
+
diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature index dc4282e4612..ad9e0ff7375 100644 --- a/lib/engines/content_block_manager/features/edit_object.feature +++ b/lib/engines/content_block_manager/features/edit_object.feature @@ -24,8 +24,11 @@ Feature: Edit a content object Then I should be on the "internal_note" step And I should see a back link to the "schedule_publishing" step When I add an internal note - Then I should be on the "review" step + Then I should be on the "change_note" step And I should see a back link to the "internal_note" step + When I add a change note + Then I should be on the "review" step + And I should see a back link to the "change_note" step When I review and confirm my answers are correct Then I should be taken to the confirmation page for a published block When I click to view the content block @@ -60,6 +63,7 @@ Feature: Edit a content object And I continue after reviewing the links When I choose to publish the change now And I add an internal note + And I add a change note When I click cancel Then I am taken back to Content Block Manager home page And no draft Content Block Edition has been created @@ -96,6 +100,7 @@ Feature: Edit a content object And I continue after reviewing the links And I choose to publish the change now And I add an internal note + And I add a change note Then I am asked to review my answers When I click publish without confirming my details Then I should see a message that I need to confirm the details are correct @@ -105,12 +110,14 @@ Feature: Edit a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I revisit the edit page Then I should see a warning telling me there is a scheduled change When I make the changes And I choose to publish the change now And I add an internal note + And I add a change note When I review and confirm my answers are correct Then I should be taken to the confirmation page for a published block When I click to view the content block diff --git a/lib/engines/content_block_manager/features/reschedule_object.feature b/lib/engines/content_block_manager/features/reschedule_object.feature index a5e6c7cbba9..5d5843b1569 100644 --- a/lib/engines/content_block_manager/features/reschedule_object.feature +++ b/lib/engines/content_block_manager/features/reschedule_object.feature @@ -12,6 +12,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I click to view the content block And I click to edit the schedule @@ -26,6 +27,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I click to view the content block And I click to edit the schedule @@ -40,6 +42,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I click to view the content block And I click to edit the schedule @@ -51,6 +54,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I click to view the content block And I click to edit the schedule @@ -63,6 +67,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I click to view the content block And I click to edit the schedule diff --git a/lib/engines/content_block_manager/features/schedule_object.feature b/lib/engines/content_block_manager/features/schedule_object.feature index 045cf05c6bb..a8bd7072442 100644 --- a/lib/engines/content_block_manager/features/schedule_object.feature +++ b/lib/engines/content_block_manager/features/schedule_object.feature @@ -12,6 +12,7 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct And I should be taken to the scheduled confirmation page When I click to view the content block @@ -23,10 +24,12 @@ Feature: Schedule a content object When I am updating a content block And I schedule the change for 7 days in the future And I add an internal note + And I add a change note When I review and confirm my answers are correct When I am updating a content block And I choose to publish the change now And I save and continue + And I add a change note When I review and confirm my answers are correct Then there should be no jobs scheduled @@ -35,6 +38,7 @@ Feature: Schedule a content object When I choose to schedule the change And the block is scheduled and published And I add an internal note + And I add a change note When I review and confirm my answers are correct Then the published state of the object should be shown And I should see the publish event on the timeline @@ -64,5 +68,6 @@ Feature: Schedule a content object When I choose to schedule the change And the block is scheduled and published And I add an internal note + And I add a change note And I click cancel Then I am taken back to Content Block Manager home page diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index f9ef48a4e2b..292f4b3571b 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -747,6 +747,12 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ click_save_and_continue end +When(/^I add a change note$/) do + choose "Yes - information has been added, updated or removed" + fill_in "Describe the edit for users", with: "Some text" + click_save_and_continue +end + def visit_edit_page visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) end @@ -867,6 +873,8 @@ def click_save_and_continue should_show_publish_form when "review" should_be_on_review_step + when "change_note" + should_be_on_change_note_step end end @@ -921,3 +929,7 @@ def should_show_publish_form def should_be_on_review_step assert_text "Review email address" end + +def should_be_on_change_note_step + assert_text "Do users have to know the content has changed?" +end diff --git a/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb b/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb index 9fc69bc1423..bb0b55f46a2 100644 --- a/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb +++ b/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb @@ -168,8 +168,62 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat assert_equal edition.reload.internal_change_note, change_note + assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :change_note) + end + end + end + + describe "when updating the change note" do + let(:step) { :change_note } + + describe "#show" do + it "shows the form" do + get content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:) + + assert_template "content_block_manager/content_block/editions/workflow/change_note" + end + end + + describe "#update" do + it "adds the note and redirects" do + change_note = "This is my note" + put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:), + params: { + "content_block/edition" => { + "major_change" => "1", + "change_note" => change_note, + }, + } + + assert_equal edition.reload.change_note, change_note + assert_equal edition.reload.major_change, true + assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_update) end + + it "shows an error if the change is major and the change note is blank" do + put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:), + params: { + "content_block/edition" => { + "major_change" => "1", + "change_note" => "", + }, + } + + assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.blank', attribute: 'Change note')}/, response.body) + end + + it "shows an error if major_change is blank" do + put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:), + params: { + "content_block/edition" => { + "major_change" => "", + "change_note" => "", + }, + } + + assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.attributes.major_change.inclusion')}/, response.body) + end end end end