Skip to content

Commit

Permalink
Add edit method and further specs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdccollins committed Jan 2, 2024
1 parent e1466ba commit 9f4549b
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 142 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ end

group :test do
gem "webmock", "~> 3.12", ">= 3.12.2"
gem "factory_bot_rails"
end
21 changes: 16 additions & 5 deletions app/controllers/land_owners_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# frozen_string_literal: true

class LandOwnersController < ApplicationController
before_action :set_planning_application, :set_certificate
before_action :set_planning_application, :set_certificate, :set_change_access_id

def new
@land_owner = LandOwner.new()
@land_owner = LandOwner.new
end

def create
@land_owner = LandOwner.new(land_owner_params.except(:change_access_id))

if @land_owner.save
redirect_to planning_application_ownership_certificate_path(
@planning_application["id"],
@ownership_certificate,
@planning_application["id"],
@ownership_certificate,
change_access_id: land_owner_params[:change_access_id]
)
else
respond_to do |format|
format.html { render :new }
format.html do
set_change_access_id
render :new
end
end
end
end
Expand All @@ -38,4 +41,12 @@ def land_owner_params
.permit(:name, :address_1, :address_2, :town, :country, :postcode, :notice_given_at, :change_access_id)
.to_h.merge(ownership_certificate_id: @ownership_certificate.id)
end

def set_change_access_id
@change_access_id = if params.has_key?(:change_access_id)
params[:change_access_id]
else
land_owner_params[:change_access_id]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def update

if ownership_certificate_validation_request_params[:approved] == "yes"
redirect_to new_planning_application_ownership_certificate_path(params[:planning_application_id], change_access_id: params[:change_access_id])
elsif @ownership_certificate_validation_request.update
flash[:notice] = t("shared.response_updated.success")
validation_requests_redirect_url
else
if @ownership_certificate_validation_request.update
respond_to do |format|
flash[:error] = error_message(@ownership_certificate_validation_request)
format.html { render :edit }
end
respond_to do |format|
flash[:error] = error_message(@ownership_certificate_validation_request)
format.html { render :edit }
end
end
end
Expand Down
64 changes: 49 additions & 15 deletions app/controllers/ownership_certificates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class OwnershipCertificatesController < ApplicationController
before_action :set_planning_application
before_action :set_certificate, except: %i[new create]
before_action :set_validation_request, only: %i[new submit edit]

def new
@ownership_certificate = OwnershipCertificate.new(planning_application_id: @planning_application["id"])
Expand All @@ -11,18 +12,41 @@ def new
def show
end

def edit
end

def update
if @ownership_certificate.update(ownership_certificate_params.except(:change_access_id))
redirect_to planning_application_ownership_certificate_path(
@planning_application["id"],
@ownership_certificate,
change_access_id: ownership_certificate_params[:change_access_id]
)
else
respond_to do |format|
format.html do
set_validation_request
render :edit
end
end
end
end

def create
@ownership_certificate = OwnershipCertificate.new(ownership_certificate_params.except(:change_access_id))

if @ownership_certificate.save
redirect_to planning_application_ownership_certificate_path(
@planning_application["id"],
@ownership_certificate,
@planning_application["id"],
@ownership_certificate,
change_access_id: ownership_certificate_params[:change_access_id]
)
else
respond_to do |format|
format.html { render :new }
format.html do
set_validation_request
render :new
end
end
end
end
Expand All @@ -31,15 +55,18 @@ def thank_you
end

def submit
validation_requests = Apis::Bops::Client.get_validation_requests(@planning_application["id"], params[:change_access_id])
ownership_certificate_validation_request_id = validation_requests["data"]["ownership_certificate_validation_requests"].first["id"]
change_access_id = if params.has_key?(:change_access_id)
params[:change_access_id]
else
ownership_certificate_params[:change_access_id]
end

if Bops::OwnershipCertificateValidationRequest.approve(
ownership_certificate_validation_request_id,
@planning_application["id"],
params[:change_access_id],
@ownership_certificate_validation_request["id"],
@planning_application["id"],
change_access_id,
params: {
certificate_type: @ownership_certificate.certificate_type,
certificate_type: @ownership_certificate.certificate_type,
land_owners_attributes: @ownership_certificate.land_owners
}
)
Expand All @@ -53,20 +80,27 @@ def submit
private

def set_certificate
if params[:ownership_certificate_id]
@ownership_certificate = OwnershipCertificate.find(params[:ownership_certificate_id])
else
@ownership_certificate = OwnershipCertificate.find(params[:id])
end
@ownership_certificate = OwnershipCertificate.find(params[:ownership_certificate_id] || params[:id])
end

def set_planning_application
@planning_application = Bops::PlanningApplication.find(params[:planning_application_id])
@planning_application ||= Bops::PlanningApplication.find(params[:planning_application_id])
end

