Skip to content

Commit 304cc32

Browse files
committed
chore: make possible enable users when try to create group
Signed-off-by: Vitor Mattos <[email protected]>
1 parent a58d9d5 commit 304cc32

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/Controller/AdminGroupController.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ private function addSubAdmin(IUser $user, IGroup $group): void {
164164
}
165165

166166
private function createUser($userId, $displayName, $email): IUser {
167+
$user = $this->userManager->get($userId);
168+
if ($user instanceof IUser) {
169+
return $user;
170+
}
167171
$passwordEvent = new GenerateSecurePasswordEvent();
168172
$this->eventDispatcher->dispatchTyped($passwordEvent);
169173
$password = $passwordEvent->getPassword() ?? $this->secureRandom->generate(20);
@@ -194,15 +198,22 @@ private function addGroup(string $groupid, string $displayname = ''): IGroup {
194198
throw new OCSException('Invalid group name', 101);
195199
}
196200
// Check if it exists
197-
if ($this->groupManager->groupExists($groupid)) {
198-
throw new OCSException('group exists', 102);
201+
$group = $this->groupManager->get($groupid);
202+
if ($group instanceof IGroup) {
203+
$users = $group->getUsers();
204+
foreach ($users as $user) {
205+
$user->setEnabled(true);
206+
}
207+
} else {
208+
$group = $this->groupManager->createGroup($groupid);
199209
}
200-
$group = $this->groupManager->createGroup($groupid);
201210
if ($group === null) {
202211
throw new OCSException('Not supported by backend', 103);
203212
}
204213
if ($displayname !== '') {
205-
$group->setDisplayName($displayname);
214+
if ($group->getDisplayName() !== $displayname) {
215+
$group->setDisplayName($displayname);
216+
}
206217
}
207218
return $group;
208219
}

0 commit comments

Comments
 (0)