Skip to content

Commit

Permalink
Merge branch 'main' into CLDC-3723-Add-validation-on-location-number-…
Browse files Browse the repository at this point in the history
…of-units
  • Loading branch information
Dinssa authored Nov 26, 2024
2 parents 91dd298 + 4d14d4b commit 2426143
Show file tree
Hide file tree
Showing 149 changed files with 1,631 additions and 558 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ gem "possessive"
# Strip whitespace from active record attributes
gem "auto_strip_attributes"
# Use sidekiq for background processing
gem "factory_bot_rails"
gem "faker"
gem "method_source", "~> 1.1"
gem "rails_admin", "~> 3.1"
gem "ruby-openai"
Expand All @@ -75,8 +77,6 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: %i[mri mingw x64_mingw]
gem "dotenv-rails"
gem "factory_bot_rails"
gem "faker"
gem "pry-byebug"

gem "parallel_tests"
Expand Down
5 changes: 5 additions & 0 deletions app/components/create_log_actions_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
<% if user.support? %>
<%= govuk_button_link_to view_uploads_button_copy, view_uploads_button_href, secondary: true %>
<% end %>

<% if FeatureToggle.create_test_logs_enabled? %>
<%= govuk_button_link_to "Create test log", create_test_log_href, secondary: true %>
<%= govuk_button_link_to "Create test log (setup only)", create_setup_test_log_href, secondary: true %>
<% end %>
<% end %>
</div>
8 changes: 8 additions & 0 deletions app/components/create_log_actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def upload_button_href
send("bulk_upload_#{log_type}_log_path", id: "start")
end

def create_test_log_href
send("create_test_#{log_type}_log_path")
end

def create_setup_test_log_href
send("create_setup_test_#{log_type}_log_path")
end

def view_uploads_button_copy
"View #{log_type} bulk uploads"
end
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/csv_downloads_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class CsvDownloadsController < ApplicationController
before_action :authenticate_user!

def show
@csv_download = CsvDownload.find(params[:id])
authorize @csv_download

return render "errors/download_link_expired" if @csv_download.expired?
end

def download
csv_download = CsvDownload.find(params[:id])
authorize csv_download

return render "errors/download_link_expired" if csv_download.expired?

downloader = Csv::Downloader.new(csv_download:)

if Rails.env.development?
downloader.call
send_file downloader.path, filename: csv_download.filename, type: "text/csv"
else
presigned_url = downloader.presigned_url
redirect_to presigned_url, allow_other_host: true
end
end
end
14 changes: 14 additions & 0 deletions app/controllers/lettings_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ def download_bulk_upload
end
end

def create_test_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?

log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA")
redirect_to lettings_log_path(log)
end

def create_setup_test_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?

log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user)
redirect_to lettings_log_path(log)
end

private

def session_filters
Expand Down
1 change: 1 addition & 0 deletions app/controllers/merge_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def validate_response

if [day, month, year].none?(&:blank?) && Date.valid_date?(year.to_i, month.to_i, day.to_i)
merge_request_params["merge_date"] = Time.zone.local(year.to_i, month.to_i, day.to_i)
@merge_request.errors.add(:merge_date, :more_than_year_from_today) if Time.zone.local(year.to_i, month.to_i, day.to_i) - 1.year > Time.zone.today
else
@merge_request.errors.add(:merge_date, :invalid)
end
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/sales_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ def download_bulk_upload
end
end

def create_test_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?

log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user)
redirect_to sales_log_path(log)
end

def create_setup_test_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?

log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user)
redirect_to sales_log_path(log)
end

private

