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')
|
||||
->modalSubmitActionLabel('Invite')
|
||||
->successNotificationTitle(null)
|
||||
->failureNotificationTitle(null)
|
||||
->action(function (Action $action, array $data, SubuserCreationService $service) use ($server) {
|
||||
$email = strtolower($data['email']);
|
||||
|
||||
|
@ -38,7 +38,7 @@ class SubuserCreationService
|
||||
public function handle(Server $server, string $email, array $permissions): Subuser
|
||||
{
|
||||
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) {
|
||||
// Just cap the username generated at 64 characters at most and then append a random string
|
||||
// to the end to make it "unique"...
|
||||
@ -50,8 +50,7 @@ class SubuserCreationService
|
||||
'username' => $username,
|
||||
'root_admin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($server->owner_id === $user->id) {
|
||||
throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner'));
|
||||
}
|
||||
@ -60,6 +59,7 @@ class SubuserCreationService
|
||||
if ($subuserCount !== 0) {
|
||||
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
|
||||
}
|
||||
}
|
||||
|
||||
$cleanedPermissions = collect($permissions)
|
||||
->unique()
|
||||
@ -68,9 +68,11 @@ class SubuserCreationService
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$subuser = Subuser::query()->create([
|
||||
$subuser = Subuser::withoutGlobalScopes()->updateOrCreate([
|
||||
'user_id' => $user->id,
|
||||
'server_id' => $server->id,
|
||||
], [
|
||||
|
||||
'permissions' => $cleanedPermissions,
|
||||
]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user