Skip to content

Commit

Permalink
Merge pull request #908 from bakaphp/KA-77
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken authored Feb 9, 2024
2 parents dff741f + 10ba246 commit 205fe9d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Kanvas\Companies\Actions\UpdateCompaniesAction;
use Kanvas\Companies\DataTransferObject\CompaniesPostData;
use Kanvas\Companies\DataTransferObject\CompaniesPutData;
use Kanvas\Companies\Jobs\DeleteCompanyJob;
use Kanvas\Companies\Models\Companies;
use Kanvas\Companies\Models\CompaniesBranches;
use Kanvas\Companies\Repositories\CompaniesRepository;
Expand Down Expand Up @@ -65,8 +66,7 @@ public function deleteCompany(mixed $root, array $request): bool
/**
* @todo only super admin can do this
*/
$companyDelete = new DeleteCompaniesAction(Auth::user());
$companyDelete->execute((int) $request['id']);
DeleteCompanyJob::dispatch((int) $request['id'], Auth::user());

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kanvas/Companies/Actions/DeleteCompaniesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function execute(int $id): bool
{
$companies = Companies::getById($id);

if (! $companies->isOwner($this->user)) {
if (! $companies->isOwner($this->user) && ! $this->user->isAdmin()) {
throw new AuthorizationException('User cant delete this company');
}

Expand Down
33 changes: 33 additions & 0 deletions src/Kanvas/Companies/Jobs/DeleteCompanyJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Kanvas\Companies\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Kanvas\Companies\Actions\DeleteCompaniesAction;
use Kanvas\Users\Models\Users;

class DeleteCompanyJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

public function __construct(
public int $companiesId,
public Users $user
) {
}

public function handle(): void
{
$companyDelete = new DeleteCompaniesAction($this->user);
$companyDelete->execute($this->companiesId);
}
}

0 comments on commit 205fe9d

Please sign in to comment.