def session_filters
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def update
flash[:notice] = if scheme_previously_confirmed
"#{@scheme.service_name} has been updated."
else
"#{@scheme.service_name} has been created. It does not require helpdesk approval."
"#{@scheme.service_name} has been created."
end
redirect_to scheme_path(@scheme)
end
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/merge_requests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ def any_organisations_have_logs_after_merge_date?(organisations, type, merge_dat
def any_organisations_share_logs?(organisations, type)
organisations.any? { |organisation| organisation.send("#{type}_logs").filter_by_managing_organisation(organisations.where.not(id: organisation.id)).exists? }
end

def begin_merge_disabled?(merge_request)
merge_request.status != "ready_to_merge" || merge_request.merge_date.future?
end
end
13 changes: 10 additions & 3 deletions app/jobs/email_csv_job.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class EmailCsvJob < ApplicationJob
include Rails.application.routes.url_helpers
queue_as :default

BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8

EXPIRATION_TIME = 24.hours.to_i
EXPIRATION_TIME = 48.hours.to_i

def perform(user, search_term = nil, filters = {}, all_orgs = false, organisation = nil, codes_only_export = false, log_type = "lettings", year = nil) # rubocop:disable Style/OptionalBooleanParameter - sidekiq can't serialise named params
export_type = codes_only_export ? "codes" : "labels"
Expand All @@ -20,10 +21,16 @@ def perform(user, search_term = nil, filters = {}, all_orgs = false, organisatio

filename = "#{[log_type, 'logs', organisation&.name, Time.zone.now].compact.join('-')}.csv"

storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
storage_service = if FeatureToggle.upload_enabled?
Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
else
Storage::LocalDiskService.new
end

storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string)
csv_download = CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type: log_type, expiration_time: EXPIRATION_TIME)

url = storage_service.get_presigned_url(filename, EXPIRATION_TIME)
url = csv_download_url(csv_download.id, host: ENV["APP_HOST"])

CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME)
end
Expand Down
13 changes: 10 additions & 3 deletions app/jobs/scheme_email_csv_job.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class SchemeEmailCsvJob < ApplicationJob
include Rails.application.routes.url_helpers
queue_as :default

BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8

EXPIRATION_TIME = 24.hours.to_i
EXPIRATION_TIME = 48.hours.to_i

def perform(user, search_term = nil, filters = {}, all_orgs = false, organisation = nil, download_type = "combined") # rubocop:disable Style/OptionalBooleanParameter - sidekiq can't serialise named params
unfiltered_schemes = if organisation.present? && user.support?
Expand All @@ -23,10 +24,16 @@ def perform(user, search_term = nil, filters = {}, all_orgs = false, organisatio
filename = "#{['schemes-and-locations', organisation&.name, Time.zone.now].compact.join('-')}.csv"
end

storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
storage_service = if FeatureToggle.upload_enabled?
Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
else
Storage::LocalDiskService.new
end

storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string)
csv_download = CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type:, expiration_time: EXPIRATION_TIME)

url = storage_service.get_presigned_url(filename, EXPIRATION_TIME)
url = csv_download_url(csv_download.id, host: ENV["APP_HOST"])

CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME)
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/csv_download.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CsvDownload < ApplicationRecord
enum download_type: { lettings: "lettings", sales: "sales", schemes: "schemes", locations: "locations", combined: "combined" }

belongs_to :user
belongs_to :organisation

def expired?
created_at < expiration_time.seconds.ago
end
end
5 changes: 5 additions & 0 deletions app/models/derived_variables/lettings_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def set_derived_fields!

self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?

if startdate_changed? && !LocalAuthority.active(startdate).where(code: la).exists?
self.la = nil
self.is_la_inferred = false
end

reset_address_fields! if is_supported_housing?
end

Expand Down
5 changes: 5 additions & 0 deletions app/models/derived_variables/sales_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def set_derived_fields!
self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?
self.nationality_all_buyer2 = nationality_all_buyer2_group if nationality2_uk_or_prefers_not_to_say?

if saledate_changed? && !LocalAuthority.active(saledate).where(code: la).exists?
self.la = nil
self.is_la_inferred = false
end

set_encoded_derived_values!(DEPENDENCIES)
end

