Skip to content

Commit

Permalink
Merge pull request #9029 from alphagov/1136-polish-republishing-ui
Browse files Browse the repository at this point in the history
Polish republishing UI
  • Loading branch information
brucebolt authored May 9, 2024
2 parents be721de + 6cee7c0 commit b614d71
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 30 deletions.
10 changes: 5 additions & 5 deletions app/controllers/admin/republishing_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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] = "The '#{page_to_republish[:title]}' page has been scheduled for republishing"
flash[:notice] = "The page '#{page_to_republish[:title]}' has been scheduled for republishing"
redirect_to(admin_republishing_index_path)
end

Expand Down Expand Up @@ -51,7 +51,7 @@ def republish_organisation
end

@organisation.publish_to_publishing_api
flash[:notice] = "The '#{@organisation.name}' organisation has been scheduled for republishing"
flash[:notice] = "The organisation '#{@organisation.name}' has been republished"
redirect_to(admin_republishing_index_path)
end

Expand Down Expand Up @@ -82,7 +82,7 @@ def republish_person
end

@person.publish_to_publishing_api
flash[:notice] = "The '#{@person.name}' person has been scheduled for republishing"
flash[:notice] = "The person '#{@person.name}' has been republished"
redirect_to(admin_republishing_index_path)
end

Expand Down Expand Up @@ -113,7 +113,7 @@ def republish_role
end

@role.publish_to_publishing_api
flash[:notice] = "The '#{@role.name}' role has been scheduled for republishing"
flash[:notice] = "The role '#{@role.name}' has been republished"
redirect_to(admin_republishing_index_path)
end

Expand Down Expand Up @@ -144,7 +144,7 @@ def republish_document
end

PublishingApiDocumentRepublishingWorker.new.perform(@document.id)
flash[:notice] = "Editions for the document with slug '#{@document.slug}' have been scheduled for republishing"
flash[:notice] = "Editions for the document with slug '#{@document.slug}' have been republished"
redirect_to(admin_republishing_index_path)
end

Expand Down
8 changes: 8 additions & 0 deletions app/helpers/admin/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def admin_header_link(name, path, path_matcher = nil, options = {})
end
end

def admin_republish_content_link
if can?(:administer, :republish_content)
admin_link "Republish content", admin_republishing_index_path
end
end

private

def active_link_class(path_matcher)
request.path.match?(path_matcher) ? "active" : ""
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/more/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
admin_topical_events_link,
admin_world_location_news_link,
admin_worldwide_organisations_link,
admin_republish_content_link,
],
} %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/republishing/confirm_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body govuk-!-margin-bottom-7">
This will schedule the following editions to be republished.
This will republish the following editions.
</p>

