Skip to content

Commit

Permalink
Merge pull request #9045 from alphagov/track-republishing-events-other
Browse files Browse the repository at this point in the history
Track remainder of republishing content
  • Loading branch information
Gweaton committed May 16, 2024
2 parents 9612e85 + 6d9c193 commit 43b3088
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 66 deletions.
60 changes: 48 additions & 12 deletions app/controllers/admin/republishing_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def confirm_organisation
@organisation = Organisation.find_by(slug: params[:organisation_slug])
render "admin/errors/not_found", status: :not_found unless @organisation
end

@republishing_event = RepublishingEvent.new
end

def republish_organisation
Expand All @@ -62,9 +64,16 @@ def republish_organisation
return render "admin/errors/not_found", status: :not_found unless @organisation
end

@organisation.publish_to_publishing_api
flash[:notice] = "The organisation '#{@organisation.name}' has been republished"
redirect_to(admin_republishing_index_path)
action = "The organisation '#{@organisation.name}' has been republished"
@republishing_event = build_republishing_event(action)

if @republishing_event.save
@organisation.publish_to_publishing_api
flash[:notice] = action
redirect_to(admin_republishing_index_path)
else
render "confirm_organisation"
end
end

def find_person; end
Expand All @@ -85,6 +94,8 @@ def confirm_person
@person = Person.find_by(slug: params[:person_slug])
render "admin/errors/not_found", status: :not_found unless @person
end

@republishing_event = RepublishingEvent.new
end

def republish_person
Expand All @@ -93,9 +104,16 @@ def republish_person
return render "admin/errors/not_found", status: :not_found unless @person
end

@person.publish_to_publishing_api
flash[:notice] = "The person '#{@person.name}' has been republished"
redirect_to(admin_republishing_index_path)
action = "The person '#{@person.name}' has been republished"
@republishing_event = build_republishing_event(action)

if @republishing_event.save
@person.publish_to_publishing_api
flash[:notice] = action
redirect_to(admin_republishing_index_path)
else
render "confirm_person"
end
end

def find_role; end
Expand All @@ -116,6 +134,8 @@ def confirm_role
@role = Role.find_by(slug: params[:role_slug])
render "admin/errors/not_found", status: :not_found unless @role
end

@republishing_event = RepublishingEvent.new
end

def republish_role
Expand All @@ -124,9 +144,16 @@ def republish_role
return render "admin/errors/not_found", status: :not_found unless @role
end

@role.publish_to_publishing_api
flash[:notice] = "The role '#{@role.name}' has been republished"
redirect_to(admin_republishing_index_path)
action = "The role '#{@role.name}' has been republished"
@republishing_event = build_republishing_event(action)

if @republishing_event.save
@role.publish_to_publishing_api
flash[:notice] = action
redirect_to(admin_republishing_index_path)
else
render "confirm_role"
end
end

def find_document; end
Expand All @@ -147,6 +174,8 @@ def confirm_document
@document = Document.find_by(slug: params[:document_slug])
render "admin/errors/not_found", status: :not_found unless @document
end

@republishing_event = RepublishingEvent.new
end

def republish_document
Expand All @@ -155,9 +184,16 @@ def republish_document
return render "admin/errors/not_found", status: :not_found unless @document
end

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

if @republishing_event.save
PublishingApiDocumentRepublishingWorker.new.perform(@document.id)
flash[:notice] = action
redirect_to(admin_republishing_index_path)
else
render "confirm_document"
end
end

