Skip to content

Commit

Permalink
Merge pull request #185 from unboxed/fix-validation-requests
Browse files Browse the repository at this point in the history
Fix fee validations being separate from other change validations
  • Loading branch information
Celia Collins authored Dec 13, 2023
2 parents 7470e62 + ceec27d commit 61a161b
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 8 deletions.
46 changes: 46 additions & 0 deletions app/controllers/fee_change_validation_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

class FeeChangeValidationRequestsController < ValidationRequestsController
before_action :set_validation_request

def show
respond_to do |format|
if validation_request_is_closed? || validation_request_is_cancelled?
format.html
else
format.html { render_not_found }
end
end
end

def edit
respond_to do |format|
if validation_request_is_open?
@fee_change_validation_request = build_validation_request
format.html
else
format.html { render_not_found }
end
end
end

def update
@fee_change_validation_request = build_validation_request(fee_change_validation_request_params)

respond_to do |format|
if @fee_change_validation_request.update
flash[:notice] = t("shared.response_updated.success")
format.html { validation_requests_redirect_url }
else
flash[:error] = error_message(@fee_change_validation_request)
format.html { render :edit }
end
end
end

private

def fee_change_validation_request_params
params.require(:fee_change_validation_request).permit(:response)
end
end
27 changes: 27 additions & 0 deletions app/models/bops/fee_change_validation_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Bops
class FeeChangeValidationRequest
include ActiveModel::Model

attr_accessor :response, :planning_application_id, :change_access_id, :id

validates :response, presence: true

class << self
def find(id, planning_application_id, change_access_id)
Apis::Bops::Client.get_fee_change_validation_request(id, planning_application_id, change_access_id)
end

def respond(id, planning_application_id, change_access_id, response)
Apis::Bops::Client.patch_response_fee_change_request(id, planning_application_id, change_access_id, response)
end
end

def update
return false unless valid?

self.class.respond(id, planning_application_id, change_access_id, response)
end
end
end
20 changes: 20 additions & 0 deletions app/services/apis/bops/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ def patch_rejected_description_change(id, planning_application_id, change_access
)
end

# Fee change validation requests
def get_fee_change_validation_request(id, planning_application_id, change_access_id)
request(
http_method: :get,
endpoint: "planning_applications/#{planning_application_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}"
)
end

def patch_response_fee_change_request(id, planning_application_id, change_access_id, response)
request(
http_method: :patch,
endpoint: "planning_applications/#{planning_application_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}",
params: {
data: {
response:
}
}.to_json
)
end

# Other change validation requests
def get_other_change_validation_request(id, planning_application_id, change_access_id)
request(
Expand Down
30 changes: 30 additions & 0 deletions app/views/fee_change_validation_requests/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= form_with scope: :fee_change_validation_request,
url: fee_change_validation_request_path(@validation_request["id"], planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]),
method: :patch,
builder: GOVUKDesignSystemFormBuilder::FormBuilder do |form| %>
<% if @fee_change_validation_request.errors.any? %>
<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary">
<h2 class="govuk-error-summary__title" id="error-summary-title">
There is a problem
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
<% @fee_change_validation_request.errors.full_messages.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
</div>
</div>
<% end %>

<div class="govuk-form-group <%= flash["error"].present? ? 'govuk-form-group govuk-form-group--error' : '' %>">
<div class="govuk-!-padding-top-4 govuk-!-padding-bottom-2">
<%= form.govuk_text_area :response, label: { text: "Respond to this request" }, rows: 6 %>
</div>
</div>
<div class="govuk-button-group">
<%= form.submit "Submit", class: "govuk-button", data: { module: "govuk-button" } %>
<%= link_to 'Back', validation_requests_path(planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]), class: "govuk-button govuk-button--secondary" %>
</div>
<% end %>
35 changes: 35 additions & 0 deletions app/views/fee_change_validation_requests/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<% content_for :page_title do %>
<%= t(".page_title", id: @validation_request["id"]) %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-width-container">
<h1 class="govuk-heading-l"><%= t(".title") %></h1>
<p class="govuk-body"> <%= t(".the_following_request") %> </p>
<p class="govuk-heading-s"><%= t(".what_you_need") %></p>
<ul class="govuk-list govuk-list--bullet">
<li><%= t(".make_changes_to") %></li>
<li><%= t(".if_you_disagree") %></li>
<li><%= t(".click_submit_to") %></li>
</ul>
<div class="govuk-inset-text">
<%= t(".if_your_response", date: date_due(@validation_request)) %>
</div>
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
<div style="margin-top: 50px;">
<p class="govuk-body">
<strong><%= t(".officers_reason_for") %></strong><br>
<%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
</p>
</div>
<div style="margin-top: 30px;">
<p class="govuk-body">
<strong><%= t(".how_you_can") %></strong><br>
<%= render(FormattedContentComponent.new(text: @validation_request["suggestion"])) %>
</p>
</div>
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
<%= render 'form' %>
</div>
</div>
</div>
42 changes: 42 additions & 0 deletions app/views/fee_change_validation_requests/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<% content_for :page_title do %>
Other change validation request #<%= @validation_request["id"] %> - Back-Office Planning System
<% end %>

