feat: Account deletion with deleteObjectJob (#6885)
Fixes: https://linear.app/chatwoot/issue/CW-1365/allow-super-admin-to-delete-an-account Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
parent
2731c2a5be
commit
d45512df72
@ -47,4 +47,11 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController
|
|||||||
Internal::SeedAccountJob.perform_later(requested_resource)
|
Internal::SeedAccountJob.perform_later(requested_resource)
|
||||||
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered')
|
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
account = Account.find(params[:id])
|
||||||
|
|
||||||
|
DeleteObjectJob.perform_later(account) if account.present?
|
||||||
|
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account deletion is in progress.')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -387,7 +387,7 @@ Rails.application.routes.draw do
|
|||||||
resource :app_config, only: [:show, :create]
|
resource :app_config, only: [:show, :create]
|
||||||
|
|
||||||
# order of resources affect the order of sidebar navigation in super admin
|
# order of resources affect the order of sidebar navigation in super admin
|
||||||
resources :accounts, only: [:index, :new, :create, :show, :edit, :update] do
|
resources :accounts, only: [:index, :new, :create, :show, :edit, :update, :destroy] do
|
||||||
post :seed, on: :member
|
post :seed, on: :member
|
||||||
end
|
end
|
||||||
resources :users, only: [:index, :new, :create, :show, :edit, :update, :destroy]
|
resources :users, only: [:index, :new, :create, :show, :edit, :update, :destroy]
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'Super Admin accounts API', type: :request do
|
RSpec.describe 'Super Admin accounts API', type: :request do
|
||||||
let(:super_admin) { create(:super_admin) }
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
|
let!(:super_admin) { create(:super_admin) }
|
||||||
|
let!(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /super_admin/accounts' do
|
describe 'GET /super_admin/accounts' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
@ -23,4 +26,26 @@ RSpec.describe 'Super Admin accounts API', type: :request do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'DELETE /super_admin/accounts/{account_id}' do
|
||||||
|
context 'when it is an unauthenticated user' do
|
||||||
|
it 'returns unauthorized' do
|
||||||
|
delete "/super_admin/accounts/#{account.id}"
|
||||||
|
expect(response).to have_http_status(:redirect)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when it is an authenticated user' do
|
||||||
|
it 'Deletes the account' do
|
||||||
|
total_accounts = Account.count
|
||||||
|
sign_in(super_admin, scope: :super_admin)
|
||||||
|
|
||||||
|
perform_enqueued_jobs(only: DeleteObjectJob) do
|
||||||
|
delete "/super_admin/accounts/#{account.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Account.count).to eq(total_accounts - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user