Skip to content

Commit

Permalink
Bugfixes: update-command
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Sep 13, 2024
1 parent e788dd7 commit c0b8640
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions commands/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserController extends Controller
public function options($actionID): array
{
return match ($actionID) {
'create', 'createOrUpdate' => ['groupIds', 'organization', 'welcomeFile'],
'create', 'create-or-update' => ['groupIds', 'organization', 'welcomeFile'],
'update' => ['groupIds', 'organization', 'password'],
default => [],
};
Expand Down Expand Up @@ -184,8 +184,15 @@ public function updateUser(?User $user, ?string $organization, ?string $password
$user->changePassword($password);
}

$existingGroups = [];
foreach ($user->userGroups as $userGroup) {
$existingGroups[] = $userGroup->id;
}

foreach ($toUserGroups as $toUserGroup) {
$user->link('userGroups', $toUserGroup);
if (!in_array($toUserGroup->id, $existingGroups)) {
$user->link('userGroups', $toUserGroup);
}
}

$this->stdout('Updated the user: ' . $user->auth);
Expand Down

0 comments on commit c0b8640

Please sign in to comment.