Skip to content

Commit b095333

Browse files
Merge pull request #54109 from nextcloud/backport/53909/stable30
2 parents d7f7b6c + 3a76fb0 commit b095333

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,16 @@ public function addUser(
536536
throw new OCSException($this->l10n->t('Required email address was not provided'), 110);
537537
}
538538

539+
// Create the user
539540
try {
540541
$newUser = $this->userManager->createUser($userid, $password);
541-
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
542+
if (!$newUser instanceof IUser) {
543+
// If the user is not an instance of IUser, it means the user creation failed
544+
$this->logger->error('Failed addUser attempt: User creation failed.', ['app' => 'ocs_api']);
545+
throw new OCSException($this->l10n->t('User creation failed'), 111);
546+
}
542547

548+
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
543549
foreach ($groups as $group) {
544550
$this->groupManager->get($group)->addUser($newUser);
545551
$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ public function testAddUserSuccessful() {
466466
$this->userManager
467467
->expects($this->once())
468468
->method('createUser')
469-
->with('NewUser', 'PasswordOfTheNewUser');
469+
->with('NewUser', 'PasswordOfTheNewUser')
470+
->willReturn($this->createMock(IUser::class));
470471
$this->logger
471472
->expects($this->once())
472473
->method('info')
@@ -529,7 +530,8 @@ public function testAddUserSuccessfulWithDisplayName() {
529530
$this->userManager
530531
->expects($this->once())
531532
->method('createUser')
532-
->with('NewUser', 'PasswordOfTheNewUser');
533+
->with('NewUser', 'PasswordOfTheNewUser')
534+
->willReturn($this->createMock(IUser::class));
533535
$this->logger
534536
->expects($this->once())
535537
->method('info')
@@ -579,7 +581,8 @@ public function testAddUserSuccessfulGenerateUserID() {
579581
$this->userManager
580582
->expects($this->once())
581583
->method('createUser')
582-
->with($this->anything(), 'PasswordOfTheNewUser');
584+
->with($this->anything(), 'PasswordOfTheNewUser')
585+
->willReturn($this->createMock(IUser::class));
583586
$this->logger
584587
->expects($this->once())
585588
->method('info')

0 commit comments

Comments
 (0)