Class: Privacy::DeletionRequest
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Privacy::DeletionRequest
- Defined in:
- app/models/privacy/deletion_request.rb
Overview
AR model: durable audit row for a data-deletion request.
Constant Summary collapse
- SOURCES =
Where the request originated. New sources are added here as we wire up
additional providers (Google, Apple, LinkedIn) or intake channels. %w[facebook_callback manual_email manual_postal crm].freeze
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
-
#account_lookup ⇒ Object
Virtual attributes used only by the admin manual-entry form.
-
#confirmation_code ⇒ Object
readonly
Validates the emailed confirmation code is present and unique.
-
#contact_email ⇒ Object
Virtual attributes used only by the admin manual-entry form.
-
#intake_notes ⇒ Object
Virtual attributes used only by the admin manual-entry form.
-
#requested_at ⇒ Object
readonly
Validates the request timestamp is present.
-
#require_account ⇒ Object
Virtual attributes used only by the admin manual-entry form.
-
#source ⇒ Object
readonly
Validates the request source is one of
SOURCES.
Belongs to collapse
-
#account ⇒ Account
Account whose data is requested for deletion (when resolved).
-
#party ⇒ Party
CRM party whose data is requested for deletion (when resolved).
-
#reviewed_by ⇒ Account
Admin account that reviewed the request.
Class Method Summary collapse
-
.awaiting_processing ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are awaiting processing.
-
.needs_review ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are needs review.
-
.ransackable_associations(_auth_object = nil) ⇒ Array<String>
Associations Ransack may traverse in the admin search.
-
.ransackable_attributes(_auth_object = nil) ⇒ Array<String>
Ransack — admin search by these attributes only.
-
.recent ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are recent.
-
.terminal ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are terminal.
Instance Method Summary collapse
-
#resolve_facebook_account! ⇒ Authentication?
Facebook UID → existing Authentication row, or nil.
Methods inherited from ApplicationRecord
ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#account_lookup ⇒ Object
Virtual attributes used only by the admin manual-entry form. None of
them are persisted directly — account_lookup resolves to
account_id/party_id, contact_email + intake_notes are folded
into the data jsonb, and require_account is a UX guard.
55 56 57 |
# File 'app/models/privacy/deletion_request.rb', line 55 def account_lookup @account_lookup end |
#confirmation_code ⇒ Object (readonly)
Validates the emailed confirmation code is present and unique.
Validations:
72 |
# File 'app/models/privacy/deletion_request.rb', line 72 validates :confirmation_code, presence: true, uniqueness: true |
#contact_email ⇒ Object
Virtual attributes used only by the admin manual-entry form. None of
them are persisted directly — account_lookup resolves to
account_id/party_id, contact_email + intake_notes are folded
into the data jsonb, and require_account is a UX guard.
55 56 57 |
# File 'app/models/privacy/deletion_request.rb', line 55 def contact_email @contact_email end |
#intake_notes ⇒ Object
Virtual attributes used only by the admin manual-entry form. None of
them are persisted directly — account_lookup resolves to
account_id/party_id, contact_email + intake_notes are folded
into the data jsonb, and require_account is a UX guard.
55 56 57 |
# File 'app/models/privacy/deletion_request.rb', line 55 def intake_notes @intake_notes end |
#requested_at ⇒ Object (readonly)
Validates the request timestamp is present.
Validations:
74 |
# File 'app/models/privacy/deletion_request.rb', line 74 validates :requested_at, presence: true |
#require_account ⇒ Object
Virtual attributes used only by the admin manual-entry form. None of
them are persisted directly — account_lookup resolves to
account_id/party_id, contact_email + intake_notes are folded
into the data jsonb, and require_account is a UX guard.
55 56 57 |
# File 'app/models/privacy/deletion_request.rb', line 55 def require_account @require_account end |
Class Method Details
.awaiting_processing ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are awaiting processing. Active Record Scope
138 |
# File 'app/models/privacy/deletion_request.rb', line 138 scope :awaiting_processing, -> { where(state: 'pending') } |
.needs_review ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are needs review. Active Record Scope
139 |
# File 'app/models/privacy/deletion_request.rb', line 139 scope :needs_review, -> { where(state: %w[held_for_review failed]) } |
.ransackable_associations(_auth_object = nil) ⇒ Array<String>
Associations Ransack may traverse in the admin search.
166 167 168 |
# File 'app/models/privacy/deletion_request.rb', line 166 def self.ransackable_associations(_auth_object = nil) %w[account party reviewed_by] end |
.ransackable_attributes(_auth_object = nil) ⇒ Array<String>
Ransack — admin search by these attributes only.
159 160 161 |
# File 'app/models/privacy/deletion_request.rb', line 159 def self.ransackable_attributes(_auth_object = nil) %w[id source state external_user_id confirmation_code account_id party_id requested_at processed_at created_at updated_at] end |
.recent ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are recent. Active Record Scope
141 |
# File 'app/models/privacy/deletion_request.rb', line 141 scope :recent, ->(window = 30.days) { where(requested_at: window.ago..).order(requested_at: :desc) } |
.terminal ⇒ ActiveRecord::Relation<Privacy::DeletionRequest>
A relation of Privacy::DeletionRequests that are terminal. Active Record Scope
140 |
# File 'app/models/privacy/deletion_request.rb', line 140 scope :terminal, -> { where(state: %w[completed declined no_account_found]) } |
Instance Method Details
#account ⇒ Account
Account whose data is requested for deletion (when resolved).
58 |
# File 'app/models/privacy/deletion_request.rb', line 58 belongs_to :account, optional: true |
#party ⇒ Party
CRM party whose data is requested for deletion (when resolved).
60 |
# File 'app/models/privacy/deletion_request.rb', line 60 belongs_to :party, optional: true |
#resolve_facebook_account! ⇒ Authentication?
Facebook UID → existing Authentication row, or nil.
Resolves the Account + Party association columns when there's a match.
146 147 148 149 150 151 152 153 154 |
# File 'app/models/privacy/deletion_request.rb', line 146 def resolve_facebook_account! return nil unless source == 'facebook_callback' && external_user_id.present? auth = Authentication.find_by(provider: 'facebook', uid: external_user_id) return nil unless auth update!(account_id: auth.account_id, party_id: auth.account&.party_id) auth end |
#reviewed_by ⇒ Account
Admin account that reviewed the request.
62 |
# File 'app/models/privacy/deletion_request.rb', line 62 belongs_to :reviewed_by, class_name: 'Account', optional: true |