diff --git a/app/controllers/admin/republishing_controller.rb b/app/controllers/admin/republishing_controller.rb index 7aeaafa6be6..c0318b4b9d4 100644 --- a/app/controllers/admin/republishing_controller.rb +++ b/app/controllers/admin/republishing_controller.rb @@ -20,7 +20,38 @@ def republish_page return render "admin/errors/not_found", status: :not_found unless page_to_republish PresentPageToPublishingApiWorker.perform_async(page_to_republish[:presenter]) - flash[:notice] = "'#{page_to_republish[:title]}' page has been scheduled for republishing" + flash[:notice] = "The '#{page_to_republish[:title]}' page has been scheduled for republishing" + redirect_to(admin_republishing_index_path) + end + + def find_organisation; end + + def search_organisation + @organisation = Organisation.find_by(slug: params[:organisation_slug]) + + unless @organisation + flash[:alert] = "Organisation with slug '#{params[:organisation_slug]}' not found" + return redirect_to(admin_republishing_organisation_find_path) + end + + redirect_to(admin_republishing_organisation_confirm_path(params[:organisation_slug])) + end + + def confirm_organisation + unless @organisation&.slug == params[:organisation_slug] + @organisation = Organisation.find_by(slug: params[:organisation_slug]) + render "admin/errors/not_found", status: :not_found unless @organisation + end + end + + def republish_organisation + unless @organisation&.slug == params[:organisation_slug] + @organisation = Organisation.find_by(slug: params[:organisation_slug]) + return render "admin/errors/not_found", status: :not_found unless @organisation + end + + @organisation.publish_to_publishing_api + flash[:notice] = "The '#{@organisation.name}' organisation has been scheduled for republishing" redirect_to(admin_republishing_index_path) end @@ -31,13 +62,23 @@ def enforce_permissions! end def republishable_pages - historical_accounts_index_presenter = PublishingApi::HistoricalAccountsIndexPresenter.new - - [{ - title: historical_accounts_index_presenter.content[:title], - public_path: historical_accounts_index_presenter.base_path, - slug: historical_accounts_index_presenter.base_path.split("/").last, - presenter: "PublishingApi::HistoricalAccountsIndexPresenter", - }] + [ + "PublishingApi::HistoricalAccountsIndexPresenter", + "PublishingApi::HowGovernmentWorksPresenter", + "PublishingApi::OperationalFieldsIndexPresenter", + "PublishingApi::MinistersIndexPresenter", + "PublishingApi::EmbassiesIndexPresenter", + "PublishingApi::WorldIndexPresenter", + "PublishingApi::OrganisationsIndexPresenter", + ].map do |presenter_class_string| + presenter_instance = presenter_class_string.constantize.new + + { + title: presenter_instance.content[:title], + public_path: presenter_instance.base_path, + slug: presenter_instance.base_path.split("/").last, + presenter: presenter_class_string, + } + end end end diff --git a/app/presenters/publishing_api/embassies_index_presenter.rb b/app/presenters/publishing_api/embassies_index_presenter.rb index 5d898b752bf..4fcaf0c4a0e 100644 --- a/app/presenters/publishing_api/embassies_index_presenter.rb +++ b/app/presenters/publishing_api/embassies_index_presenter.rb @@ -29,12 +29,12 @@ def links { parent: [WORLD_INDEX_CONTENT_ID] } end - private - def base_path "/world/embassies" end + private + def details { world_locations: world_locations.map do |embassy| diff --git a/app/presenters/publishing_api/ministers_index_presenter.rb b/app/presenters/publishing_api/ministers_index_presenter.rb index c6e2c9774f0..d7ef4744aca 100644 --- a/app/presenters/publishing_api/ministers_index_presenter.rb +++ b/app/presenters/publishing_api/ministers_index_presenter.rb @@ -46,6 +46,10 @@ def links } end + def base_path + "/government/ministers" + end + private def details @@ -60,10 +64,6 @@ def details end end - def base_path - "/government/ministers" - end - def reshuffle_in_progress? SitewideSetting.find_by(key: :minister_reshuffle_mode)&.on || false end diff --git a/app/views/admin/republishing/confirm_organisation.html.erb b/app/views/admin/republishing/confirm_organisation.html.erb new file mode 100644 index 00000000000..26bc9d2cb51 --- /dev/null +++ b/app/views/admin/republishing/confirm_organisation.html.erb @@ -0,0 +1,18 @@ +<% content_for :page_title, "Republish '#{@organisation.name}'" %> +<% content_for :title, "Are you sure you want to republish '#{@organisation.name}'?" %> +<% content_for :title_margin_bottom, 6 %> + +
+
+