def ownership_certificate_params
params.require(:ownership_certificate)
.permit(:know_owners, :number_of_owners, :certificate_type, :notification_of_owners, :change_access_id)
.to_h.merge(planning_application_id: @planning_application["id"])
end

def set_validation_request
change_access_id = if params.has_key?(:change_access_id)
params[:change_access_id]
else
ownership_certificate_params[:change_access_id]
end

validation_requests = Apis::Bops::Client.get_validation_requests(@planning_application["id"], change_access_id)
@ownership_certificate_validation_request ||= validation_requests["data"]["ownership_certificate_validation_requests"].first
end
end
2 changes: 1 addition & 1 deletion app/helpers/validation_requests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def flattened_validation_requests(validation_requests)
validation_requests["data"]["replacement_document_validation_requests"] +
validation_requests["data"]["other_change_validation_requests"] +
validation_requests["data"]["fee_change_validation_requests"] +
validation_requests["data"]["red_line_boundary_change_validation_requests"]
validation_requests["data"]["red_line_boundary_change_validation_requests"] +
validation_requests["data"]["ownership_certificate_validation_requests"]
end

Expand Down
15 changes: 0 additions & 15 deletions app/models/bops/land_owner.rb

This file was deleted.

15 changes: 0 additions & 15 deletions app/models/bops/ownership_certificate.rb

This file was deleted.

8 changes: 4 additions & 4 deletions app/views/land_owners/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
builder: GOVUKDesignSystemFormBuilder::FormBuilder do |form| %>
<%= form.govuk_text_field :name, label: { text: "Owner name" } %>
<%= form.govuk_text_field :address_1, label: { text: "Address line 1" } %>
<%= form.govuk_text_field :address_1, label: { text: "Address line 2 (optional)" } %>
<%= form.govuk_text_field :address_2, label: { text: "Address line 2 (optional)" } %>
<%= form.govuk_text_field :town, label: { text: "Town or city" } %>
<%= form.govuk_text_field :country, label: { text: "Country (optional)" } %>
<%= form.govuk_text_field :postcode, label: { text: "Postcode" } %>
<%= form.govuk_date_field :notice_given_at, legend: { text: "What date was notice given to this owner?", size: "s" } %>
<%= form.hidden_field :change_access_id, value: params[:change_access_id] %>
<%= form.govuk_submit "Add owner" %>
<%= link_to "Back", planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate), class: "govuk-button govuk-button--secondary" %>
<%= form.hidden_field :change_access_id, value: @change_access_id %>
<%= form.govuk_submit "Add owner", change_access_id: @change_access_id %>
<%= link_to "Back", planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate, change_access_id: @change_access_id), class: "govuk-button govuk-button--secondary" %>
<% end %>
</div>
</div>
20 changes: 10 additions & 10 deletions app/views/ownership_certificate_validation_requests/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
<p class="govuk-body"><%= @planning_application["reference"] %></p>
</div>
<div class="govuk-grid-column-full">
<%# <my-map %>
<%# style="width: 100%; height: 400px; margin-bottom: 20px;" %>
<%# osVectorTilesApiKey='<%= ENV['OS_VECTOR_TILES_API_KEY'] %>' %>
<%# showScale %>
<%# useScaleBarStyle %>
<%# geojsonData='<%= @planning_application["boundary_geojson"].is_a?(Hash) ? @planning_application["boundary_geojson"].to_json : JSON.parse(@planning_application["boundary_geojson"]).to_json.html_safe %>' %>
<%# zoom="19" %>
<%# latitude='<%= @planning_application["site"]["latitude"] %>' %>
<%# longitude='<%= @planning_application["site"]["longitude"] %>' %>
<%# ></my-map> %>
<my-map
style="width: 100%; height: 400px; margin-bottom: 20px;"
osVectorTilesApiKey='<%= ENV['OS_VECTOR_TILES_API_KEY'] %>'
showScale
useScaleBarStyle
geojsonData='<%= @planning_application["boundary_geojson"].is_a?(Hash) ? @planning_application["boundary_geojson"].to_json : JSON.parse(@planning_application["boundary_geojson"]).to_json.html_safe %>'
zoom="19"
latitude='<%= @planning_application["site"]["latitude"] %>'
longitude='<%= @planning_application["site"]["longitude"] %>'
></my-map>
</div>
<div class="govuk-grid-column-two-thirds govuk-!-margin-top-5">
<p class="govuk-body">
Expand Down
52 changes: 52 additions & 0 deletions app/views/ownership_certificates/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<section aria-labelledby="page-heading">
<% content_for :page_title do %>
Confirm ownership
<% end %>
</section>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Confirm ownership</h1>

<p class="govuk-body">
<%= @planning_application["site"]["address_1"] %>,
<%= @planning_application["site"]["address_2"] %>,
<%= @planning_application["site"]["postcode"] %>
</p>

