diff --git a/lib/Controller/UsersController.php b/lib/Controller/UsersController.php index 2d75edb..1f9a99e 100644 --- a/lib/Controller/UsersController.php +++ b/lib/Controller/UsersController.php @@ -32,6 +32,8 @@ namespace OCA\UserManagement\Controller; use OC\AppFramework\Http; +use OC\User\Service\CreateUser; +use OC\User\Service\SigninWithEmail; use OC\User\User; use OCA\UserManagement\Exception\InvalidUserTokenException; use OCA\UserManagement\Exception\UserTokenException; @@ -56,6 +58,9 @@ use OCP\Mail\IMailer; use OCP\IAvatarManager; use OCP\Security\ISecureRandom; +use OCP\User\Exceptions\CannotCreateUserException; +use OCP\User\Exceptions\InvalidEmailException; +use OCP\User\Exceptions\UserAlreadyExistsException; use OCP\Util; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -69,6 +74,7 @@ class UsersController extends Controller { private $l10n; /** @var IUserSession */ private $userSession; + private $createUser; /** @var bool */ private $isAdmin; /** @var IUserManager */ @@ -125,6 +131,7 @@ public function __construct($appName, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession, + CreateUser $createUser, IConfig $config, ISecureRandom $secureRandom, IL10N $l10n, @@ -140,6 +147,7 @@ public function __construct($appName, $this->userManager = $userManager; $this->groupManager = $groupManager; $this->userSession = $userSession; + $this->createUser = $createUser; $this->config = $config; $this->l10n = $l10n; $this->secureRandom = $secureRandom; @@ -353,40 +361,6 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe return new DataResponse($users); } - /** - * @param string $userId - * @param string $email - */ - private function generateTokenAndSendMail($userId, $email) { - $token = $this->secureRandom->generate(21, - ISecureRandom::CHAR_DIGITS, - ISecureRandom::CHAR_LOWER, ISecureRandom::CHAR_UPPER); - $this->config->setUserValue($userId, 'owncloud', - 'lostpassword', $this->timeFactory->getTime() . ':' . $token); - - // data for the mail template - $mailData = [ - 'username' => $userId, - 'url' => $this->urlGenerator->linkToRouteAbsolute('user_management.Users.setPasswordForm', ['userId' => $userId, 'token' => $token]) - ]; - - $mail = new TemplateResponse('user_management', 'new_user/email-html', $mailData, 'blank'); - $mailContent = $mail->render(); - - $mail = new TemplateResponse('user_management', 'new_user/email-plain_text', $mailData, 'blank'); - $plainTextMailContent = $mail->render(); - - $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]); - - $message = $this->mailer->createMessage(); - $message->setTo([$email => $userId]); - $message->setSubject($subject); - $message->setHtmlBody($mailContent); - $message->setPlainBody($plainTextMailContent); - $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]); - $this->mailer->send($message); - } - /** * @NoAdminRequired * @@ -397,329 +371,37 @@ private function generateTokenAndSendMail($userId, $email) { * @return DataResponse */ public function create($username, $password, array $groups= [], $email='') { - if ($email !== '' && !$this->mailer->validateMailAddress($email)) { - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Invalid mail address') - ], - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - $currentUser = $this->userSession->getUser(); - - if (!$this->isAdmin) { - if (!empty($groups)) { - foreach ($groups as $key => $group) { - $groupObject = $this->groupManager->get($group); - if ($groupObject === null) { - unset($groups[$key]); - continue; - } - - if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { - unset($groups[$key]); - } - } - } - - if (empty($groups)) { - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($currentUser); - // New class returns IGroup[] so convert back - $gids = []; - foreach ($groups as $group) { - $gids[] = $group->getGID(); - } - $groups = $gids; - } - } - - if ($this->userManager->userExists($username)) { - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('A user with that name already exists.') - ], - Http::STATUS_CONFLICT - ); - } - try { - if (($password === '') && ($email !== '')) { - /** - * Generate a random password as we are going to have this - * use one time. The new user has to reset it using the link - * from email. - */ - $event = new GenericEvent(); - $this->eventDispatcher->dispatch('OCP\User::createPassword', $event); - if ($event->hasArgument('password')) { - $password = $event->getArgument('password'); - } else { - $password = $this->secureRandom->generate(20); - } - } - $user = $this->userManager->createUser($username, $password); - } catch (\Exception $exception) { - $message = $exception->getMessage(); - if (!$message) { - $message = $this->l10n->t('Unable to create user.'); + $user = $this->createUser->createUser($username, $password, $groups, $email); + if ($user instanceof User) { + $userGroups = $this->groupManager->getUserGroupIds($user); + return new DataResponse( + $this->formatUserForIndex($user, $userGroups), + Http::STATUS_CREATED + ); } + } catch (CannotCreateUserException $e) { return new DataResponse( [ - 'message' => (string) $message, + 'message' => (string)$this->l10n->t($e->getMessage()) ], Http::STATUS_FORBIDDEN ); - } - - if ($user instanceof User) { - if ($groups !== null) { - foreach ($groups as $groupName) { - $group = $this->groupManager->get($groupName); - - if (empty($group)) { - $group = $this->groupManager->createGroup($groupName); - } - $group->addUser($user); - } - } - /** - * Send new user mail only if a mail is set - */ - if ($email !== '') { - $user->setEMailAddress($email); - try { - $this->generateTokenAndSendMail($username, $email); - } catch (\Exception $e) { - $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), ['app' => 'settings']); - } - } - // fetch users groups - $userGroups = $this->groupManager->getUserGroupIds($user); - + } catch (InvalidEmailException $e) { return new DataResponse( - $this->formatUserForIndex($user, $userGroups), - Http::STATUS_CREATED - ); - } - - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Unable to create user.') - ], - Http::STATUS_FORBIDDEN - ); - } - - /** - * Set password for user using link - * - * @PublicPage - * @NoCSRFRequired - * @NoAdminRequired - * @NoSubadminRequired - * - * @param string $token - * @param string $userId - * @return TemplateResponse - */ - public function setPasswordForm($token, $userId) { - try { - $this->checkPasswordSetToken($token, $userId); - } catch (UserTokenException $e) { - if ($e instanceof UserTokenExpiredException) { - return new TemplateResponse( - 'user_management', 'new_user/resendtokenbymail', - [ - 'link' => $this->urlGenerator->linkToRouteAbsolute('user_management.Users.resendToken', ['userId' => $userId]) - ], 'guest' - ); - } - $this->log->logException($e, ['app' => 'user_management']); - return new TemplateResponse( - 'core', 'error', [ - "errors" => [["error" => $e->getMessage()]] - ], 'guest' - ); - } - - return new TemplateResponse( - 'user_management', 'new_user/setpassword', - [ - 'link' => $this->urlGenerator->linkToRouteAbsolute('user_management.Users.setPassword', ['userId' => $userId, 'token' => $token]) - ], 'guest' - ); - } - - /** - * @param string $token - * @param string $userId - * @return null - * @throws InvalidUserTokenException - * @throws UserTokenExpiredException - * @throws UserTokenMismatchException - */ - private function checkPasswordSetToken($token, $userId) { - $user = $this->userManager->get($userId); - - $splittedToken = \explode(':', $this->config->getUserValue($userId, 'owncloud', 'lostpassword', null)); - if (\count($splittedToken) !== 2) { - $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword'); - throw new InvalidUserTokenException($this->l10n->t('The token provided is invalid.')); - } - - //The value 43200 = 60*60*12 = 1/2 day - if ($splittedToken[0] < ($this->timeFactory->getTime() - (int)$this->config->getAppValue('user_management', 'token_expire_time', '43200')) || - $user->getLastLogin() > $splittedToken[0]) { - $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword'); - throw new UserTokenExpiredException($this->l10n->t('The token provided had expired.')); - } - - if (!\hash_equals($splittedToken[1], $token)) { - throw new UserTokenMismatchException($this->l10n->t('The token provided is invalid.')); - } - } - - /** - * @PublicPage - * @NoCSRFRequired - * @NoAdminRequired - * @NoSubadminRequired - * - * @param $userId - * @return TemplateResponse - */ - public function resendToken($userId) { - $user = $this->userManager->get($userId); - - if ($user === null) { - $this->log->error('User: ' . $userId . ' does not exist', ['app' => 'user_management']); - return new TemplateResponse( - 'core', 'error', - [ - "errors" => [["error" => $this->l10n->t('Failed to create activation link. Please contact your administrator.')]] + 'message' => (string)$this->l10n->t($e->getMessage()) ], - 'guest' + Http::STATUS_UNPROCESSABLE_ENTITY ); - } - - if ($user->getEMailAddress() === null) { - $this->log->error('Email address not set for: ' . $userId, ['app' => 'user_management']); - return new TemplateResponse( - 'core', 'error', + } catch (UserAlreadyExistsException $e) { + return new DataResponse( [ - "errors" => [["error" => $this->l10n->t('Failed to create activation link. Please contact your administrator.', [$userId])]] + 'message' => (string)$this->l10n->t($e->getMessage()) ], - 'guest' - ); - } - - try { - $this->generateTokenAndSendMail($user->getUID(), $user->getEMailAddress()); - } catch (\Exception $e) { - $this->log->error("Can't send new user mail to " . $user->getEMailAddress() . ": " . $e->getMessage(), ['app' => 'user_management']); - return new TemplateResponse( - 'core', 'error', - [ - "errors" => [[ - "error" => $this->l10n->t('Can\'t send email to the user. Contact your administrator.')]] - ], 'guest' - ); - } - - return new TemplateResponse( - 'user_management', 'new_user/tokensendnotify', [], 'guest' - ); - } - - /** - * @PublicPage - * @NoAdminRequired - * @NoSubadminRequired - * @NoCSRFRequired - * - * @param $token - * @param $userId - * @param $password - * @return JSONResponse - */ - public function setPassword($token, $userId, $password) { - $user = $this->userManager->get($userId); - - if ($user === null) { - $this->log->error('User: ' . $userId . ' does not exist.', ['app' => 'user_management']); - return new JSONResponse( - [ - 'status' => 'error', - 'message' => $this->l10n->t('Failed to set password. Please contact the administrator.', [$userId]), - 'type' => 'usererror' - ], Http::STATUS_NOT_FOUND - ); - } - - try { - $this->checkPasswordSetToken($token, $userId); - - if (!$user->setPassword($password)) { - $this->log->error('The password can not be set for user: '. $userId); - return new JSONResponse( - [ - 'status' => 'error', - 'message' => $this->l10n->t('Failed to set password. Please contact your administrator.', [$userId]), - 'type' => 'passwordsetfailed' - ], Http::STATUS_FORBIDDEN - ); - } - - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); - \OC_User::unsetMagicInCookie(); - } catch (UserTokenException $e) { - $this->log->logException($e, ['app' => 'user_management']); - return new JSONResponse( - [ - 'status' => 'error', - 'message' => $e->getMessage(), - 'type' => 'tokenfailure' - ], Http::STATUS_UNAUTHORIZED - ); - } - - try { - $this->sendNotificationMail($userId); - } catch (\Exception $e) { - $this->log->logException($e, ['app' => 'user_management']); - return new JSONResponse( - [ - 'status' => 'error', - 'message' => $this->l10n->t('Failed to send email. Please contact your administrator.'), - 'type' => 'emailsendfailed' - ], Http::STATUS_INTERNAL_SERVER_ERROR + Http::STATUS_CONFLICT ); } - - return new JSONResponse(['status' => 'success']); - } - - /** - * @param $userId - * @throws \Exception - */ - protected function sendNotificationMail($userId) { - $user = $this->userManager->get($userId); - $email = $user->getEMailAddress(); - - if ($email !== '') { - $tmpl = new \OC_Template('core', 'lostpassword/notify'); - $msg = $tmpl->fetchPage(); - - $message = $this->mailer->createMessage(); - $message->setTo([$email => $userId]); - $message->setSubject($this->l10n->t('%s password changed successfully', [$this->defaults->getName()])); - $message->setPlainBody($msg); - $message->setFrom([$email => $this->defaults->getName()]); - $this->mailer->send($message); - } } /** @@ -1187,6 +869,7 @@ private function isAdmin() { if ($activeUser !== null) { return $this->groupManager->isAdmin($activeUser->getUID()); } + \OC::$CLI; return false; } } diff --git a/templates/new_user/email-html.php b/templates/new_user/email-html.php deleted file mode 100644 index 716755d..0000000 --- a/templates/new_user/email-html.php +++ /dev/null @@ -1,36 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - -
  - <?php p($theme->getName()); ?> -
 
  - t('Hey there,

just letting you know that you now have an %s account.

Your username: %s
Please set the password by accessing it: Here

', [$theme->getName(), $_['username'], $_['url']])); - - // TRANSLATORS term at the end of a mail - p($l->t('Cheers!')); - ?> -
 
 --
- getName()); ?> - - getSlogan()); ?> -
getBaseUrl());?> -
 
-
diff --git a/templates/new_user/email-plain_text.php b/templates/new_user/email-plain_text.php deleted file mode 100644 index 21daeed..0000000 --- a/templates/new_user/email-plain_text.php +++ /dev/null @@ -1,10 +0,0 @@ -t("Hey there,\n\njust letting you know that you now have an %s account.\n\nYour username: %s\nAccess it: %s\n\n", [$theme->getName(), $_['username'], $_['url']])); - -// TRANSLATORS term at the end of a mail -p($l->t("Cheers!")); -?> - - -- -getName() . ' - ' . $theme->getSlogan()); ?> -getBaseUrl()); diff --git a/templates/new_user/resendtokenbymail.php b/templates/new_user/resendtokenbymail.php deleted file mode 100644 index 0c6bedb..0000000 --- a/templates/new_user/resendtokenbymail.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * @copyright Copyright (c) 2018, ownCloud GmbH - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -?> - -
-
-

