Class: Privacy::DeletionRequest

Inherits:
ApplicationRecord show all
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

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#account_lookupObject

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
end

#confirmation_codeObject (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_emailObject

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_notesObject

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_atObject (readonly)

Validates the request timestamp is present.

Validations:



74
# File 'app/models/privacy/deletion_request.rb', line 74

validates :requested_at,      presence: true

#require_accountObject

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
end

#sourceObject (readonly)

Validates the request source is one of SOURCES.

Validations:



70
# File 'app/models/privacy/deletion_request.rb', line 70

validates :source,            presence: true, inclusion: { in: SOURCES }

Class Method Details

.awaiting_processingActiveRecord::Relation<Privacy::DeletionRequest>

A relation of Privacy::DeletionRequests that are awaiting processing. Active Record Scope

Returns:

See Also:



138
# File 'app/models/privacy/deletion_request.rb', line 138

scope :awaiting_processing, -> { where(state: 'pending') }

.needs_reviewActiveRecord::Relation<Privacy::DeletionRequest>

A relation of Privacy::DeletionRequests that are needs review. Active Record Scope

Returns:

See Also:



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.

Parameters:

  • _auth_object (Object, nil) (defaults to: nil)

    ransack authorization object (unused)

Returns:

  • (Array<String>)


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.

Parameters:

  • _auth_object (Object, nil) (defaults to: nil)

    ransack authorization object (unused)

Returns:

  • (Array<String>)


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

.recentActiveRecord::Relation<Privacy::DeletionRequest>

A relation of Privacy::DeletionRequests that are recent. Active Record Scope

Returns:

See Also:



141
# File 'app/models/privacy/deletion_request.rb', line 141

scope :recent,              ->(window = 30.days) { where(requested_at: window.ago..).order(requested_at: :desc) }

.terminalActiveRecord::Relation<Privacy::DeletionRequest>

A relation of Privacy::DeletionRequests that are terminal. Active Record Scope

Returns:

See Also:



140
# File 'app/models/privacy/deletion_request.rb', line 140

scope :terminal,            -> { where(state: %w[completed declined no_account_found]) }

Instance Method Details

#accountAccount

Account whose data is requested for deletion (when resolved).

Returns:

See Also:



58
# File 'app/models/privacy/deletion_request.rb', line 58

belongs_to :account,     optional: true

#partyParty

CRM party whose data is requested for deletion (when resolved).

Returns:

See Also:



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.

Returns:



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., party_id: auth.&.party_id)
  auth
end

#reviewed_byAccount

Admin account that reviewed the request.

Returns:

See Also:



62
# File 'app/models/privacy/deletion_request.rb', line 62

belongs_to :reviewed_by, class_name: 'Account', optional: true