<div class="govuk-grid-row govuk-!-padding-bottom-8">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-width-container">
<% if @validation_request["state"] == "cancelled" %>
<%= render "validation_requests/cancelled",
validation_request: @validation_request,
heading: "Cancelled fee change request on your application" %>
<% else %>
<h1 class="govuk-heading-l">Response to fee change request</h1>
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
<p class="govuk-body">
<strong>Officer's reason for invalidating application</strong><br>
</p>
<p class="govuk-body">
<%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
</p>
<p class="govuk-body">
<strong>How you can make your application valid</strong><br>
</p>
<p class="govuk-body">
<%= @validation_request["suggestion"] %>
</p>
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
<p class="govuk-body">
<strong>My response to this request</strong><br>
</p>
<p class="govuk-body">
<%= render(FormattedContentComponent.new(text: @validation_request["response"])) %>
</p>
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
<% end %>

<div class="govuk-!-padding-bottom-8">
<%= link_to 'Back', validation_requests_path(planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]), class: "govuk-button govuk-button--secondary" %>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/other_change_validation_requests/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div style="margin-top: 50px;">
<p class="govuk-body">
<strong><%= t(".officers_reason_for") %></strong><br>
<%= render(FormattedContentComponent.new(text: @validation_request["summary"])) %>
<%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
</p>
</div>
<div style="margin-top: 30px;">
Expand Down
2 changes: 1 addition & 1 deletion app/views/other_change_validation_requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<strong>Officer's reason for invalidating application</strong><br>
</p>
<p class="govuk-body">
<%= render(FormattedContentComponent.new(text: @validation_request["summary"])) %>
<%= render(FormattedContentComponent.new(text: @validation_request["reason"])) %>
</p>
<p class="govuk-body">
<strong>How you can make your application valid</strong><br>
Expand Down
4 changes: 1 addition & 3 deletions app/views/validation_requests/_cancelled.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<strong>The officer gave the following reason for cancelling this request:</strong>
</p>
<div class="govuk-inset-text">
<p class="govuk-body">
<%= render(FormattedContentComponent.new(text: validation_request["cancel_reason"])) %>
</p>
<%= render(FormattedContentComponent.new(text: validation_request["cancel_reason"])) %>
<p class="govuk-body">
<%= validation_request["cancelled_at"].to_time.to_formatted_s(:day_month_year) %>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<li>
<h2 class="moj-task-list__section">
<span class="moj-task-list__section-number"><%= count_total_requests(@validation_requests, "fee_change_validation_requests") %></span>
Respond to fee change request
</h2>
<ul class="moj-task-list__items" id="other-change-validation-requests">
<% @validation_requests["data"]["fee_change_validation_requests"].each do |change_request| %>
<li class="moj-task-list__item">
<% if change_request["state"] == "open" %>
<%= link_to "Fee change", edit_fee_change_validation_request_path(change_request["id"], planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]), class: "moj-task-list__task-name" %>
<% else %>
<%= link_to "Fee change", fee_change_validation_request_path(change_request["id"], planning_application_id: params["planning_application_id"], change_access_id: params["change_access_id"]), class: "moj-task-list__task-name" %>
<% end %>
<%= render "validation_requests/change_request_state", change_request: change_request %>
</li>
<% end %>
</ul>
</li>
4 changes: 4 additions & 0 deletions app/views/validation_requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<%= render "red_line_boundary_change_validation_requests" %>
<% end %>
<% if @validation_requests["data"]["fee_change_validation_requests"].present? %>
<%= render "fee_change_validation_requests" %>
<% end %>
<% if @validation_requests["data"]["other_change_validation_requests"].present? %>
<%= render "other_change_validation_requests" %>
<% end %>
Expand Down
16 changes: 16 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ en:
the_following_changes: The following changes have been made to your application's description.
title: Confirm changes to your application description
what_you_need: "What you need to do:"
fee_change_validation_requests:
edit:
click_submit_to: Click submit to complete this action
how_you_can: How you can make your application valid
if_you_disagree: If you disagree with the suggested changes, reply stating why you disagree
if_your_response: If your response is not received by %{date} your application will be returned to you and your payment refunded.
make_changes_to: Make changes to your application as set out by your case officer and reply in the box below stating what changes have been made
officers_reason_for: Officer's reason for invalidating application
page_title: "Fee change validation request #%{id} - Back-Office Planning System"
the_following_request: The following request has been made.
title: Respond to fee change request
what_you_need: "What you need to do:"
other_change_validation_requests:
edit:
click_submit_to: Click submit to complete this action
Expand Down Expand Up @@ -166,6 +178,10 @@ en:
attributes:
files:
blank: "Please choose at least one file to upload"
bops/fee_change_validation_request:
attributes:
response:
blank: "Please enter your response to the planning officer's question."
bops/replacement_document_validation_request:
attributes:
file:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
resources :replacement_document_validation_requests
resources :additional_document_validation_requests
resources :other_change_validation_requests
resources :fee_change_validation_requests
resources :red_line_boundary_change_validation_requests
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

RSpec.configure do |config|
helpers = Module.new do
def stub_get_fee_change_validation_request(id:, planning_id:, change_access_id:, response_body:, status:)
stub_request(
:get,
"#{ApiSpecHelper::API_BASE_URL}/#{planning_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}"
)
.with(
headers:
)
.to_return(
body: JSON.generate(response_body),
status:
)
end

def stub_patch_fee_change_validation_request(id:, planning_id:, change_access_id:, response:, status:)
stub_request(
:patch,
"#{ApiSpecHelper::API_BASE_URL}/#{planning_id}/fee_change_validation_requests/#{id}?change_access_id=#{change_access_id}"
)
.with(
headers:,
body: {data: {response:}}.to_json
)
.to_return(
body: "{}",
status:
)
end
end

config.include helpers, type: :system
end
Loading

0 comments on commit 61a161b

Please sign in to comment.