-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8958 from alphagov/1057-add-a-user-interface-for-…
…whitehalls-republish-tasks Add a user interface for republishing past prime ministers page
- Loading branch information
Showing
8 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Admin::RepublishingController < Admin::BaseController | ||
before_action :enforce_permissions! | ||
|
||
def index | ||
@republishable_documents = republishable_documents | ||
end | ||
|
||
def republish_past_prime_ministers_index | ||
PresentPageToPublishingApiWorker.perform_async("PublishingApi::HistoricalAccountsIndexPresenter") | ||
flash[:notice] = "'Past Prime Ministers' page has been scheduled for republishing" | ||
redirect_to(admin_republishing_index_path) | ||
end | ||
|
||
def confirm | ||
republishable_document = republishable_documents.find { |document| document[:slug] == params[:document_slug] } | ||
|
||
return render "admin/errors/not_found", status: :not_found unless republishable_document | ||
|
||
@document_title = republishable_document[:title] | ||
@republishing_path = republishable_document[:republishing_path] | ||
end | ||
|
||
private | ||
|
||
def enforce_permissions! | ||
enforce_permission!(:administer, :republish_documents) | ||
end | ||
|
||
def republishable_documents | ||
historical_accounts_index_presenter = PublishingApi::HistoricalAccountsIndexPresenter.new | ||
|
||
[{ | ||
title: historical_accounts_index_presenter.content[:title], | ||
public_path: historical_accounts_index_presenter.base_path, | ||
republishing_path: admin_republishing_republish_past_prime_ministers_path, | ||
slug: historical_accounts_index_presenter.base_path.split("/").last, | ||
}] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% content_for :page_title, "Republish '#{@document_title}'" %> | ||
<% content_for :title, "Are you sure you want to republish '#{@document_title}'?" %> | ||
<% 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 page to be republished. | ||
</p> | ||
<%= form_with(url: @republishing_path, method: :post, data: { | ||
module: "prevent-multiple-form-submissions", | ||
}) do | ||
render("govuk_publishing_components/components/button", { | ||
text: "Confirm republishing", | ||
}) | ||
end %> | ||
</section> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<% content_for :page_title, "Republish documents" %> | ||
<% content_for :title, "Republish documents" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<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> | ||
|
||
<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 document type most focused to the scope of what you need to republish to avoid unnecessary server load. | ||
</p> | ||
|
||
<%= render "govuk_publishing_components/components/table", { | ||
head: [ | ||
{ | ||
text: "Document", | ||
}, | ||
{ | ||
text: "Action", | ||
}, | ||
], | ||
rows: @republishable_documents.map do |document| | ||
[ | ||
{ | ||
text: link_to(document[:title], Plek.website_root + document[:public_path], class:"govuk-link"), | ||
}, | ||
{ | ||
text: link_to(sanitize("Republish #{tag.span('\'' + document[:title] + '\' page', class: 'govuk-visually-hidden')}"), | ||
admin_confirm_republishing_path(document[:slug]), | ||
id: "republish-past-prime-ministers-index", | ||
class: "govuk-link", | ||
), | ||
}, | ||
] | ||
end, | ||
} %> | ||
</section> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 |
13 changes: 13 additions & 0 deletions
13
features/step_definitions/republishing_published_documents_steps.rb.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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-index").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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "test_helper" | ||
|
||
class Admin::RepublishingControllerTest < ActionController::TestCase | ||
setup do | ||
login_as :gds_admin | ||
create(:ministerial_role, name: "Prime Minister", cabinet_member: true) | ||
end | ||
|
||
should_be_an_admin_controller | ||
|
||
view_test "GDS Admin users should be able to acess the GET :index and see links to republishable documents" 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/past-prime-ministers/confirm']", text: "Republish 'Past Prime Ministers' page" | ||
assert_response :ok | ||
end | ||
|
||
test "Non-GDS Admin users should not be able to access the GET :index" do | ||
login_as :writer | ||
|
||
get :index | ||
assert_response :forbidden | ||
end | ||
|
||
test "GDS Admin users should be able to access GET :confirm with a republishable document slug" do | ||
get :confirm, params: { document_slug: "past-prime-ministers" } | ||
assert_response :ok | ||
end | ||
|
||
test "GDS Admin users should see a 404 page when trying to republish a document with an unregistered document slug" do | ||
get :confirm, params: { document_slug: "not-republishable" } | ||
assert_response :not_found | ||
end | ||
|
||
test "Non-GDS Admin users should not be able to access GET :confirm" do | ||
login_as :writer | ||
|
||
get :confirm, params: { document_slug: "past-prime-ministers" } | ||
assert_response :forbidden | ||
end | ||
|
||
test "GDS Admin users should be able to trigger the PresentPageToPublishingWorker job with the HistoricalAccountsIndexPresenter" do | ||
PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").once | ||
|
||
post :republish_past_prime_ministers_index | ||
|
||
assert_redirected_to admin_republishing_index_path | ||
assert_equal "'Past Prime Ministers' page has been scheduled for republishing", flash[:notice] | ||
end | ||
|
||
test "Non-GDS Admin users should not be able to republish the page" do | ||
PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HistoricalAccountsIndexPresenter").never | ||
|
||
login_as :writer | ||
|
||
post :republish_past_prime_ministers_index | ||
assert_response :forbidden | ||
end | ||
end |