private
Expand Down
17 changes: 17 additions & 0 deletions app/views/admin/republishing/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(url: republishing_url, method: :post, data: {
module: "prevent-multiple-form-submissions",
}) do %>
<%= render("govuk_publishing_components/components/textarea", {
label: {
text: "What is the reason for republishing?",
heading_size: "m",
},
name: "reason",
id: "republishing_event_reason",
error_items: errors_for(@republishing_event.errors, :reason),
}) %>
<%= render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
}) %>
<% end %>
10 changes: 2 additions & 8 deletions app/views/admin/republishing/confirm_document.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% content_for :page_title, "Republish '#{@document.slug}'" %>
<% content_for :title, "Are you sure you want to republish '#{@document.slug}'?" %>
<% content_for :title_margin_bottom, 6 %>
<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @republishing_event)) %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
Expand Down Expand Up @@ -29,13 +30,6 @@
]
end,
} %>
<%= form_with(url: admin_republishing_document_republish_path(@document.slug), method: :post, data: {
module: "prevent-multiple-form-submissions",
}) do
render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
})
end %>
<%= render "form", republishing_url: admin_republishing_document_republish_path(@document.slug) %>
</section>
</div>
9 changes: 2 additions & 7 deletions app/views/admin/republishing/confirm_organisation.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<% 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 %>
<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @republishing_event)) %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body govuk-!-margin-bottom-7">
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",
}) do
render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
})
end %>
<%= render "form", republishing_url: admin_republishing_organisation_republish_path(@organisation.slug) %>
</section>
</div>
18 changes: 1 addition & 17 deletions app/views/admin/republishing/confirm_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@
<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/textarea", {
label: {
text: "What is the reason for republishing?",
heading_size: "m",
},
name: "reason",
id: "republishing_event_reason",
error_items: errors_for(@republishing_event.errors, :reason),
}) %>
<%= render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
}) %>
<% end %>
<%= render "form", republishing_url: @republishing_path %>
</section>
</div>
9 changes: 2 additions & 7 deletions app/views/admin/republishing/confirm_person.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<% content_for :page_title, "Republish '#{@person.name}'" %>
<% content_for :title, "Are you sure you want to republish '#{@person.name}'?" %>
<% content_for :title_margin_bottom, 6 %>
<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @republishing_event)) %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
<p class="govuk-body govuk-!-margin-bottom-7">
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",
}) do
render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
})
end %>
<%= render "form", republishing_url: admin_republishing_person_republish_path(@person.slug) %>
</section>
</div>
9 changes: 2 additions & 7 deletions app/views/admin/republishing/confirm_role.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% content_for :page_title, "Republish '#{@role.name}'" %>
<% content_for :title, "Are you sure you want to republish '#{@role.name}'?" %>
<% content_for :title_margin_bottom, 6 %>
<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @republishing_event)) %>

<div class="govuk-grid-row">
<section class="govuk-grid-column-two-thirds">
Expand All @@ -11,12 +12,6 @@
This will republish the role '<%= @role.name %>'.
<% end %>
</p>
<%= form_with(url: admin_republishing_role_republish_path(@role.slug), method: :post, data: {
module: "prevent-multiple-form-submissions",
}) do
render("govuk_publishing_components/components/button", {
text: "Confirm republishing",
})
end %>
<%= render "form", republishing_url: admin_republishing_role_republish_path(@role.slug) %>
</section>
</div>
4 changes: 4 additions & 0 deletions features/step_definitions/republishing_content_steps.rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
find("#republish-organisation").click
fill_in "Enter the slug for the organisation", with: "an-existing-organisation"
click_button("Continue")
fill_in "What is the reason for republishing?", with: "It needs republishing"
click_button("Confirm republishing")
end

Expand All @@ -46,6 +47,7 @@
find("#republish-person").click
fill_in "Enter the slug for the person", with: "existing-person"
click_button("Continue")
fill_in "What is the reason for republishing?", with: "It needs republishing"
click_button("Confirm republishing")
end

Expand All @@ -66,6 +68,7 @@
find("#republish-role").click
fill_in "Enter the slug for the role", with: "an-existing-role"
click_button("Continue")
fill_in "What is the reason for republishing?", with: "It needs republishing"
click_button("Confirm republishing")
end

Expand All @@ -87,6 +90,7 @@
find("#republish-document").click
fill_in "Enter the slug for the document", with: "an-existing-document"
click_button("Continue")
fill_in "What is the reason for republishing?", with: "It needs republishing"
click_button("Confirm republishing")
end

Expand Down

0 comments on commit 43b3088

Please sign in to comment.