mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 15:34:44 +02:00
fix subuser creation
This commit is contained in:
parent
67ecdd9fb1
commit
4a550c291b
@ -383,6 +383,8 @@ class ListUsers extends ListRecords
|
|||||||
])
|
])
|
||||||
->modalHeading('Invite User')
|
->modalHeading('Invite User')
|
||||||
->modalSubmitActionLabel('Invite')
|
->modalSubmitActionLabel('Invite')
|
||||||
|
->successNotificationTitle(null)
|
||||||
|
->failureNotificationTitle(null)
|
||||||
->action(function (Action $action, array $data, SubuserCreationService $service) use ($server) {
|
->action(function (Action $action, array $data, SubuserCreationService $service) use ($server) {
|
||||||
$email = strtolower($data['email']);
|
$email = strtolower($data['email']);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class SubuserCreationService
|
|||||||
public function handle(Server $server, string $email, array $permissions): Subuser
|
public function handle(Server $server, string $email, array $permissions): Subuser
|
||||||
{
|
{
|
||||||
return $this->connection->transaction(function () use ($server, $email, $permissions) {
|
return $this->connection->transaction(function () use ($server, $email, $permissions) {
|
||||||
$user = User::query()->where('email', $email)->first();
|
$user = User::withoutGlobalScopes()->where('email', $email)->first();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
// Just cap the username generated at 64 characters at most and then append a random string
|
// Just cap the username generated at 64 characters at most and then append a random string
|
||||||
// to the end to make it "unique"...
|
// to the end to make it "unique"...
|
||||||
@ -50,15 +50,15 @@ class SubuserCreationService
|
|||||||
'username' => $username,
|
'username' => $username,
|
||||||
'root_admin' => false,
|
'root_admin' => false,
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
|
if ($server->owner_id === $user->id) {
|
||||||
|
throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($server->owner_id === $user->id) {
|
$subuserCount = $server->subusers()->where('user_id', $user->id)->count();
|
||||||
throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner'));
|
if ($subuserCount !== 0) {
|
||||||
}
|
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
|
||||||
|
}
|
||||||
$subuserCount = $server->subusers()->where('user_id', $user->id)->count();
|
|
||||||
if ($subuserCount !== 0) {
|
|
||||||
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cleanedPermissions = collect($permissions)
|
$cleanedPermissions = collect($permissions)
|
||||||
@ -68,9 +68,11 @@ class SubuserCreationService
|
|||||||
->values()
|
->values()
|
||||||
->all();
|
->all();
|
||||||
|
|
||||||
$subuser = Subuser::query()->create([
|
$subuser = Subuser::withoutGlobalScopes()->updateOrCreate([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
|
], [
|
||||||
|
|
||||||
'permissions' => $cleanedPermissions,
|
'permissions' => $cleanedPermissions,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user