-
Notifications
You must be signed in to change notification settings - Fork 0
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 #185 from unboxed/fix-validation-requests
Fix fee validations being separate from other change validations
- Loading branch information
Showing
16 changed files
with
450 additions
and
8 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
app/controllers/fee_change_validation_requests_controller.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,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 |
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,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 |
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,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 %> |
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,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> |
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,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> |
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
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
19 changes: 19 additions & 0 deletions
19
app/views/validation_requests/_fee_change_validation_requests.html.erb
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,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> |
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
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
36 changes: 36 additions & 0 deletions
36
spec/support/bops_api_request_stubs/fee_change_validation_request.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,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 |
Oops, something went wrong.