Browse Source

Merge 3afe5eb68d into 6bccc2676e

pull/3313/merge
Samuel Young 2 weeks ago committed by GitHub
parent
commit
9c515ea0f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/controllers/lettings_logs_controller.rb
  2. 4
      app/controllers/organisations_controller.rb
  3. 1
      app/controllers/sales_logs_controller.rb
  4. 1
      app/controllers/schemes_controller.rb
  5. 1
      app/controllers/users_controller.rb
  6. 25
      app/models/download_record.rb
  7. 13
      db/migrate/20260415101455_create_download_record.rb
  8. 16
      db/schema.rb

1
app/controllers/lettings_logs_controller.rb

@ -96,6 +96,7 @@ class LettingsLogsController < LogsController
end end
def email_csv def email_csv
DownloadRecord.build_from_user(download_type: :lettings_log, download_filters: session_filters.to_s, user: current_user).save!
all_orgs = params["organisation_select"] == "all" all_orgs = params["organisation_select"] == "all"
EmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, codes_only_export?, "lettings", session_filters["years"].first.to_i) EmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, codes_only_export?, "lettings", session_filters["years"].first.to_i)
redirect_to csv_confirmation_lettings_logs_path redirect_to csv_confirmation_lettings_logs_path

4
app/controllers/organisations_controller.rb

@ -40,6 +40,7 @@ class OrganisationsController < ApplicationController
end end
def email_schemes_csv def email_schemes_csv
DownloadRecord.build_from_user(download_type: :scheme_location, download_filters: session_filters.merge({ download_type: params[:download_type] }).to_s, user: current_user).save!
SchemeEmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, params[:download_type]) SchemeEmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, params[:download_type])
redirect_to schemes_csv_confirmation_organisation_path redirect_to schemes_csv_confirmation_organisation_path
end end
@ -72,6 +73,7 @@ class OrganisationsController < ApplicationController
end end
end end
format.csv do format.csv do
DownloadRecord.build_from_user(download_type: :user, download_filters: session_filters.to_s, user: current_user).save!
send_data byte_order_mark + unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv" send_data byte_order_mark + unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv"
end end
end end
@ -205,6 +207,7 @@ class OrganisationsController < ApplicationController
end end
def email_lettings_csv def email_lettings_csv
DownloadRecord.build_from_user(download_type: :lettings_log, download_filters: session_filters.to_s, user: current_user).save!
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "lettings", session_filters["years"].first.to_i) EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "lettings", session_filters["years"].first.to_i)
redirect_to lettings_logs_csv_confirmation_organisation_path redirect_to lettings_logs_csv_confirmation_organisation_path
end end
@ -243,6 +246,7 @@ class OrganisationsController < ApplicationController
end end
def email_sales_csv def email_sales_csv
DownloadRecord.build_from_user(download_type: :sales_log, download_filters: session_filters.to_s, user: current_user).save!
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "sales", session_filters["years"].first.to_i) EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "sales", session_filters["years"].first.to_i)
redirect_to sales_logs_csv_confirmation_organisation_path redirect_to sales_logs_csv_confirmation_organisation_path
end end

1
app/controllers/sales_logs_controller.rb

@ -70,6 +70,7 @@ class SalesLogsController < LogsController
end end
def email_csv def email_csv
DownloadRecord.build_from_user(download_type: :sales_log, download_filters: session_filters.to_s, user: current_user).save!
all_orgs = params["organisation_select"] == "all" all_orgs = params["organisation_select"] == "all"
EmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, codes_only_export?, "sales", session_filters["years"].first.to_i) EmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, codes_only_export?, "sales", session_filters["years"].first.to_i)
redirect_to csv_confirmation_sales_logs_path redirect_to csv_confirmation_sales_logs_path

1
app/controllers/schemes_controller.rb

@ -236,6 +236,7 @@ class SchemesController < ApplicationController
end end
def email_csv def email_csv
DownloadRecord.build_from_user(download_type: :scheme_location, download_filters: session_filters.merge({ download_type: params[:download_type] }).to_s, user: current_user).save!
all_orgs = params["organisation_select"] == "all" all_orgs = params["organisation_select"] == "all"
SchemeEmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, params[:download_type]) SchemeEmailCsvJob.perform_later(current_user, search_term, session_filters, all_orgs, nil, params[:download_type])
redirect_to csv_confirmation_schemes_path redirect_to csv_confirmation_schemes_path

1
app/controllers/users_controller.rb

@ -24,6 +24,7 @@ class UsersController < ApplicationController
format.html format.html
format.csv do format.csv do
if current_user.support? if current_user.support?
DownloadRecord.build_from_user(download_type: :user, download_filters: session_filters.to_s, user: current_user).save!
send_data byte_order_mark + filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv" send_data byte_order_mark + filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv"
else else
head :unauthorized head :unauthorized

25
app/models/download_record.rb

@ -0,0 +1,25 @@
# Used to allow for easier auditing of what users downloaded what info
# Caches some info about the user at the time of download
class DownloadRecord < ApplicationRecord
belongs_to :user
belongs_to :user_organisation, class_name: "Organisation"
DOWNLOAD_TYPE = {
user: 0,
lettings_log: 1,
sales_log: 2,
scheme_location: 3,
}.freeze
enum download_type: DOWNLOAD_TYPE
enum user_role: User::ROLES
def self.build_from_user(user:, **attrs)
new(
user:,
user_organisation: user.organisation,
user_role: user.role,
**attrs,
)
end
end

13
db/migrate/20260415101455_create_download_record.rb

@ -0,0 +1,13 @@
class CreateDownloadRecord < ActiveRecord::Migration[7.2]
def change
create_table :download_records do |t|
t.integer :download_type, null: false
t.string :download_filters, null: false
t.references :user, null: false, foreign_key: true
t.references :user_organisation, null: false, foreign_key: { to_table: :organisations }
t.integer :user_role, null: false
t.timestamps
end
end
end

16
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2026_03_05_095832) do ActiveRecord::Schema[7.2].define(version: 2026_04_15_101455) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -106,6 +106,18 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_05_095832) do
t.index ["organisation_id"], name: "index_data_protection_confirmations_on_organisation_id" t.index ["organisation_id"], name: "index_data_protection_confirmations_on_organisation_id"
end end
create_table "download_records", force: :cascade do |t|
t.integer "download_type", null: false
t.string "download_filters", null: false
t.bigint "user_id", null: false
t.bigint "user_organisation_id", null: false
t.integer "user_role", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_download_records_on_user_id"
t.index ["user_organisation_id"], name: "index_download_records_on_user_organisation_id"
end
create_table "exports", force: :cascade do |t| create_table "exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "started_at", null: false t.datetime "started_at", null: false
@ -943,6 +955,8 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_05_095832) do
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end end
add_foreign_key "download_records", "organisations", column: "user_organisation_id"
add_foreign_key "download_records", "users"
add_foreign_key "lettings_logs", "locations" add_foreign_key "lettings_logs", "locations"
add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "lettings_logs", "schemes" add_foreign_key "lettings_logs", "schemes"

Loading…
Cancel
Save