Skip to content

Commit

Permalink
Merge pull request #8965 from alphagov/1117-add-ui-for-republish-orga…
Browse files Browse the repository at this point in the history
…nisation-by-slug

Add UI for republishing organisation by slug
  • Loading branch information
brucebolt authored Apr 23, 2024
2 parents f0e3e9f + 83e8f56 commit bf67825
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 60 deletions.
59 changes: 50 additions & 9 deletions app/controllers/admin/republishing_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions app/presenters/publishing_api/embassies_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
8 changes: 4 additions & 4 deletions app/presenters/publishing_api/ministers_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def links
}
end

def base_path
"/government/ministers"
end

private

def details
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions app/views/admin/republishing/confirm_organisation.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body govuk-!-margin-bottom-7">
This will schedule the <%= link_to @organisation.name, @organisation.public_url, { class: "govuk-link" } %> organisation to be republished.
</p>
<%= 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 %>
</section>
</div>
24 changes: 24 additions & 0 deletions app/views/admin/republishing/find_organisation.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<%= 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 %>
</section>
</div>
70 changes: 60 additions & 10 deletions app/views/admin/republishing/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body">
Sometimes it may be necessary to republish content to the Publishing API. This will refresh the content on the website.
</p>
<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Guidance on republishing content
</span>
</summary>
<div class="govuk-details__text">
<p class="govuk-body">
Sometimes it may be necessary to republish content to the Publishing API. This will refresh the content on the website.
</p>

<p class="govuk-body">
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.
</p>
<p class="govuk-body">
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.
</p>

<p class="govuk-body">
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.
</p>
</div>
</details>

<h2>Individual pages</h2>

<p class="govuk-body">
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.
</p>

<%= render "govuk_publishing_components/components/table", {
Expand All @@ -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",
Expand All @@ -42,5 +57,40 @@
]
end,
} %>

<h2>Other individual content</h2>

<p class="govuk-body">
You can republish certain types of other indidivual content using the following actions.
</p>

<p class="govuk-body">
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.
</p>

<%= 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",
),
},
],
],
} %>
</section>
</div>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions features/republishing-content.feature
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions features/republishing-documents.feature

This file was deleted.

50 changes: 50 additions & 0 deletions features/step_definitions/republishing_content_steps.rb.rb
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Loading

0 comments on commit bf67825

Please sign in to comment.