fix(provisioning_api): catch failed user creation

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
skjnldsv 2025-07-11 09:17:45 +02:00 committed by John Molakvoæ
parent 19009b3620
commit 74d6494290
2 changed files with 13 additions and 4 deletions

View file

@ -542,10 +542,16 @@ class UsersController extends AUserDataOCSController {
throw new OCSException($this->l10n->t('Required email address was not provided'), 110);
}
// Create the user
try {
$newUser = $this->userManager->createUser($userid, $password);
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
if (!$newUser instanceof IUser) {
// If the user is not an instance of IUser, it means the user creation failed
$this->logger->error('Failed addUser attempt: User creation failed.', ['app' => 'ocs_api']);
throw new OCSException($this->l10n->t('User creation failed'), 111);
}
$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
foreach ($groups as $group) {
$this->groupManager->get($group)->addUser($newUser);
$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);

View file

@ -452,7 +452,8 @@ class UsersControllerTest extends TestCase {
$this->userManager
->expects($this->once())
->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser');
->with('NewUser', 'PasswordOfTheNewUser')
->willReturn($this->createMock(IUser::class));
$this->logger
->expects($this->once())
->method('info')
@ -517,7 +518,8 @@ class UsersControllerTest extends TestCase {
$this->userManager
->expects($this->once())
->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser');
->with('NewUser', 'PasswordOfTheNewUser')
->willReturn($this->createMock(IUser::class));
$this->logger
->expects($this->once())
->method('info')
@ -567,7 +569,8 @@ class UsersControllerTest extends TestCase {
$this->userManager
->expects($this->once())
->method('createUser')
->with($this->anything(), 'PasswordOfTheNewUser');
->with($this->anything(), 'PasswordOfTheNewUser')
->willReturn($this->createMock(IUser::class));
$this->logger
->expects($this->once())
->method('info')