3 changed files with 54 additions and 1 deletions
@ -0,0 +1,26 @@
|
||||
# Not used functionally, but used to allow 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, |
||||
organisation: 3, |
||||
scheme: 4, |
||||
}.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 |
||||
@ -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 |
||||
Loading…
Reference in new issue