Skip to content

Commit

Permalink
Merge branch 'main' into SchemesForAbsorbedOrgs
Browse files Browse the repository at this point in the history
  • Loading branch information
RachaelBooth authored Nov 26, 2024
2 parents 780cbd9 + 4d14d4b commit 4687124
Show file tree
Hide file tree
Showing 274 changed files with 4,642 additions and 1,981 deletions.
1 change: 1 addition & 0 deletions .github/workflows/staging_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
types:
- opened
- synchronize
merge_group:
workflow_dispatch:

defaults:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apk add --update --no-cache tzdata && \
# build-base: compilation tools for bundle
# yarn: node package manager
# postgresql-dev: postgres driver and libraries
RUN apk add --no-cache build-base=0.5-r3 busybox=1.36.1-r7 nodejs-current=20.8.1-r0 yarn=1.22.19-r0 postgresql13-dev=13.16-r0 git=2.40.3-r0 bash=5.2.15-r5
RUN apk add --no-cache build-base=0.5-r3 busybox=1.36.1-r7 nodejs-current=20.8.1-r0 yarn=1.22.19-r0 postgresql13-dev=13.17-r0 git=2.40.3-r0 bash=5.2.15-r5

# Bundler version should be the same version as what the Gemfile.lock was bundled with
RUN gem install bundler:2.3.14 --no-document
Expand Down
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
16 changes: 8 additions & 8 deletions app/controllers/schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ def update
if @scheme.errors.empty? && @scheme.update(scheme_params)
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
if scheme_params[:confirmed] == "true" || @scheme.confirmed?
if check_answers && confirm_secondary_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
if check_answers && should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
else
@scheme.locations.update!(confirmed: true)
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
elsif check_answers
if confirm_secondary_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
if should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
else
redirect_to scheme_check_answers_path(@scheme)
end
Expand Down Expand Up @@ -253,8 +253,8 @@ def validation_errors(scheme_params)
end
end

def confirm_secondary_page?(page)
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes"
def should_direct_via_secondary_client_group_page?(page)
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" && @scheme.secondary_client_group.nil?
end

def current_template(page)
Expand Down Expand Up @@ -297,9 +297,9 @@ def next_page_path(page)
def scheme_params
required_params = params.require(:scheme).permit(:service_name,
:sensitive,
:owning_organisation_id,
:scheme_type,
:registered_under_care_act,
:owning_organisation_id,
:id,
:has_other_client_group,
:primary_client_group,
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/styles/_table-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
}

.scheme-name-cell {
word-break: break-all;
overflow-wrap: break-word;
word-break: break-word;
}

.app-table-group:focus {
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/form_page_error_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def remove_duplicate_page_errors(lettings_log)
end

def all_questions_affected_by_errors(log)
log.errors.map(&:attribute) - [:base]
(log.errors.map(&:attribute) - [:base]).uniq
end
end
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
10 changes: 5 additions & 5 deletions app/helpers/schemes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def secondary_schemes_csv_download_url(organisation, search, download_type)
def change_answer_link(scheme, question_id, user)
case question_id
when "service_name", "sensitive", "scheme_type", "registered_under_care_act", "owning_organisation_id", "arrangement_type"
user.support? || !scheme.confirmed? ? scheme_details_path(scheme, check_answers: true) : scheme_edit_name_path(scheme)
user.support? || !scheme.confirmed? ? scheme_details_path(scheme, referrer: "check-answers") : scheme_edit_name_path(scheme)
when "primary_client_group"
scheme_primary_client_group_path(scheme, check_answers: true)
scheme_primary_client_group_path(scheme, referrer: "check-answers")
when "has_other_client_group"
scheme_confirm_secondary_client_group_path(scheme, check_answers: true)
scheme_confirm_secondary_client_group_path(scheme, referrer: "check-answers")
when "secondary_client_group"
scheme_secondary_client_group_path(scheme, check_answers: true)
scheme_secondary_client_group_path(scheme, referrer: "check-answers")
when "support_type", "intended_stay"
scheme_support_path(scheme, check_answers: true)
scheme_support_path(scheme, referrer: "check-answers")
end
end

Expand Down
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
9 changes: 9 additions & 0 deletions app/models/derived_variables/sales_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ def set_derived_fields!
self.la = nil
end

if form.start_year_2025_or_later? && is_bedsit?
self.beds = 1
end

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
2 changes: 1 addition & 1 deletion app/models/form/lettings/questions/uprn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(id, hsh, page)
end

def unanswered_error_message
I18n.t("validations.property.uprn.invalid")
I18n.t("validations.lettings.property.uprn.invalid")
end

def get_extra_check_answer_value(log)
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
Loading

0 comments on commit 4687124

Please sign in to comment.