- -

- -
-
diff --git a/templates/new_user/setpassword.php b/templates/new_user/setpassword.php deleted file mode 100644 index c2e0798..0000000 --- a/templates/new_user/setpassword.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * @copyright Copyright (c) 2018, ownCloud GmbH - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ -style('user_management', 'setpassword'); -script('user_management', 'setpassword'); -?> - - -
-
-

- - -

- -
-
diff --git a/templates/new_user/tokensendnotify.php b/templates/new_user/tokensendnotify.php deleted file mode 100644 index 1317674..0000000 --- a/templates/new_user/tokensendnotify.php +++ /dev/null @@ -1,2 +0,0 @@ -t('Activation link was sent to an email address, if one was configured.')); diff --git a/tests/unit/UsersControllerTest.php b/tests/unit/UsersControllerTest.php index a5cb4a1..c241230 100644 --- a/tests/unit/UsersControllerTest.php +++ b/tests/unit/UsersControllerTest.php @@ -10,6 +10,7 @@ namespace OCA\UserManagement\Test\Unit; +use OC\User\Service\SigninWithEmail; use OCA\UserManagement\Controller\UsersController; use OCA\UserManagement\Exception\UserTokenException; use OCP\AppFramework\Http; @@ -80,6 +81,8 @@ class UsersControllerTest extends TestCase { private $request; /** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */ private $eventDispatcher; + /** @var SigninWithEmail | \PHPUnit_Framework_MockObject_MockObject */ + private $signinWithEmail; protected function setUp() { $this->groupManager = $this->getMockBuilder(Manager::class) @@ -140,6 +143,10 @@ protected function setUp() { $this->request = $this->createMock(IRequest::class); $this->eventDispatcher = $this->createMock(EventDispatcher::class); + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); } public function testIndexAdmin() { @@ -1059,7 +1066,31 @@ public function testCreateSuccessfulWithoutGroupSubAdmin() { ], Http::STATUS_CREATED ); - $response = $this->createController()->create('foo', 'password'); + + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $usersController = new UsersController( + 'user_management', + $this->request, + $this->userManager, + $this->groupManager, + $this->userSession, + $this->signinWithEmail, + $this->config, + $this->secureRandom, + $this->l10N, + $this->logger, + $this->defaults, + $this->mailer, + $this->timeFactory, + $this->urlGenerator, + $this->appManager, + $this->avatarManager, + $this->eventDispatcher + ); + $response = $usersController->create('foo', 'password'); $this->assertEquals($expectedResponse, $response); } @@ -1161,6 +1192,7 @@ public function testCreateSuccessfulWithGroupAdmin() { } public function testCreateSuccessfulWithGroupSubAdmin() { + $this->invokePrivate($this->signinWithEmail, 'isAdmin', []); $this->groupManager ->expects($this->any()) ->method('isAdmin') @@ -1204,7 +1236,10 @@ public function testCreateSuccessfulWithGroupSubAdmin() { ->expects($this->once()) ->method('createUser') ->will($this->returnValue($newUser)); - $this->groupManager + $this->groupManager->expects($this->any()) + ->method('get') + ->willReturn($subGroup1); + /*$this->groupManager ->expects($this->at(1)) ->method('get') ->with('SubGroup1') @@ -1213,7 +1248,7 @@ public function testCreateSuccessfulWithGroupSubAdmin() { ->expects($this->at(5)) ->method('get') ->with('SubGroup1') - ->will($this->returnValue($subGroup1)); + ->will($this->returnValue($subGroup1));*/ $this->groupManager ->expects($this->once()) ->method('getUserGroupIds') @@ -1228,14 +1263,20 @@ public function testCreateSuccessfulWithGroupSubAdmin() { $subadmin = $this->getMockBuilder(SubAdmin::class) ->disableOriginalConstructor() ->getMock(); - $subadmin->expects($this->at(1)) + $subadmin->expects($this->any()) + ->method('getSubAdminsGroups') + ->willReturnMap([ + [$user, [$subGroup1]], + [$newUser, []], + ]); + /*$subadmin->expects($this->at(1)) ->method('getSubAdminsGroups') ->with($user) ->will($this->returnValue([$subGroup1])); $subadmin->expects($this->at(2)) ->method('getSubAdminsGroups') ->with($newUser) - ->will($this->returnValue([])); + ->will($this->returnValue([]));*/ $this->groupManager ->expects($this->any()) ->method('getSubAdmin') @@ -1258,7 +1299,31 @@ public function testCreateSuccessfulWithGroupSubAdmin() { ], Http::STATUS_CREATED ); - $response = $this->createController()->create('foo', 'password', ['SubGroup1', 'ExistingGroup']); + + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $usersController = new UsersController( + 'user_management', + $this->request, + $this->userManager, + $this->groupManager, + $this->userSession, + $this->signinWithEmail, + $this->config, + $this->secureRandom, + $this->l10N, + $this->logger, + $this->defaults, + $this->mailer, + $this->timeFactory, + $this->urlGenerator, + $this->appManager, + $this->avatarManager, + $this->eventDispatcher + ); + $response = $usersController->create('foo', 'password', ['SubGroup1', 'ExistingGroup']); $this->assertEquals($expectedResponse, $response); } @@ -1343,7 +1408,31 @@ public function testCreateUnsuccessfulSubAdmin() { ], Http::STATUS_FORBIDDEN ); - $response = $this->createController()->create('foo', 'password', []); + + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $usersController = new UsersController( + 'user_management', + $this->request, + $this->userManager, + $this->groupManager, + $this->userSession, + $this->signinWithEmail, + $this->config, + $this->secureRandom, + $this->l10N, + $this->logger, + $this->defaults, + $this->mailer, + $this->timeFactory, + $this->urlGenerator, + $this->appManager, + $this->avatarManager, + $this->eventDispatcher + ); + $response = $usersController->create('foo', 'password', []); $this->assertEquals($expectedResponse, $response); } @@ -2365,7 +2454,7 @@ public function testRestorePossibleWithoutEncryption() { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); - $result = self::invokePrivate($this->createController(), 'formatUserForIndex', [$user]); + $result = $this->signinWithEmail->formatUserForIndex($user); $this->assertEquals($expectedResult, $result); } @@ -2427,7 +2516,11 @@ public function testRestorePossibleWithAdminAndUserRestore() { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); - $result = self::invokePrivate($this->createController(), 'formatUserForIndex', [$user]); + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $result = $this->signinWithEmail->formatUserForIndex($user); $this->assertEquals($expectedResult, $result); } @@ -2470,7 +2563,11 @@ public function testRestoreNotPossibleWithoutAdminRestore() { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); - $result = self::invokePrivate($this->createController(), 'formatUserForIndex', [$user]); + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $result = $this->signinWithEmail->formatUserForIndex($user); $this->assertEquals($expectedResult, $result); } @@ -2534,7 +2631,11 @@ public function testRestoreNotPossibleWithoutUserRestore() { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); - $result = self::invokePrivate($this->createController(), 'formatUserForIndex', [$user]); + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $result = $this->signinWithEmail->formatUserForIndex($user); $this->assertEquals($expectedResult, $result); } @@ -2573,7 +2674,11 @@ public function testNoAvatar() { ->will($this->throwException(new \OCP\Files\NotFoundException())); $expectedResult['isAvatarAvailable'] = false; - $result = self::invokePrivate($this->createController(), 'formatUserForIndex', [$user]); + $this->signinWithEmail = new SigninWithEmail($this->userSession, $this->groupManager, + $this->urlGenerator, $this->userManager, $this->secureRandom, $this->defaults, + $this->timeFactory, $this->mailer, $this->l10N, $this->logger, $this->config, + $this->appManager, $this->avatarManager, $this->eventDispatcher); + $result = $this->signinWithEmail->formatUserForIndex($user); $this->assertEquals($expectedResult, $result); } @@ -2611,9 +2716,12 @@ public function testSetSelfEmailAddress($loginUser, $setUser, $emailAddress) { $appManager = $this->createMock(IAppManager::class); $iAvatarManager = $this->createMock(IAvatarManager::class); $eventDispatcher = $this->createMock(EventDispatcher::class); + $signinWithEmail = new SigninWithEmail($userSession, $groupManager, $urlGenerator, + $userManager, $iSecureRandom, $ocDefault, $iTimeFactory, $iMailer, $iL10, $iLogger, + $iConfig, $appManager, $iAvatarManager, $eventDispatcher); $userController = new UsersController($appName, $irequest, $userManager, $groupManager, - $userSession, $iConfig, $iSecureRandom, $iL10, $iLogger, $ocDefault, $iMailer, - $iTimeFactory, $urlGenerator, $appManager, $iAvatarManager, $eventDispatcher); + $userSession, $signinWithEmail, $iConfig, $iSecureRandom, $iL10, $iLogger, $ocDefault, + $iMailer, $iTimeFactory, $urlGenerator, $appManager, $iAvatarManager, $eventDispatcher); $iUser = $this->createMock(IUser::class); $userManager->method('get')->willReturn($iUser); @@ -2670,9 +2778,12 @@ public function testSetEmailAddressSendEmail($id, $mailaddress) { $appManager = $this->createMock(IAppManager::class); $iAvatarManager = $this->createMock(IAvatarManager::class); $eventDispatcher = $this->createMock(EventDispatcher::class); + $signinWithEmail = new SigninWithEmail($userSession, $groupManager, $urlGenerator, + $userManager, $iSecureRandom, $ocDefault, $iTimeFactory, $iMailer, $iL10, $iLogger, + $iConfig, $appManager, $iAvatarManager, $eventDispatcher); $userController = new UsersController($appName, $irequest, $userManager, $groupManager, - $userSession, $iConfig, $iSecureRandom, $iL10, $iLogger, $ocDefault, $iMailer, - $iTimeFactory, $urlGenerator, $appManager, $iAvatarManager, $eventDispatcher); + $userSession, $signinWithEmail, $iConfig, $iSecureRandom, $iL10, $iLogger, $ocDefault, + $iMailer, $iTimeFactory, $urlGenerator, $appManager, $iAvatarManager, $eventDispatcher); $iUser = $this->createMock(IUser::class); $iUser->expects($this->once()) @@ -3680,6 +3791,7 @@ private function createController() { $this->userManager, $this->groupManager, $this->userSession, + $this->signinWithEmail, $this->config, $this->secureRandom, $this->l10N,