mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Restrict removing owner from organization
This commit is contained in:
10
app/Exceptions/Api/CanNotRemoveOwnerFromOrganization.php
Normal file
10
app/Exceptions/Api/CanNotRemoveOwnerFromOrganization.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exceptions\Api;
|
||||
|
||||
class CanNotRemoveOwnerFromOrganization extends ApiException
|
||||
{
|
||||
public const string KEY = 'can_not_remove_owner_from_organization';
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Exceptions\Api\CanNotRemoveOwnerFromOrganization;
|
||||
use App\Exceptions\Api\EntityStillInUseApiException;
|
||||
use App\Exceptions\Api\UserNotPlaceholderApiException;
|
||||
use App\Http\Requests\V1\Member\MemberIndexRequest;
|
||||
@@ -72,7 +73,7 @@ class MemberController extends Controller
|
||||
/**
|
||||
* Remove a member of the organization.
|
||||
*
|
||||
* @throws AuthorizationException|EntityStillInUseApiException
|
||||
* @throws AuthorizationException|EntityStillInUseApiException|CanNotRemoveOwnerFromOrganization
|
||||
*
|
||||
* @operationId removeMember
|
||||
*/
|
||||
@@ -86,6 +87,9 @@ class MemberController extends Controller
|
||||
if (ProjectMember::query()->whereBelongsToOrganization($organization)->where('user_id', $member->user_id)->exists()) {
|
||||
throw new EntityStillInUseApiException('member', 'project_member');
|
||||
}
|
||||
if ($member->role === Role::Owner->value) {
|
||||
throw new CanNotRemoveOwnerFromOrganization();
|
||||
}
|
||||
|
||||
$member->delete();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user