Expand Down
5 changes: 3 additions & 2 deletions app/models/form/lettings/pages/no_address_found.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ def initialize(id, hsh, subsection)
super
@id = "no_address_found"
@type = "interruption_screen"
@copy_key = "lettings.soft_validations.no_address_found"
@title_text = {
"translation" => "soft_validations.no_address_found.title_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [],
}
@informative_text = {
"translation" => "soft_validations.no_address_found.informative_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
@depends_on = [
Expand Down
1 change: 0 additions & 1 deletion app/models/form/lettings/subsections/household_needs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Lettings::Subsections::HouseholdNeeds < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "household_needs"
@copy_key = "lettings.household_needs.housingneeds_type"
@label = "Household needs"
@depends_on = [{ "non_location_setup_questions_completed?" => true }]
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/form/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(id, hsh, subsection)
delegate :form, to: :subsection

def copy_key
@copy_key ||= "#{form.type}.#{subsection.id}.#{questions[0].id}"
@copy_key ||= "#{form.type}.#{subsection.copy_key}.#{questions[0].id}"
end

def header
Expand Down
2 changes: 1 addition & 1 deletion app/models/form/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize(id, hsh, page)
delegate :form, to: :subsection

def copy_key
@copy_key ||= "#{form.type}.#{subsection.id}.#{id}"
@copy_key ||= "#{form.type}.#{subsection.copy_key}.#{id}"
end

def check_answer_label
Expand Down
2 changes: 1 addition & 1 deletion app/models/form/sales/pages/buyer_interview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Form::Sales::Pages::BuyerInterview < ::Form::Page
def initialize(id, hsh, subsection, joint_purchase:)
super(id, hsh, subsection)
@joint_purchase = joint_purchase
@copy_key = "sales.#{subsection.id}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
@copy_key = "sales.#{subsection.copy_key}.noint.#{joint_purchase ? 'joint_purchase' : 'not_joint_purchase'}"
end

def questions
Expand Down
1 change: 0 additions & 1 deletion app/models/form/sales/pages/deposit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ def initialize(id, hsh, subsection, ownershipsch:, optional:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@optional = optional
@copy_key = "sales.sale_information.deposit"
end

def questions
Expand Down
1 change: 0 additions & 1 deletion app/models/form/sales/pages/deposit_discount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Sales::Pages::DepositDiscount < ::Form::Page
def initialize(id, hsh, subsection, optional:)
super(id, hsh, subsection)
@optional = optional
@copy_key = "sales.sale_information.cashdis"
end

def questions
Expand Down
1 change: 0 additions & 1 deletion app/models/form/sales/pages/discount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Sales::Pages::Discount < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "discount"
@copy_key = "sales.sale_information.discount"
@depends_on = [{
"right_to_buy?" => true,
}]
Expand Down
1 change: 0 additions & 1 deletion app/models/form/sales/pages/equity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Sales::Pages::Equity < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "equity"
@copy_key = "sales.sale_information.equity"
end

def questions
Expand Down
13 changes: 13 additions & 0 deletions app/models/form/sales/pages/estate_management_fee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Form::Sales::Pages::EstateManagementFee < ::Form::Page
def initialize(id, hsh, subsection)
super
@copy_key = "sales.sale_information.management_fee"
end

def questions
@questions ||= [
Form::Sales::Questions::HasManagementFee.new(nil, nil, self),
Form::Sales::Questions::ManagementFee.new(nil, nil, self),
]
end
end
1 change: 0 additions & 1 deletion app/models/form/sales/pages/extra_borrowing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Sales::Pages::ExtraBorrowing < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection)
@ownershipsch = ownershipsch
@copy_key = "sales.sale_information.extrabor"
@description = ""
@subsection = subsection
@depends_on = [{
Expand Down
1 change: 0 additions & 1 deletion app/models/form/sales/pages/grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Form::Sales::Pages::Grant < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "grant"
@copy_key = "sales.sale_information.grant"
@depends_on = [{
"right_to_buy?" => false,
"rent_to_buy_full_ownership?" => false,
Expand Down
12 changes: 10 additions & 2 deletions app/models/form/sales/pages/handover_date_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ def initialize(id, hsh, subsection)
super
@id = "handover_date_check"
@copy_key = "sales.soft_validations.hodate_check"
@depends_on = [{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
@informative_text = {}
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [],
}
end

def depends_on
if form.start_year_2025_or_later?
[{ "saledate_check" => nil, "hodate_5_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_5_years_or_more_saledate?" => true }]
else
[{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
end
end

def questions
@questions ||= [
Form::Sales::Questions::HandoverDateCheck.new(nil, nil, self),
Expand Down
12 changes: 9 additions & 3 deletions app/models/form/sales/pages/living_before_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ def living_before_purchase
end
end

def depends_on
def routed_to?(log, _user)
super && page_routed_to?(log)
end

def page_routed_to?(log)
return false if form.start_year_2025_or_later? && log.resale != 2

if @joint_purchase
[{ "joint_purchase?" => true }]
log.joint_purchase?
else
[{ "not_joint_purchase?" => true }, { "jointpur" => nil }]
log.not_joint_purchase? || log.jointpur.nil?
end
end
end
Loading

0 comments on commit 2426143

Please sign in to comment.