+ This will schedule the <%= link_to @organisation.name, @organisation.public_url, { class: "govuk-link" } %> organisation to be republished. +

+ <%= form_with(url: admin_republishing_organisation_republish_path(@organisation.slug), method: :post, data: { + module: "prevent-multiple-form-submissions", + }) do + render("govuk_publishing_components/components/button", { + text: "Confirm republishing", + }) + end %> +
+
diff --git a/app/views/admin/republishing/find_organisation.html.erb b/app/views/admin/republishing/find_organisation.html.erb new file mode 100644 index 00000000000..6a87eb550ce --- /dev/null +++ b/app/views/admin/republishing/find_organisation.html.erb @@ -0,0 +1,24 @@ +<% content_for :page_title, "Republish an organisation" %> +<% content_for :title, "Which organisation would you like to republish?" %> +<% content_for :title_margin_bottom, 6 %> + +
+
+ <%= form_with(url: admin_republishing_organisation_search_path, method: :post, data: { + module: "prevent-multiple-form-submissions", + }) do %> + + <%= render "govuk_publishing_components/components/input", { + label: { + text: "Enter the slug for the organisation", + }, + hint: "You can get the slug from the last part of the public URL - everything after '/government/organisations/'.", + name: "organisation_slug", + } %> + + <%= render "govuk_publishing_components/components/button", { + text: "Continue", + } %> + <% end %> +
+
diff --git a/app/views/admin/republishing/index.html.erb b/app/views/admin/republishing/index.html.erb index de816ed0065..387c4239411 100644 --- a/app/views/admin/republishing/index.html.erb +++ b/app/views/admin/republishing/index.html.erb @@ -4,18 +4,33 @@
-

- Sometimes it may be necessary to republish content to the Publishing API. This will refresh the content on the website. -

+
+ + + Guidance on republishing content + + +
+

+ Sometimes it may be necessary to republish content to the Publishing API. This will refresh the content on the website. +

-

- For example, if we make an update to govspeak and a publishing application pre-renders that content prior to its submission to Publishing API, that would require us to re-render and save new HTML for content. -

+

+ For example, if we make an update to govspeak and a publishing application pre-renders that content prior to its submission to Publishing API, that would require us to re-render and save new HTML for content. +

+ +

+ The following actions will allow you to schedule the republishing of content that was originally published in this application. + Any linked editions will also be republished through dependency resolution. + Try to pick the republishing task most focused to the scope of what you need to republish to avoid unnecessary server load. +

+
+
+ +

Individual pages

- The following actions will allow you to schedule the republishing of content that was originally published in this application. - Any linked editions will also be republished through dependency resolution. - Try to pick the republishing task most focused to the scope of what you need to republish to avoid unnecessary server load. + You can republish a selection of individual pages using the links below. If the page you wish to republish is not listed below, you may be able to use the 'Document' link in the next section.

