diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-08-28 03:31:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-28 03:31:54 +0200 |
commit | c556c3a0d1e54a6b07bbdd8f76cbb43672a91fd1 (patch) | |
tree | 4a5b8cbce1e63c42d79c6feb8606343bdb26313b /app/models/canonical_email_block.rb | |
parent | b399d79545e5e5430cb9d6a2c936efc244b69a75 (diff) |
Add admin API for managing canonical e-mail blocks (#19067)
Diffstat (limited to 'app/models/canonical_email_block.rb')
-rw-r--r-- | app/models/canonical_email_block.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/app/models/canonical_email_block.rb b/app/models/canonical_email_block.rb index 94781386c..1eb69ac67 100644 --- a/app/models/canonical_email_block.rb +++ b/app/models/canonical_email_block.rb @@ -5,27 +5,30 @@ # # id :bigint(8) not null, primary key # canonical_email_hash :string default(""), not null -# reference_account_id :bigint(8) not null +# reference_account_id :bigint(8) # created_at :datetime not null # updated_at :datetime not null # class CanonicalEmailBlock < ApplicationRecord include EmailHelper + include Paginable - belongs_to :reference_account, class_name: 'Account' + belongs_to :reference_account, class_name: 'Account', optional: true validates :canonical_email_hash, presence: true, uniqueness: true + scope :matching_email, ->(email) { where(canonical_email_hash: email_to_canonical_email_hash(email)) } + + def to_log_human_identifier + canonical_email_hash + end + def email=(email) self.canonical_email_hash = email_to_canonical_email_hash(email) end def self.block?(email) - where(canonical_email_hash: email_to_canonical_email_hash(email)).exists? - end - - def self.find_blocks(email) - where(canonical_email_hash: email_to_canonical_email_hash(email)) + matching_email(email).exists? end end |