<p class="govuk-body-s govuk-!-margin-bottom-1">Planning application reference number</p>
<p class="govuk-body"><%= @planning_application["reference"] %></p>
<%= form_for @ownership_certificate,
url: planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate),
builder: GOVUKDesignSystemFormBuilder::FormBuilder,
method: :patch do |form| %>
<%= form.govuk_radio_buttons_fieldset(:know_owners, legend: { size: 'm', text: 'Do you know how many owners there are?' }) do %>
<%= form.govuk_radio_button :know_owners, 'Yes', label: { text: 'Yes' } do %>
<%= form.govuk_text_field :number_of_owners, label: { text: 'How many owners are there' } %>
<% end %>
<%= form.govuk_radio_button :know_owners, 'No', label: { text: 'No or not sure' }, link_errors: true %>
<% end %>
<%= form.govuk_radio_buttons_fieldset :certificate_type, legend: { text: 'Do you know who the owners of the property are?' } do %>
<%= form.govuk_radio_button :certificate_type, "b", label: { text: "Yes" } %>
<%= form.govuk_radio_button :certificate_type, "c", label: { text: "I know who some of them are" } %>
<%= form.govuk_radio_button :certificate_type, "d", label: { text: "I don't know who they are" } %>
<% end %>
<%= form.govuk_radio_buttons_fieldset(:notification_of_owners, legend: { size: 'm', text: 'Have you notified the owners of the land about this application?' }) do %>
<%= form.govuk_radio_button :notification_of_owners, 'yes', label: { text: 'Yes, all of them' } %>
<%= form.govuk_radio_button :notification_of_owners, 'some', label: { text: 'Yes, some of them' } %>
<%= form.govuk_radio_button :notification_of_owners, 'no', label: { text: 'No' } do %>
<p class="govuk-body">
You must notify owners about this application. Use a notification form to send them details of the proposed work
</p>
<% end %>
<% end %>
<%= form.hidden_field :change_access_id, value: params[:change_access_id] %>
<%= form.govuk_submit "Continue" %>
<%= link_to "Back",
edit_ownership_certificate_validation_request_path(@ownership_certificate_validation_request["id"], change_access_id: params[:change_access_id], planning_application_id: @planning_application["id"]),
class: "govuk-button govuk-button--secondary"
%>
<% end %>
</div>
</div>
6 changes: 4 additions & 2 deletions app/views/ownership_certificates/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
<% end %>
<%= form.hidden_field :change_access_id, value: params[:change_access_id] %>
<%= form.govuk_submit "Continue" %>
<%# <%= link_to "Back", edit_ownership_certificate_validation_request_path(), class: "govuk-button govuk-button--secondary" %> %>
<button type="submit" name="move_back" class="govuk-button govuk-button--secondary" data-disable-with="Back">Back</button>
<%= link_to "Back",
edit_ownership_certificate_validation_request_path(@ownership_certificate_validation_request["id"], change_access_id: params[:change_access_id], planning_application_id: @planning_application["id"]),
class: "govuk-button govuk-button--secondary"
%>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/ownership_certificates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
</p>
<%= hidden_field :change_access_id, value: params[:change_access_id] %>
<%= link_to "Accept and send", planning_application_ownership_certificate_submit_path(@planning_application["id"], @ownership_certificate, change_access_id: params[:change_access_id]), method: :post, class: "govuk-button" %>
<%= link_to "Back", new_planning_application_ownership_certificate_path(@planning_application["id"]), class: "govuk-button govuk-button--secondary" %>
<%= link_to "Back", edit_planning_application_ownership_certificate_path(@planning_application["id"], change_access_id: params[:change_access_id]), class: "govuk-button govuk-button--secondary" %>
</div>
</div>
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ en:
attributes:
response:
blank: "Please enter your response to the planning officer's question."
bops/ownership_certificate_validation_request:
attributes:
approved:
blank: "Select an option"
rejection_reason:
blank: "Fill in the reason for disagreeing with the suggested change."
bops/additional_document_validation_request:
attributes:
files:
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20231218112414_create_ownership_certificate.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateOwnershipCertificate < ActiveRecord::Migration[7.0]
def change
create_table :ownership_certificates do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20231218131345_create_land_owners.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateLandOwners < ActiveRecord::Migration[7.0]
def change
create_table :land_owners do |t|
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/test_change_request_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@
"response": "",
"type": "other_change_request"
}
],
"ownership_certificate_validation_requests": [
{
"id": 19,
"state": "open",
"response_due": "2021-06-16",
"days_until_response_due": 14,
"summary": "You applied for the wrong sort of certificate",
"response": "",
"type": "ownership_certificate_validation_request"
}
]
}
}
Loading

0 comments on commit 9f4549b

Please sign in to comment.