feat: Ability to delete account for administrators (#1874)
## Description Add account delete option in the user account settings. Fixes #1555 ## Type of change - [ ] New feature (non-breaking change which adds functionality)   ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose <sojan@pepalo.com> Co-authored-by: Sojan Jose <sojan.official@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
class AdministratorNotifications::AccountNotificationMailer < AdministratorNotifications::BaseMailer
|
||||
def account_deletion(account, reason = 'manual_deletion')
|
||||
subject = 'Your account has been marked for deletion'
|
||||
action_url = settings_url('general')
|
||||
meta = {
|
||||
'account_name' => account.name,
|
||||
'deletion_date' => account.custom_attributes['marked_for_deletion_at'],
|
||||
'reason' => reason
|
||||
}
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
def contact_import_complete(resource)
|
||||
subject = 'Contact Import Completed'
|
||||
|
||||
action_url = if resource.failed_records.attached?
|
||||
Rails.application.routes.url_helpers.rails_blob_url(resource.failed_records)
|
||||
else
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{resource.account.id}/contacts"
|
||||
end
|
||||
|
||||
meta = {
|
||||
'failed_contacts' => resource.total_records - resource.processed_records,
|
||||
'imported_contacts' => resource.processed_records
|
||||
}
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
|
||||
def contact_import_failed
|
||||
subject = 'Contact Import Failed'
|
||||
send_notification(subject)
|
||||
end
|
||||
|
||||
def contact_export_complete(file_url, email_to)
|
||||
subject = "Your contact's export file is available to download."
|
||||
send_notification(subject, to: email_to, action_url: file_url)
|
||||
end
|
||||
|
||||
def automation_rule_disabled(rule)
|
||||
subject = 'Automation rule disabled due to validation errors.'
|
||||
action_url = settings_url('automation/list')
|
||||
meta = { 'rule_name' => rule.name }
|
||||
|
||||
send_notification(subject, action_url: action_url, meta: meta)
|
||||
end
|
||||
end
|
||||
31
app/mailers/administrator_notifications/base_mailer.rb
Normal file
31
app/mailers/administrator_notifications/base_mailer.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class AdministratorNotifications::BaseMailer < ApplicationMailer
|
||||
# Common method to check SMTP configuration and send mail with liquid
|
||||
def send_notification(subject, to: nil, action_url: nil, meta: {})
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@action_url = action_url
|
||||
@meta = meta || {}
|
||||
|
||||
send_mail_with_liquid(to: to || admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
# Helper method to generate inbox URL
|
||||
def inbox_url(inbox)
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}"
|
||||
end
|
||||
|
||||
# Helper method to generate settings URL
|
||||
def settings_url(section)
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/#{section}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def admin_emails
|
||||
Current.account.administrators.pluck(:email)
|
||||
end
|
||||
|
||||
def liquid_locals
|
||||
super.merge({ meta: @meta })
|
||||
end
|
||||
end
|
||||
@@ -1,93 +1,16 @@
|
||||
class AdministratorNotifications::ChannelNotificationsMailer < ApplicationMailer
|
||||
def slack_disconnect
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Your Slack integration has expired'
|
||||
@action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/integrations/slack"
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
def dialogflow_disconnect
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Your Dialogflow integration was disconnected'
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
class AdministratorNotifications::ChannelNotificationsMailer < AdministratorNotifications::BaseMailer
|
||||
def facebook_disconnect(inbox)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Your Facebook page connection has expired'
|
||||
@action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}"
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def whatsapp_disconnect(inbox)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Your Whatsapp connection has expired'
|
||||
@action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}"
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
|
||||
def email_disconnect(inbox)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Your email inbox has been disconnected. Please update the credentials for SMTP/IMAP'
|
||||
@action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}"
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
def contact_import_complete(resource)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Contact Import Completed'
|
||||
|
||||
@action_url = Rails.application.routes.url_helpers.rails_blob_url(resource.failed_records) if resource.failed_records.attached?
|
||||
@action_url ||= "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{resource.account.id}/contacts"
|
||||
@meta = {}
|
||||
@meta['failed_contacts'] = resource.total_records - resource.processed_records
|
||||
@meta['imported_contacts'] = resource.processed_records
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
def contact_import_failed
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
subject = 'Contact Import Failed'
|
||||
|
||||
@meta = {}
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
def contact_export_complete(file_url, email_to)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@action_url = file_url
|
||||
subject = "Your contact's export file is available to download."
|
||||
|
||||
send_mail_with_liquid(to: email_to, subject: subject) and return
|
||||
end
|
||||
|
||||
def automation_rule_disabled(rule)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@action_url ||= "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/automation/list"
|
||||
|
||||
subject = 'Automation rule disabled due to validation errors.'.freeze
|
||||
@meta = {}
|
||||
@meta['rule_name'] = rule.name
|
||||
|
||||
send_mail_with_liquid(to: admin_emails, subject: subject) and return
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def admin_emails
|
||||
Current.account.administrators.pluck(:email)
|
||||
end
|
||||
|
||||
def liquid_locals
|
||||
super.merge({ meta: @meta })
|
||||
send_notification(subject, action_url: inbox_url(inbox))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class AdministratorNotifications::IntegrationsNotificationMailer < AdministratorNotifications::BaseMailer
|
||||
def slack_disconnect
|
||||
subject = 'Your Slack integration has expired'
|
||||
action_url = settings_url('integrations/slack')
|
||||
send_notification(subject, action_url: action_url)
|
||||
end
|
||||
|
||||
def dialogflow_disconnect
|
||||
subject = 'Your Dialogflow integration was disconnected'
|
||||
send_notification(subject)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user