149 changed files with 1631 additions and 558 deletions
@ -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 |
||||
@ -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 |
||||
@ -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 |
||||
@ -0,0 +1,24 @@
|
||||
class Form::Sales::Questions::HasManagementFee < ::Form::Question |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "has_management_fee" |
||||
@copy_key = "sales.sale_information.management_fee.has_management_fee" |
||||
@type = "radio" |
||||
@answer_options = ANSWER_OPTIONS |
||||
@conditional_for = { |
||||
"management_fee" => [1], |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"has_management_fee" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
|
||||
ANSWER_OPTIONS = { |
||||
"1" => { "value" => "Yes" }, |
||||
"0" => { "value" => "No" }, |
||||
}.freeze |
||||
end |
||||
@ -0,0 +1,12 @@
|
||||
class Form::Sales::Questions::ManagementFee < ::Form::Question |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "management_fee" |
||||
@copy_key = "sales.sale_information.management_fee.management_fee" |
||||
@type = "numeric" |
||||
@min = 1 |
||||
@step = 0.01 |
||||
@width = 5 |
||||
@prefix = "£" |
||||
end |
||||
end |
||||
@ -0,0 +1,48 @@
|
||||
class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsection |
||||
def initialize(id, hsh, section) |
||||
super |
||||
@id = "shared_ownership_initial_purchase" |
||||
@label = "Shared ownership - initial purchase" |
||||
@depends_on = [{ "ownershipsch" => 1, "setup_completed?" => true, "staircase" => 2 }] |
||||
end |
||||
|
||||
def pages |
||||
@pages ||= [ |
||||
Form::Sales::Pages::Resale.new(nil, nil, self), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership_joint_purchase", nil, self, ownershipsch: 1, joint_purchase: true), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self, ownershipsch: 1, joint_purchase: false), |
||||
Form::Sales::Pages::HandoverDate.new(nil, nil, self), |
||||
Form::Sales::Pages::HandoverDateCheck.new(nil, nil, self), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_joint_purchase", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_not_joint_purchase", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousTenure.new(nil, nil, self), |
||||
Form::Sales::Pages::ValueSharedOwnership.new(nil, nil, self), |
||||
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), |
||||
Form::Sales::Pages::Equity.new(nil, nil, self), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), |
||||
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_amount_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), |
||||
Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), |
||||
Form::Sales::Pages::MonthlyRent.new(nil, nil, self), |
||||
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), |
||||
Form::Sales::Pages::EstateManagementFee.new("estate_management_fee", nil, self), |
||||
].compact |
||||
end |
||||
|
||||
def displayed_in_tasklist?(log) |
||||
log.staircase == 2 && (log.ownershipsch.nil? || log.ownershipsch == 1) |
||||
end |
||||
end |
||||
@ -0,0 +1,16 @@
|
||||
class CsvDownloadPolicy |
||||
attr_reader :current_user, :csv_download |
||||
|
||||
def initialize(current_user, csv_download) |
||||
@current_user = current_user |
||||
@csv_download = csv_download |
||||
end |
||||
|
||||
def show? |
||||
@current_user == @csv_download.user || @current_user.support? || @current_user.organisation == @csv_download.organisation |
||||
end |
||||
|
||||
def download? |
||||
@current_user == @csv_download.user || @current_user.support? || @current_user.organisation == @csv_download.organisation |
||||
end |
||||
end |
||||
@ -0,0 +1,50 @@
|
||||
class Csv::Downloader |
||||
attr_reader :csv_download |
||||
|
||||
delegate :path, to: :file |
||||
|
||||
def initialize(csv_download:) |
||||
@csv_download = csv_download |
||||
end |
||||
|
||||
def call |
||||
download |
||||
end |
||||
|
||||
def delete_local_file! |
||||
file.unlink |
||||
end |
||||
|
||||
def presigned_url |
||||
s3_storage_service.get_presigned_url(csv_download.filename, 60, response_content_disposition: "attachment; filename=#{csv_download.filename}") |
||||
end |
||||
|
||||
private |
||||
|
||||
def download |
||||
io = storage_service.get_file_io(csv_download.filename) |
||||
file.write(io.read) |
||||
io.close |
||||
file.close |
||||
end |
||||
|
||||
def file |
||||
@file ||= Tempfile.new |
||||
end |
||||
|
||||
def storage_service |
||||
@storage_service ||= if FeatureToggle.upload_enabled? |
||||
s3_storage_service |
||||
else |
||||
local_disk_storage_service |
||||
end |
||||
end |
||||
|
||||
def s3_storage_service |
||||
Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"]) |
||||
end |
||||
|
||||
def local_disk_storage_service |
||||
Storage::LocalDiskService.new |
||||
end |
||||
end |
||||
@ -0,0 +1,10 @@
|
||||
<% title = "Downlaod CSV file" %> |
||||
<% content_for :title, title %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||
<h1 class="govuk-heading-l govuk-!-margin-bottom-6">You are about to download a CSV file</h1> |
||||
<p class="govuk-body-m">Filename: <%= @csv_download.filename %></p> |
||||
<%= govuk_button_link_to "Download CSV", download_csv_download_path(@csv_download) %> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,8 @@
|
||||
<% content_for :title, "This link has expired" %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">This link has expired.</h1> |
||||
<p class="govuk-body-m">Download the logs again to get a new link.</p> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,8 @@
|
||||
class AddManagementFeeFields < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :sales_logs, bulk: true do |t| |
||||
t.column :has_management_fee, :integer |
||||
t.column :management_fee, :decimal, precision: 10, scale: 2 |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,12 @@
|
||||
class AddCsvDownloadTable < ActiveRecord::Migration[7.0] |
||||
def change |
||||
create_table :csv_downloads do |t| |
||||
t.column :download_type, :string |
||||
t.column :filename, :string |
||||
t.column :expiration_time, :integer |
||||
t.timestamps |
||||
t.references :user |
||||
t.references :organisation |
||||
end |
||||
end |
||||
end |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue