-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user and organization deletion system; Added coverage annotations
- Loading branch information
Showing
65 changed files
with
2,651 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ APP_URL=https://solidtime.test | |
|
||
SUPER_ADMINS=[email protected] | ||
|
||
LOG_CHANNEL=stack | ||
LOG_DEPRECATIONS_CHANNEL=null | ||
LOG_CHANNEL=single | ||
LOG_DEPRECATIONS_CHANNEL=deprecation | ||
LOG_LEVEL=debug | ||
|
||
DB_CONNECTION=pgsql | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ yarn-error.log | |
/k8s | ||
/_ide_helper.php | ||
/.phpstorm.meta.php | ||
/.rnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Jetstream; | ||
|
||
use App\Models\Organization; | ||
use App\Models\User; | ||
use App\Service\PermissionStore; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
|
||
class ValidateOrganizationDeletion | ||
{ | ||
/** | ||
* Validate that the team can be deleted by the given user. | ||
* | ||
* @param User $user Authenticated user | ||
* @param Organization $organization Organization to be deleted | ||
* | ||
* @throws AuthorizationException | ||
*/ | ||
public function validate(User $user, Organization $organization): void | ||
{ | ||
if (! app(PermissionStore::class)->userHas($organization, $user, 'organizations:delete')) { | ||
throw new AuthorizationException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands\Admin; | ||
|
||
use App\Models\Organization; | ||
use App\Service\DeletionService; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Str; | ||
|
||
class DeleteOrganizationCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'admin:delete-organization | ||
{ organization : The ID of the organization to delete }'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete a organization.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(DeletionService $deletionService): int | ||
{ | ||
$organizationId = $this->argument('organization'); | ||
|
||
if (! Str::isUuid($organizationId)) { | ||
$this->error('Organization ID must be a valid UUID.'); | ||
|
||
return self::FAILURE; | ||
|
||
} | ||
|
||
/** @var Organization|null $organization */ | ||
$organization = Organization::find($organizationId); | ||
if ($organization === null) { | ||
$this->error('Organization with ID '.$organizationId.' not found.'); | ||
|
||
return self::FAILURE; | ||
} | ||
|
||
$this->info('Deleting organization with ID '.$organization->getKey()); | ||
|
||
$deletionService->deleteOrganization($organization); | ||
|
||
$this->info('Organization with ID '.$organization->getKey().' has been deleted.'); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Organization; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
|
||
class BeforeOrganizationDeletion | ||
{ | ||
use Dispatchable; | ||
|
||
public Organization $organization; | ||
|
||
public function __construct(Organization $organization) | ||
{ | ||
$this->organization = $organization; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/Exceptions/Api/CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions\Api; | ||
|
||
class CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers extends ApiException | ||
{ | ||
public const string KEY = 'can_not_delete_user_who_is_owner_of_organization_with_multiple_members'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/Filament/Resources/OrganizationResource/Actions/DeleteOrganization.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\OrganizationResource\Actions; | ||
|
||
use App\Exceptions\Api\ApiException; | ||
use App\Models\Organization; | ||
use App\Service\DeletionService; | ||
use Filament\Actions\DeleteAction; | ||
use Throwable; | ||
|
||
class DeleteOrganization extends DeleteAction | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
// TODO: check why setting the icon is necessary | ||
$this->icon('heroicon-m-trash'); | ||
$this->action(function (): void { | ||
$result = $this->process(function (Organization $record): bool { | ||
try { | ||
$deletionService = app(DeletionService::class); | ||
$deletionService->deleteOrganization($record); | ||
|
||
return true; | ||
} catch (ApiException $exception) { | ||
$this->failureNotificationTitle($exception->getTranslatedMessage()); | ||
report($exception); | ||
} catch (Throwable $exception) { | ||
$this->failureNotificationTitle(__('exceptions.unknown_error_in_admin_panel')); | ||
report($exception); | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
if (! $result) { | ||
$this->failure(); | ||
|
||
return; | ||
} | ||
|
||
$this->success(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/Filament/Resources/UserResource/Actions/DeleteUser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\UserResource\Actions; | ||
|
||
use App\Exceptions\Api\ApiException; | ||
use App\Models\User; | ||
use App\Service\DeletionService; | ||
use Filament\Actions\DeleteAction; | ||
use Throwable; | ||
|
||
class DeleteUser extends DeleteAction | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->icon('heroicon-m-trash'); | ||
$this->action(function (): void { | ||
$result = $this->process(function (User $record): bool { | ||
try { | ||
$deletionService = app(DeletionService::class); | ||
$deletionService->deleteUser($record); | ||
|
||
return true; | ||
} catch (ApiException $exception) { | ||
$this->failureNotificationTitle($exception->getTranslatedMessage()); | ||
report($exception); | ||
} catch (Throwable $exception) { | ||
$this->failureNotificationTitle(__('exceptions.unknown_error_in_admin_panel')); | ||
report($exception); | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
if (! $result) { | ||
$this->failure(); | ||
|
||
return; | ||
} | ||
|
||
$this->success(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.