Skip to content

Commit

Permalink
Merge pull request #2830 from alphagov/3035-integrate-the-specialist-…
Browse files Browse the repository at this point in the history
…finder-edit-forms-with-support-api

Integrate the finder edit forms with support api
  • Loading branch information
dnkrj authored Nov 1, 2024
2 parents 09c5f14 + 4c05003 commit cbda85c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ $govuk-page-width: 1140px;
@import 'govuk_publishing_components/components/breadcrumbs';
@import 'govuk_publishing_components/components/button';
@import 'govuk_publishing_components/components/checkboxes';
@import 'govuk_publishing_components/components/details';
@import 'govuk_publishing_components/components/error-message';
@import 'govuk_publishing_components/components/govspeak';
@import 'govuk_publishing_components/components/hint';
Expand All @@ -20,6 +19,7 @@ $govuk-page-width: 1140px;
@import 'govuk_publishing_components/components/secondary-navigation';
@import 'govuk_publishing_components/components/select';
@import 'govuk_publishing_components/components/skip-link';
@import 'govuk_publishing_components/components/success-alert';
@import 'govuk_publishing_components/components/summary-card';
@import 'govuk_publishing_components/components/textarea';
@import 'govuk_publishing_components/components/title';
Expand Down
21 changes: 20 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def confirm_metadata
:base_path,
:description,
:summary,
:show_summaries,
:document_noun,
organisations: [],
related: [],
Expand All @@ -29,7 +30,7 @@ def confirm_metadata
@proposed_schema.delete("related")
end

if @proposed_schema["show_summaries"] == "true"
if params["show_summaries"] == "true"
@proposed_schema["show_summaries"] = true
else
@proposed_schema.delete("show_summaries")
Expand All @@ -38,6 +39,11 @@ def confirm_metadata
render :confirm_metadata
end

def zendesk
GdsApi.support_api.raise_support_ticket(support_payload)
redirect_to "/admin/#{current_format.admin_slug}", notice: "Your changes have been submitted and Zendesk ticket created."
end

private

def check_authorisation
Expand All @@ -48,4 +54,17 @@ def check_authorisation
redirect_to root_path
end
end

def support_payload
{
subject: "Specialist Finder Edit Request: #{current_format.title.pluralize}",
tags: %w[specialist_finder_edit_request],
priority: "normal",
description: "```\r\n#{params[:proposed_schema]}\r\n```",
requester: {
name: current_user.name,
email: current_user.email,
},
}
end
end
1 change: 1 addition & 0 deletions app/policies/document_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def can_request_edits_to_finder?
alias_method :summary?, :can_request_edits_to_finder?
alias_method :edit_metadata?, :can_request_edits_to_finder?
alias_method :confirm_metadata?, :can_request_edits_to_finder?
alias_method :zendesk?, :can_request_edits_to_finder?

def publish?
document_type_editor? || gds_editor? || departmental_editor?
Expand Down
18 changes: 6 additions & 12 deletions app/views/admin/confirm_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@
previous_schema: @current_format.finder_schema.schema,
} %>

<%= render "govuk_publishing_components/components/details", {
title: "Proposed JSON",
} do %>
<% capture do %>
<pre><%= JSON.pretty_generate(@proposed_schema) %></pre>
<% end %>
<% end %>

<p class="govuk-body govuk-body govuk-!-margin-top-7">
By submitting you are confirming that these changes are required to the specialist finder.
</p>

<div class="govuk-button-group govuk-!-margin-top-7">
<%= render "govuk_publishing_components/components/button", {
text: "Submit changes",
href: "/admin/#{current_format.admin_slug}"
} %>
<%= form_tag "/admin/zendesk/#{current_format.admin_slug}", method: 'post' do %>
<%= hidden_field_tag :proposed_schema, JSON.pretty_generate(@proposed_schema) %>
<%= render "govuk_publishing_components/components/button", {
text: "Submit changes"
} %>
<% end %>
<%= link_to("Cancel", "/admin/#{current_format.admin_slug}", class: "govuk-link govuk-link--no-visited-state") %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<%= yield(:breadcrumbs) %>

<main class="govuk-main-wrapper<%= " govuk-main-wrapper--l" if yield(:back_link).blank? && yield(:breadcrumbs).blank? %>" id="main-content" role="main">

<%= render "govuk_publishing_components/components/success_alert", {
message: flash[:notice]
} if flash[:notice] %>
<% if yield(:title).present? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get "/admin/:document_type_slug", to: "admin#summary"
get "/admin/metadata/:document_type_slug", to: "admin#edit_metadata"
post "/admin/metadata/:document_type_slug", to: "admin#confirm_metadata"
post "/admin/zendesk/:document_type_slug", to: "admin#zendesk"

resources :documents, path: "/:document_type_slug", param: :content_id_and_locale, except: :destroy do
collection do
Expand Down
27 changes: 24 additions & 3 deletions spec/controllers/admin_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
require "spec_helper"
require "gds_api/test_helpers/support_api"

RSpec.describe AdminController, type: :controller do
include GdsApi::TestHelpers::SupportApi

render_views

let(:user) { FactoryBot.create(:gds_editor) }

before do
log_in_as user
end

describe "GET summary" do
it "responds successfully" do
log_in_as_gds_editor
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
get :summary, params: { document_type_slug: "asylum-support-decisions" }
expect(response.status).to eq(200)
Expand All @@ -14,7 +22,6 @@

describe "GET edit metadata" do
it "responds successfully" do
log_in_as_gds_editor
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
get :edit_metadata, params: { document_type_slug: "asylum-support-decisions" }
expect(response.status).to eq(200)
Expand All @@ -23,10 +30,24 @@

describe "POST edit metadata" do
it "responds successfully" do
log_in_as_gds_editor
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
post :edit_metadata, params: { document_type_slug: "asylum-support-decisions" }
expect(response.status).to eq(200)
end
end

describe "POST zendesk" do
it "responds successfully, calling support api" do
stub_post = stub_support_api_valid_raise_support_ticket(hash_including({
subject: "Specialist Finder Edit Request: CMA Cases",
tags: %w[specialist_finder_edit_request],
priority: "normal",
requester: { name: user.name, email: user.email },
}))

post :zendesk, params: { document_type_slug: "cma-cases", proposed_schema: CmaCase.finder_schema.schema }

assert_requested(stub_post)
end
end
end
8 changes: 8 additions & 0 deletions spec/features/editing_the_cma_case_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require "spec_helper"
require "gds_api/test_helpers/support_api"

RSpec.feature "Editing the CMA case finder", type: :feature do
include GdsApi::TestHelpers::SupportApi

let(:organisations) do
[
{ "content_id" => "957eb4ec-089b-4f71-ba2a-dc69ac8919ea", "title" => "Competition and Markets Authority" },
Expand All @@ -11,6 +14,7 @@
log_in_as_editor(:cma_editor)
stub_publishing_api_has_content([], hash_including(document_type: CmaCase.document_type))
stub_publishing_api_has_content(organisations, hash_including(document_type: Organisation.document_type))
stub_any_support_api_call
end

scenario "changing all fields" do
Expand Down Expand Up @@ -39,6 +43,10 @@
expect(page).to have_selector("dt", text: "Changed link 2")
expect(page).to have_selector("dt", text: "Changed link 3")
expect(page).to have_selector("dt", text: "Changed document noun")

click_button "Submit changes"

expect(page).to have_selector(".gem-c-success-alert__message", text: "Your changes have been submitted and Zendesk ticket created.")
end

scenario "fields are not shown on the confirmation page if not changed" do
Expand Down

0 comments on commit cbda85c

Please sign in to comment.