diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb
index da44874c2..ce82ad98a 100644
--- a/app/controllers/editions_controller.rb
+++ b/app/controllers/editions_controller.rb
@@ -159,6 +159,10 @@ def add_edition_note
render "secondary_nav_tabs/add_edition_note"
end
+ def update_important_note
+ render "secondary_nav_tabs/update_important_note"
+ end
+
def destroy
@resource.destroy!
flash[:success] = "Edition deleted"
diff --git a/app/views/editions/_important_note.html.erb b/app/views/editions/_important_note.html.erb
new file mode 100644
index 000000000..c15ba82c0
--- /dev/null
+++ b/app/views/editions/_important_note.html.erb
@@ -0,0 +1,6 @@
+<%= render "govuk_publishing_components/components/notice", {
+ description_govspeak: sanitize("
#{h(User.find_by(id: @edition.important_note&.requester_id)&.name)} added an important note on
+ #{h(@edition.important_note&.created_at&.strftime("%d %B %Y"))}
"),
+ show_banner_title: true
+} %>
\ No newline at end of file
diff --git a/app/views/editions/secondary_nav_tabs/_history.html.erb b/app/views/editions/secondary_nav_tabs/_history.html.erb
index 7344df759..301071e10 100644
--- a/app/views/editions/secondary_nav_tabs/_history.html.erb
+++ b/app/views/editions/secondary_nav_tabs/_history.html.erb
@@ -19,6 +19,12 @@
margin_bottom: 3,
href: history_add_edition_note_edition_path,
}),
+ (render "govuk_publishing_components/components/button", {
+ text: "Update important note",
+ margin_bottom: 3,
+ secondary_solid: true,
+ href: history_update_important_note_edition_path,
+ }),
],
} %>
diff --git a/app/views/editions/secondary_nav_tabs/update_important_note.html.erb b/app/views/editions/secondary_nav_tabs/update_important_note.html.erb
new file mode 100644
index 000000000..6f6b89825
--- /dev/null
+++ b/app/views/editions/secondary_nav_tabs/update_important_note.html.erb
@@ -0,0 +1,33 @@
+<% @edition = @resource %>
+<% content_for :title_context, @edition.title %>
+<% content_for :page_title, "Update important note" %>
+<% content_for :title, "Update important note" %>
+
+
+
+
Add important notes that anyone who works on this edition needs to see, eg “(Doesn’t) need fact check, don’t publish.”.
+ Each edition can have only one important note at a time.
+
+ <%= form_for(:note, :url=> notes_path) do |f| %>
+ <%= hidden_field_tag :edition_id, resource.id %>
+ <%= hidden_field_tag "note[type]", Action::IMPORTANT_NOTE %>
+
+ <%= render "govuk_publishing_components/components/textarea", {
+ label: {
+ heading_size: "m",
+ text: "Important note",
+ },
+ name: "note[comment]",
+ rows: 14,
+ value: @edition.important_note&.comment,
+ } %>
+
+
+ <%= render "govuk_publishing_components/components/button", {
+ text: "Save",
+ } %>
+ <%= link_to("Cancel", history_edition_path, class: "govuk-link govuk-link--no-visited-state") %>
+
+ <% end %>
+
+
diff --git a/app/views/editions/show.html.erb b/app/views/editions/show.html.erb
index 33ecc1ec7..daba2b71d 100644
--- a/app/views/editions/show.html.erb
+++ b/app/views/editions/show.html.erb
@@ -20,8 +20,16 @@
- <%= render "govuk_publishing_components/components/summary_list", {
- items: document_summary_items(@resource),
+ <%= render "govuk_publishing_components/components/summary_list", {
+ items: document_summary_items(@resource),
+ } %>
+
+
+
+ <%= render "govuk_publishing_components/components/notice", {
+ title: @edition.important_note.comment,
+ description_govspeak: sanitize("
#{User.find_by(id: @edition.important_note.requester_id).name} added an important note on #{@edition.important_note.created_at.strftime("%d %B %Y")}
"),
+ show_banner_title: true
} %>
diff --git a/config/routes.rb b/config/routes.rb
index c8e1517da..0a70d2e3f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,6 +28,7 @@
get "metadata"
get "history"
get "history/add_edition_note", to: "editions#add_edition_note", as: "history/add_edition_note"
+ get "history/update_important_note", to: "editions#update_important_note", as: "history/update_important_note"
get "admin"
post "duplicate"
get "related_external_links"
diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb
index d7499c803..63d033582 100644
--- a/test/functional/notes_controller_test.rb
+++ b/test/functional/notes_controller_test.rb
@@ -49,6 +49,27 @@ class NotesControllerTest < ActionController::TestCase
end
end
+ context "when an Important note is provided" do
+ should "confirm the note was successfully recorded" do
+ post :create,
+ params: {
+ edition_id: @edition.id,
+ note: {
+ type: "important_note",
+ comment: @note_text,
+ },
+ }
+
+ @edition.reload
+
+ assert_equal(@note_text, @edition.important_note.comment)
+ assert_redirected_to history_edition_path(@edition)
+ assert_includes flash[:success], "Note recorded"
+ end
+ end
+
+ # TODO: Test that a blank note is saved and message is "Note resolved"
+
context "Welsh editors" do
setup do
login_as_welsh_editor
diff --git a/test/integration/edition_edit_test.rb b/test/integration/edition_edit_test.rb
index c3feff73f..008fd0bd1 100644
--- a/test/integration/edition_edit_test.rb
+++ b/test/integration/edition_edit_test.rb
@@ -55,6 +55,16 @@ class EditionEditTest < IntegrationTest
assert_selector(".govuk-summary-list__value", text: @draft_edition.assignee)
end
end
+
+ should "display the important note if an important note exists" do
+ setup do
+ @note_text = "This is really really urgent!"
+ create_important_note_for_edition(@published_edition, @note_text)
+ end
+
+ assert page.has_text?("Important")
+ assert page.has_text?(@note_text)
+ end
end
context "edit assignee page" do
@@ -133,6 +143,16 @@ class EditionEditTest < IntegrationTest
assert_current_path history_add_edition_note_edition_path(@draft_edition.id)
end
+
+ should "show an 'Update important note' button" do
+ assert page.has_link?("Update important note")
+ end
+
+ should "navigate to the 'Update important note' page when the button is clicked" do
+ click_link("Update important note")
+
+ assert_current_path history_update_important_note_edition_path(@draft_edition.id)
+ end
end
context "Add edition note page" do
@@ -161,6 +181,39 @@ class EditionEditTest < IntegrationTest
end
end
+ context "Update important note page" do
+ setup do
+ visit_draft_edition
+ click_link("History and notes")
+ click_link("Update important note")
+ end
+
+ should "render the 'Update important note' page" do
+ within :css, ".gem-c-heading" do
+ assert page.has_css?("h1", text: "Update important note")
+ assert page.has_css?(".gem-c-heading__context", text: @draft_edition.title)
+ end
+
+ assert page.has_text?("Add important notes that anyone who works on this edition needs to see, eg “(Doesn’t) need fact check, don’t publish.”.")
+ assert page.has_text?("Each edition can have only one important note at a time.")
+
+ within :css, ".gem-c-textarea" do
+ assert page.has_css?("label", text: "Important note")
+ assert page.has_css?("textarea")
+ end
+
+ assert page.has_button?("Save")
+ assert page.has_link?("Cancel")
+ end
+
+ should "pre-populate with the existing note" do
+ create_important_note_for_edition(@draft_edition, "An updated note")
+ click_link("Update important note")
+
+ assert page.has_field?("Important note", with: "An updated note")
+ end
+ end
+
context "unpublish tab" do
context "user does not have required permissions" do
setup do
@@ -905,4 +958,13 @@ def visit_old_edition_of_published_edition
)
visit edition_path(published_edition)
end
+
+ def create_important_note_for_edition(edition, note_text)
+ FactoryBot.create(
+ :action,
+ request_type: Action::IMPORTANT_NOTE,
+ edition: edition,
+ comment: note_text,
+ )
+ end
end