chore: Improve the reauthorization requirement for Email Channel (#4753)

This commit is contained in:
Sojan Jose
2022-05-26 20:23:00 +05:30
committed by GitHub
parent 47a6d9681a
commit ab05dd9b9b
5 changed files with 45 additions and 2 deletions

View File

@@ -36,6 +36,8 @@ class Channel::Email < ApplicationRecord
include Channelable
include Reauthorizable
AUTHORIZATION_ERROR_THRESHOLD = 10
self.table_name = 'channel_email'
EDITABLE_ATTRS = [:email, :imap_enabled, :imap_login, :imap_password, :imap_address, :imap_port, :imap_enable_ssl, :imap_inbox_synced_at,
:smtp_enabled, :smtp_login, :smtp_password, :smtp_address, :smtp_port, :smtp_domain, :smtp_enable_starttls_auto,

View File

@@ -29,7 +29,9 @@ module Reauthorizable
# Implement in your exception handling logic for authorization errors
def authorization_error!
::Redis::Alfred.incr(authorization_error_count_key)
prompt_reauthorization! if authorization_error_count >= AUTHORIZATION_ERROR_THRESHOLD
# we are giving precendence to the authorization error threshhold defined in the class
# so that channels can override the default value
prompt_reauthorization! if authorization_error_count >= self.class::AUTHORIZATION_ERROR_THRESHOLD
end
# Performed automatically if error threshold is breached