<%= render "govuk_publishing_components/components/table", {
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/republishing/confirm_organisation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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.
This will republish the organisation <%= link_to @organisation.name, @organisation.public_url, { class: "govuk-link" } %>.
</p>
<%= form_with(url: admin_republishing_organisation_republish_path(@organisation.slug), method: :post, data: {
module: "prevent-multiple-form-submissions",
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/republishing/confirm_person.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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 @person.name, @person.public_url, { class: "govuk-link" } %> person to be republished.
This will republish the person <%= link_to @person.name, @person.public_url, { class: "govuk-link" } %>.
</p>
<%= form_with(url: admin_republishing_person_republish_path(@person.slug), method: :post, data: {
module: "prevent-multiple-form-submissions",
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/republishing/confirm_role.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body govuk-!-margin-bottom-7">
<% if @role.public_url %>
This will schedule the <%= link_to @role.name, @role.public_url, { class: "govuk-link" } %> role to be republished.
This will republish the role <%= link_to @role.name, @role.public_url, { class: "govuk-link" } %>.
<% else %>
This will schedule the '<%= @role.name %>' role to be republished.
This will republish the role '<%= @role.name %>'.
<% end %>
</p>
<%= form_with(url: admin_republishing_role_republish_path(@role.slug), method: :post, data: {
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/republishing/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</p>

<p class="govuk-body">
The following actions will allow you to schedule the republishing of content that was originally published in this application.
The following actions will allow you to republish 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>
Expand All @@ -30,7 +30,7 @@
<h2>Individual pages</h2>

<p class="govuk-body">
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.
You can schedule a selection of individual pages for republishing 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 Down
8 changes: 4 additions & 4 deletions features/republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ Feature: Republishing published documents
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
Then I can see the "An Existing Organisation" organisation has been republished

Scenario: Republish a person
Given a published person "Existing Person" exists
And the "Existing Person" person can be republished
When I request a republish of the "Existing Person" person
Then I can see the "Existing Person" person has been scheduled for republishing
Then I can see the "Existing Person" person has been republished

Scenario: Republish a role
Given a published role "An Existing Role" exists
And the "An Existing Role" role can be republished
When I request a republish of the "An Existing Role" role
Then I can see the "An Existing Role" role has been scheduled for republishing
Then I can see the "An Existing Role" role has been republished

Scenario: Republish a document
Given a document with slug "an-existing-document" exists
And the "an-existing-document" document's editions can be republished
When I request a republish of the "an-existing-document" document's editions
Then I can see the "an-existing-document" document's editions have been scheduled for republishing
Then I can see the "an-existing-document" document's editions have been republished
18 changes: 9 additions & 9 deletions features/step_definitions/republishing_content_steps.rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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")
expect(page).to have_selector(".gem-c-success-alert", text: "The page '#{page_title}' has been scheduled for republishing")
end

Given(/^a published organisation "An Existing Organisation" exists$/) do
Expand All @@ -28,8 +28,8 @@
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")
Then(/^I can see the "An Existing Organisation" organisation has been republished/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The organisation 'An Existing Organisation' has been republished")
end

Given(/^a published person "Existing Person" exists$/) do
Expand All @@ -48,8 +48,8 @@
click_button("Confirm republishing")
end

Then(/^I can see the "Existing Person" person has been scheduled for republishing/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The 'Existing Person' person has been scheduled for republishing")
Then(/^I can see the "Existing Person" person has been republished/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The person 'Existing Person' has been republished")
end

Given(/^a published role "An Existing Role" exists$/) do
Expand All @@ -68,8 +68,8 @@
click_button("Confirm republishing")
end

Then(/^I can see the "An Existing Role" role has been scheduled for republishing/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The 'An Existing Role' role has been scheduled for republishing")
Then(/^I can see the "An Existing Role" role has been republished/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The role 'An Existing Role' has been republished")
end

Given(/^a document with slug "an-existing-document" exists$/) do
Expand All @@ -89,8 +89,8 @@
click_button("Confirm republishing")
end

Then(/^I can see the "an-existing-document" document's editions have been scheduled for republishing/) do
expect(page).to have_selector(".gem-c-success-alert", text: "Editions for the document with slug 'an-existing-document' have been scheduled for republishing")
Then(/^I can see the "an-existing-document" document's editions have been republished/) do
expect(page).to have_selector(".gem-c-success-alert", text: "Editions for the document with slug 'an-existing-document' have been republished")
end

def republishing_link_id_from_page_title(page_title)
Expand Down
20 changes: 20 additions & 0 deletions test/functional/admin/more_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,24 @@ class Admin::MoreControllerTest < ActionController::TestCase
assert_select ".govuk-list"
assert_select "a.govuk-link", text: "Emergency banner"
end

view_test "GET #index does not render Republish content option when the user is not a GDS Admin." do
organisation = create(:organisation, name: "cabinet-minister")
login_as(:writer, organisation)

get :index

assert_select ".govuk-list"
refute_select "a.govuk-link", text: "Republish content"
end

view_test "GET #index renders Republish content option when the user is a GDS Admin." do
organisation = create(:organisation, name: "government-digital-service")
login_as(:gds_admin, organisation)

get :index

assert_select ".govuk-list"
assert_select "a.govuk-link", text: "Republish content"
end
end
10 changes: 5 additions & 5 deletions test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
post :republish_page, params: { page_slug: "past-prime-ministers" }

assert_redirected_to admin_republishing_index_path
assert_equal "The 'Past Prime Ministers' page has been scheduled for republishing", flash[:notice]
assert_equal "The page 'Past Prime Ministers' 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
Expand Down Expand Up @@ -137,7 +137,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
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]
assert_equal "The organisation 'An Existing Organisation' has been republished", flash[:notice]
end

test "GDS Admin users should see a 404 page when trying to POST :republish_organisation with a nonexistent organisation slug" do
Expand Down Expand Up @@ -224,7 +224,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
post :republish_person, params: { person_slug: "existing-person" }

assert_redirected_to admin_republishing_index_path
assert_equal "The 'Existing Person' person has been scheduled for republishing", flash[:notice]
assert_equal "The person 'Existing Person' has been republished", flash[:notice]
end

test "GDS Admin users should see a 404 page when trying to POST :republish_person with a nonexistent person slug" do
Expand Down Expand Up @@ -311,7 +311,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
post :republish_role, params: { role_slug: "an-existing-role" }

assert_redirected_to admin_republishing_index_path
assert_equal "The 'An Existing Role' role has been scheduled for republishing", flash[:notice]
assert_equal "The role 'An Existing Role' has been republished", flash[:notice]
end

test "GDS Admin users should see a 404 page when trying to POST :republish_role with a nonexistent role slug" do
Expand Down Expand Up @@ -398,7 +398,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
post :republish_document, params: { document_slug: "an-existing-document" }

assert_redirected_to admin_republishing_index_path
assert_equal "Editions for the document with slug 'an-existing-document' have been scheduled for republishing", flash[:notice]
assert_equal "Editions for the document with slug 'an-existing-document' have been republished", flash[:notice]
end

test "GDS Admin users should see a 404 page when trying to POST :republish_document with a nonexistent document slug" do
Expand Down

0 comments on commit b614d71

Please sign in to comment.