chore: Remove account.destroy listener (#1530)
This commit is contained in:
@@ -15,7 +15,6 @@ class AccountBuilder
|
|||||||
end
|
end
|
||||||
[@user, @account]
|
[@user, @account]
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
@account&.destroy
|
|
||||||
puts e.inspect
|
puts e.inspect
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
class InstallationWebhookListener < BaseListener
|
class InstallationWebhookListener < BaseListener
|
||||||
def account_created(event)
|
def account_created(event)
|
||||||
payload = event.data[:account].webhook_data.merge(event: __method__.to_s)
|
payload = account(event).webhook_data.merge(
|
||||||
deliver_webhook_payloads(payload)
|
event: __method__.to_s,
|
||||||
end
|
users: users(event)
|
||||||
|
)
|
||||||
def account_destroyed(event)
|
|
||||||
payload = event.data[:account].webhook_data.merge(event: __method__.to_s)
|
|
||||||
deliver_webhook_payloads(payload)
|
deliver_webhook_payloads(payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def account(event)
|
||||||
|
event.data[:account]
|
||||||
|
end
|
||||||
|
|
||||||
|
def users(event)
|
||||||
|
account(event).administrators.map(&:webhook_data)
|
||||||
|
end
|
||||||
|
|
||||||
def deliver_webhook_payloads(payload)
|
def deliver_webhook_payloads(payload)
|
||||||
# Deliver the installation event
|
# Deliver the installation event
|
||||||
webhook_url = InstallationConfig.find_by(name: 'INSTALLATION_EVENTS_WEBHOOK_URL')&.value
|
webhook_url = InstallationConfig.find_by(name: 'INSTALLATION_EVENTS_WEBHOOK_URL')&.value
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class Account < ApplicationRecord
|
|||||||
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h
|
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h
|
||||||
|
|
||||||
after_create_commit :notify_creation
|
after_create_commit :notify_creation
|
||||||
after_destroy :notify_deletion
|
|
||||||
|
|
||||||
def agents
|
def agents
|
||||||
users.where(account_users: { role: :agent })
|
users.where(account_users: { role: :agent })
|
||||||
@@ -92,8 +91,4 @@ class Account < ApplicationRecord
|
|||||||
def notify_creation
|
def notify_creation
|
||||||
Rails.configuration.dispatcher.dispatch(ACCOUNT_CREATED, Time.zone.now, account: self)
|
Rails.configuration.dispatcher.dispatch(ACCOUNT_CREATED, Time.zone.now, account: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_deletion
|
|
||||||
Rails.configuration.dispatcher.dispatch(ACCOUNT_DESTROYED, Time.zone.now, account: self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ module Events::Types
|
|||||||
### Installation Events ###
|
### Installation Events ###
|
||||||
# account events
|
# account events
|
||||||
ACCOUNT_CREATED = 'account.created'
|
ACCOUNT_CREATED = 'account.created'
|
||||||
ACCOUNT_DESTROYED = 'account.destroyed'
|
|
||||||
|
|
||||||
#### Account Events ###
|
#### Account Events ###
|
||||||
# channel events
|
# channel events
|
||||||
|
|||||||
@@ -17,28 +17,9 @@ describe InstallationWebhookListener do
|
|||||||
context 'when installation config is configured' do
|
context 'when installation config is configured' do
|
||||||
it 'triggers webhook' do
|
it 'triggers webhook' do
|
||||||
create(:installation_config, name: 'INSTALLATION_EVENTS_WEBHOOK_URL', value: 'https://test.com')
|
create(:installation_config, name: 'INSTALLATION_EVENTS_WEBHOOK_URL', value: 'https://test.com')
|
||||||
expect(WebhookJob).to receive(:perform_later).with('https://test.com', account.webhook_data.merge(event: 'account_created')).once
|
expect(WebhookJob).to receive(:perform_later).with('https://test.com', account.webhook_data.merge(event: 'account_created', users: [])).once
|
||||||
listener.account_created(event)
|
listener.account_created(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#account_destroyed' do
|
|
||||||
let(:event_name) { :'account.destroyed' }
|
|
||||||
|
|
||||||
context 'when installation config is not configured' do
|
|
||||||
it 'does not trigger webhook' do
|
|
||||||
expect(WebhookJob).to receive(:perform_later).exactly(0).times
|
|
||||||
listener.account_destroyed(event)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when installation config is configured' do
|
|
||||||
it 'triggers webhook' do
|
|
||||||
create(:installation_config, name: 'INSTALLATION_EVENTS_WEBHOOK_URL', value: 'https://test.com')
|
|
||||||
expect(WebhookJob).to receive(:perform_later).with('https://test.com', account.webhook_data.merge(event: 'account_destroyed')).once
|
|
||||||
listener.account_destroyed(event)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user