<%= render "govuk_publishing_components/components/table", { @@ -33,7 +48,7 @@ text: link_to(page[:title], Plek.website_root + page[:public_path], class:"govuk-link"), }, { - text: link_to(sanitize("Republish #{tag.span('\'' + page[:title] + '\' page', class: 'govuk-visually-hidden')}"), + text: link_to(sanitize("Republish #{tag.span('the \'' + page[:title] + '\' page', class: 'govuk-visually-hidden')}"), admin_republishing_page_confirm_path(page[:slug]), id: "republish-" + page[:slug], class: "govuk-link", @@ -42,5 +57,40 @@ ] end, } %> + +

Other individual content

+ +

+ You can republish certain types of other indidivual content using the following actions. +

+ +

+ You'll need to provide the slug for the specific content you want to republish. Instructions for how to find this are provided on each page. +

+ + <%= render "govuk_publishing_components/components/table", { + head: [ + { + text: "Content type", + }, + { + text: "Action", + }, + ], + rows: [ + [ + { + text: "Organisation", + }, + { + text: link_to(sanitize("Republish #{tag.span('an organisation', class: 'govuk-visually-hidden')}"), + admin_republishing_organisation_find_path, + id: "republish-organisation", + class: "govuk-link", + ), + }, + ], + ], + } %>
diff --git a/config/routes.rb b/config/routes.rb index d5d5b121133..0028b3e1afa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,12 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) get "/:page_slug/confirm" => "republishing#confirm_page", as: :republishing_page_confirm post "/:page_slug/republish" => "republishing#republish_page", as: :republishing_page_republish end + scope :organisation do + get "/find" => "republishing#find_organisation", as: :republishing_organisation_find + post "/search" => "republishing#search_organisation", as: :republishing_organisation_search + get "/:organisation_slug/confirm" => "republishing#confirm_organisation", as: :republishing_organisation_confirm + post "/:organisation_slug/republish" => "republishing#republish_organisation", as: :republishing_organisation_republish + end end resources :documents, only: [] do diff --git a/features/republishing-content.feature b/features/republishing-content.feature new file mode 100644 index 00000000000..7fe7f832c59 --- /dev/null +++ b/features/republishing-content.feature @@ -0,0 +1,55 @@ +Feature: Republishing published documents + As an editor + I want to be able to republish published documents + So that they reflect changes to their dependencies when this doesn't happen automatically + + Background: + Given I am a GDS admin + + Scenario: Republish the "Past Prime Ministers" page + Given a published publication "Past Prime Ministers" exists + And the "Past Prime Ministers" page can be republished + When I request a republish of the "Past Prime Ministers" page + Then I can see the "Past Prime Ministers" page has been scheduled for republishing + + Scenario: Republish the "How government works" page + Given a published publication "How government works" exists + And the "How government works" page can be republished + When I request a republish of the "How government works" page + Then I can see the "How government works" page has been scheduled for republishing + + Scenario: Republish the "Fields of operation" page + Given a published publication "Fields of operation" exists + And the "Fields of operation" page can be republished + When I request a republish of the "Fields of operation" page + Then I can see the "Fields of operation" page has been scheduled for republishing + + Scenario: Republish the "Ministers" page + Given a published publication "Ministers" exists + And the "Ministers" page can be republished + When I request a republish of the "Ministers" page + Then I can see the "Ministers" page has been scheduled for republishing + + Scenario: Republish the "Find a British embassy, high commission or consulate" page + Given a published publication "Find a British embassy, high commission or consulate" exists + And the "Find a British embassy, high commission or consulate" page can be republished + When I request a republish of the "Find a British embassy, high commission or consulate" page + Then I can see the "Find a British embassy, high commission or consulate" page has been scheduled for republishing + + Scenario: Republish the "Help and services around the world" page + Given a published publication "Help and services around the world" exists + And the "Help and services around the world" page can be republished + When I request a republish of the "Help and services around the world" page + Then I can see the "Help and services around the world" page has been scheduled for republishing + + Scenario: Republish the "Departments, agencies and public bodies" page + Given a published publication "Departments, agencies and public bodies" exists + And the "Departments, agencies and public bodies" page can be republished + When I request a republish of the "Departments, agencies and public bodies" page + Then I can see the "Departments, agencies and public bodies" page has been scheduled for republishing + + Scenario: Republish an organisation + Given a published organisation "An Existing Organisation" exists + And the "An Existing Organisation" organisation can be republished + When I request a republish of the "An Existing Organisation" organisation + Then I can see the "An Existing Organisation" organisation has been scheduled for republishing diff --git a/features/republishing-documents.feature b/features/republishing-documents.feature deleted file mode 100644 index 3ccba7ca17f..00000000000 --- a/features/republishing-documents.feature +++ /dev/null @@ -1,13 +0,0 @@ -Feature: Republishing published documents - As an editor - I want to be able to republish published documents - So that they reflect changes to their dependencies when this doesn't happen automatically - - Background: - Given I am a GDS admin - - Scenario: Republish the "Past prime ministers" page - Given a published publication "Past prime ministers" exists - And the "Past prime ministers" page can be republished - When I request a republish of the "Past prime ministers" page - Then I can see the "Past prime ministers" page has been scheduled for republishing diff --git a/features/step_definitions/republishing_content_steps.rb.rb b/features/step_definitions/republishing_content_steps.rb.rb new file mode 100644 index 00000000000..0912cd86f1b --- /dev/null +++ b/features/step_definitions/republishing_content_steps.rb.rb @@ -0,0 +1,50 @@ +Given(/^the "([^"]*)" page can be republished$/) do |_page_title| + create(:ministerial_role, name: "Prime Minister", cabinet_member: true) +end + +When(/^I request a republish of the "([^"]*)" page$/) do |page_title| + visit admin_republishing_index_path + find(republishing_link_id_from_page_title(page_title)).click + click_button("Confirm republishing") +end + +Then(/^I can see the "([^"]*)" page has been scheduled for republishing/) do |page_title| + expect(page).to have_selector(".gem-c-success-alert", text: "The '#{page_title}' page has been scheduled for republishing") +end + +Given(/^a published organisation "An Existing Organisation" exists$/) do + create(:organisation, name: "An Existing Organisation", slug: "an-existing-organisation") +end + +Given(/^the "An Existing Organisation" organisation can be republished$/) do + create(:ministerial_role, name: "Prime Minister", cabinet_member: true) +end + +When(/^I request a republish of the "An Existing Organisation" organisation$/) do + visit admin_republishing_index_path + find("#republish-organisation").click + fill_in "Enter the slug for the organisation", with: "an-existing-organisation" + click_button("Continue") + click_button("Confirm republishing") +end + +Then(/^I can see the "An Existing Organisation" organisation has been scheduled for republishing/) do + expect(page).to have_selector(".gem-c-success-alert", text: "The 'An Existing Organisation' organisation has been scheduled for republishing") +end + +def republishing_link_id_from_page_title(page_title) + link_id = "#republish-" + + link_id += case page_title + when "Find a British embassy, high commission or consulate" + "embassies" + when "Help and services around the world" + "world" + when "Departments, agencies and public bodies" + "organisations" + else + page_title.downcase.gsub(" ", "-") + end + + link_id +end diff --git a/features/step_definitions/republishing_published_documents_steps.rb.rb b/features/step_definitions/republishing_published_documents_steps.rb.rb deleted file mode 100644 index 9df82a6ab55..00000000000 --- a/features/step_definitions/republishing_published_documents_steps.rb.rb +++ /dev/null @@ -1,13 +0,0 @@ -Given(/^the "Past prime ministers" page can be republished$/) do - create(:ministerial_role, name: "Prime Minister", cabinet_member: true) -end - -When(/^I request a republish of the "Past prime ministers" page$/) do - visit admin_republishing_index_path - find("#republish-past-prime-ministers").click - click_button("Confirm republishing") -end - -Then(/^I can see the "Past prime ministers" page has been scheduled for republishing/) do - expect(page).to have_selector(".gem-c-success-alert", text: "'Past Prime Ministers' page has been scheduled for republishing") -end diff --git a/test/functional/admin/republishing_controller_test.rb b/test/functional/admin/republishing_controller_test.rb index ef76f2d6c97..0cf2262bb6c 100644 --- a/test/functional/admin/republishing_controller_test.rb +++ b/test/functional/admin/republishing_controller_test.rb @@ -8,22 +8,25 @@ class Admin::RepublishingControllerTest < ActionController::TestCase should_be_an_admin_controller - view_test "GDS Admin users should be able to acess the GET :index and see links to republishable content" do + view_test "GDS Admin users should be able to GET :index and see links to republishable content" do get :index - assert_select ".govuk-table__cell:nth-child(1) a[href='https://www.test.gov.uk/government/history/past-prime-ministers']", text: "Past Prime Ministers" - assert_select ".govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/page/past-prime-ministers/confirm']", text: "Republish 'Past Prime Ministers' page" + assert_select ".govuk-table:nth-of-type(1) .govuk-table__cell:nth-child(1) a[href='https://www.test.gov.uk/government/history/past-prime-ministers']", text: "Past Prime Ministers" + assert_select ".govuk-table:nth-of-type(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/page/past-prime-ministers/confirm']", text: "Republish the 'Past Prime Ministers' page" + + assert_select ".govuk-table:nth-of-type(2) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/organisation/find']", text: "Republish an organisation" + assert_response :ok end - test "Non-GDS Admin users should not be able to access the GET :index" do + test "Non-GDS Admin users should not be able to GET :index" do login_as :writer get :index assert_response :forbidden end - test "GDS Admin users should be able to access GET :confirm_page with a republishable page slug" do + test "GDS Admin users should be able to GET :confirm_page with a republishable page slug" do get :confirm_page, params: { page_slug: "past-prime-ministers" } assert_response :ok end @@ -33,20 +36,20 @@ class Admin::RepublishingControllerTest < ActionController::TestCase assert_response :not_found end - test "Non-GDS Admin users should not be able to access GET :confirm_page" do + test "Non-GDS Admin users should not be able to GET :confirm_page" do login_as :writer get :confirm_page, params: { page_slug: "past-prime-ministers" } assert_response :forbidden end - test "GDS Admin users should be able to access POST :republish_page with a republishable page slug" do + test "GDS Admin users should be able to POST :republish_page with a republishable page slug" do PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").once post :republish_page, params: { page_slug: "past-prime-ministers" } assert_redirected_to admin_republishing_index_path - assert_equal "'Past Prime Ministers' page has been scheduled for republishing", flash[:notice] + assert_equal "The 'Past Prime Ministers' page has been scheduled for republishing", flash[:notice] end test "GDS Admin users should see a 404 page when trying to POST :republish_page with an unregistered page slug" do @@ -56,7 +59,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase assert_response :not_found end - test "Non-GDS Admin users should not be able to access POST :republish_page" do + test "Non-GDS Admin users should not be able to POST :republish_page" do PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").never login_as :writer @@ -64,4 +67,91 @@ class Admin::RepublishingControllerTest < ActionController::TestCase post :republish_page, params: { page_slug: "past-prime-ministers" } assert_response :forbidden end + + view_test "GDS Admin users should be able to GET :find_organisation" do + get :find_organisation + + assert_response :ok + end + + test "Non-GDS Admin users should not be able to GET :find_organisation" do + login_as :writer + + get :find_organisation + assert_response :forbidden + end + + test "GDS Admin users should be able to POST :search_organisation with an existing organisation slug" do + create(:organisation, slug: "an-existing-organisation") + + post :search_organisation, params: { organisation_slug: "an-existing-organisation" } + + assert_redirected_to admin_republishing_organisation_confirm_path("an-existing-organisation") + end + + test "GDS Admin users should be redirected back to :find_organisation when trying to POST :search_organisation with a nonexistent organisation slug" do + get :search_organisation, params: { organisation_slug: "not-an-existing-organisation" } + + assert_redirected_to admin_republishing_organisation_find_path + assert_equal "Organisation with slug 'not-an-existing-organisation' not found", flash[:alert] + end + + test "Non-GDS Admin users should not be able to POST :search_organisation" do + create(:organisation, slug: "an-existing-organisation") + + login_as :writer + + post :search_organisation, params: { organisation_slug: "an-existing-organisation" } + assert_response :forbidden + end + + test "GDS Admin users should be able to GET :confirm_organisation with an existing organisation slug" do + create(:organisation, slug: "an-existing-organisation") + + get :confirm_organisation, params: { organisation_slug: "an-existing-organisation" } + assert_response :ok + end + + test "GDS Admin users should see a 404 page when trying to GET :confirm_organisation with a nonexistent organisation slug" do + get :confirm_organisation, params: { organisation_slug: "not-an-existing-organisation" } + assert_response :not_found + end + + test "Non-GDS Admin users should not be able to GET :confirm_organisation" do + create(:organisation, slug: "an-existing-organisation") + + login_as :writer + + get :confirm_organisation, params: { organisation_slug: "an-existing-organisation" } + assert_response :forbidden + end + + test "GDS Admin users should be able to POST :republish_organisation with an existing organisation slug" do + create(:organisation, slug: "an-existing-organisation", name: "An Existing Organisation") + + Organisation.any_instance.expects(:publish_to_publishing_api).once + + post :republish_organisation, params: { organisation_slug: "an-existing-organisation" } + + assert_redirected_to admin_republishing_index_path + assert_equal "The 'An Existing Organisation' organisation has been scheduled for republishing", flash[:notice] + end + + test "GDS Admin users should see a 404 page when trying to POST :republish_organisation with a nonexistent organisation slug" do + Organisation.any_instance.expects(:publish_to_publishing_api).never + + get :republish_organisation, params: { organisation_slug: "not-an-existing-organisation" } + assert_response :not_found + end + + test "Non-GDS Admin users should not be able to POST :republish_organisation" do + create(:organisation, slug: "an-existing-organisation", name: "An Existing Organisation") + + Organisation.any_instance.expects(:publish_to_publishing_api).never + + login_as :writer + + post :republish_organisation, params: { organisation_slug: "an-existing-organisation" } + assert_response :forbidden + end end