File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff 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 ' ]);
Original file line number Diff line number Diff 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 ' )
You can’t perform that action at this time.
0 commit comments