docbrown/app/workers/organizations/delete_worker.rb
Ridhwana 272aea6127
Allow admins to delete an organization (#19699)
* feat: update the layout for organizations

* feat: update the layout for an organization

* feat: organization logos are square

* feat: change the text on the org visit button

* feat: initialize the dropdown menu

* feat: trigger the  modal

* feat: update the text in the model

* feat: tweak wording

* WIP/feat: hook up a route with an action that calls an organization delete worker.

* feat: redirect after showing the notice

* feat: update the authorization required to be super admin

* feat: add the notice to localization

* spec: integration test

* spec: fix

* spec: delete worker

* chore: update the link

* feat: add safe navigation

* feat: make sure that we show an error if the organization has credits

* fix: error message for modal unspent credits

* feat add the spec for the helper

* fix: remove rspec preface

* fix: small fixes to tests and I18n

* fix: updated the number of orgs

* feat: update the message

* feat: update the message

* chore: remove inclusion of helper

* feat: change the name of the parameter

* chore: newline
2023-07-17 12:09:24 +02:00

47 lines
1.4 KiB
Ruby

module Organizations
class DeleteWorker
include Sidekiq::Job
sidekiq_options queue: :high_priority, retry: 10
# operator_id - the user who deletes the organization
# deleted_by_org_admin - the organization can be deleted by either
# the admin of an organization or by the Forem Admin.
def perform(organization_id, operator_id, deleted_by_org_admin)
org = Organization.find_by(id: organization_id)
return unless org
user = User.find_by(id: operator_id)
return unless user
Organizations::Delete.call(org)
if deleted_by_org_admin
user.touch(:organization_info_updated_at)
EdgeCache::BustUser.call(user)
NotifyMailer.with(name: user.name, org_name: org.name, email: user.email).organization_deleted_email.deliver_now
end
audit_log(org, user)
rescue StandardError => e
ForemStatsClient.count("organizations.delete", 1,
tags: ["action:failed", "organization_id:#{org.id}", "user_id:#{user.id}"])
Honeybadger.context({ organization_id: org.id, user_id: user.id })
Honeybadger.notify(e)
end
def audit_log(org, user)
AuditLog.create(
user: user,
category: "user.organization.delete",
roles: user.roles_name,
slug: "organization_delete",
data: {
organization_id: org.id,
organization_slug: org.slug
},
)
end
end
end