Also clear the knownUser when changing via the settings endpoint
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
49f7d08b38
commit
490bfa7330
|
@ -42,6 +42,7 @@ use OC\AppFramework\Http;
|
||||||
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
||||||
use OC\ForbiddenException;
|
use OC\ForbiddenException;
|
||||||
use OC\Group\Manager as GroupManager;
|
use OC\Group\Manager as GroupManager;
|
||||||
|
use OC\KnownUser\KnownUserService;
|
||||||
use OC\L10N\Factory;
|
use OC\L10N\Factory;
|
||||||
use OC\Security\IdentityProof\Manager;
|
use OC\Security\IdentityProof\Manager;
|
||||||
use OC\User\Manager as UserManager;
|
use OC\User\Manager as UserManager;
|
||||||
|
@ -96,6 +97,8 @@ class UsersController extends Controller {
|
||||||
private $jobList;
|
private $jobList;
|
||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
private $encryptionManager;
|
private $encryptionManager;
|
||||||
|
/** @var KnownUserService */
|
||||||
|
private $knownUserService;
|
||||||
/** @var IEventDispatcher */
|
/** @var IEventDispatcher */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@ class UsersController extends Controller {
|
||||||
Manager $keyManager,
|
Manager $keyManager,
|
||||||
IJobList $jobList,
|
IJobList $jobList,
|
||||||
IManager $encryptionManager,
|
IManager $encryptionManager,
|
||||||
|
KnownUserService $knownUserService,
|
||||||
IEventDispatcher $dispatcher
|
IEventDispatcher $dispatcher
|
||||||
) {
|
) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
|
@ -132,6 +136,7 @@ class UsersController extends Controller {
|
||||||
$this->keyManager = $keyManager;
|
$this->keyManager = $keyManager;
|
||||||
$this->jobList = $jobList;
|
$this->jobList = $jobList;
|
||||||
$this->encryptionManager = $encryptionManager;
|
$this->encryptionManager = $encryptionManager;
|
||||||
|
$this->knownUserService = $knownUserService;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,6 +368,19 @@ class UsersController extends Controller {
|
||||||
?string $twitter = null,
|
?string $twitter = null,
|
||||||
?string $twitterScope = null
|
?string $twitterScope = null
|
||||||
) {
|
) {
|
||||||
|
$user = $this->userSession->getUser();
|
||||||
|
if (!$user instanceof IUser) {
|
||||||
|
return new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => $this->l10n->t('Invalid user')
|
||||||
|
]
|
||||||
|
],
|
||||||
|
Http::STATUS_UNAUTHORIZED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$email = strtolower($email);
|
$email = strtolower($email);
|
||||||
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
|
@ -375,8 +393,9 @@ class UsersController extends Controller {
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$user = $this->userSession->getUser();
|
|
||||||
$data = $this->accountManager->getUser($user);
|
$data = $this->accountManager->getUser($user);
|
||||||
|
$beforeData = $data;
|
||||||
$data[IAccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
|
$data[IAccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
|
||||||
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
||||||
$data[IAccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
|
$data[IAccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
|
||||||
|
@ -393,6 +412,9 @@ class UsersController extends Controller {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$data = $this->saveUserSettings($user, $data);
|
$data = $this->saveUserSettings($user, $data);
|
||||||
|
if ($beforeData[IAccountManager::PROPERTY_PHONE]['value'] !== $data[IAccountManager::PROPERTY_PHONE]['value']) {
|
||||||
|
$this->knownUserService->deleteKnownUser($user->getUID());
|
||||||
|
}
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
[
|
[
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace OCA\Settings\Tests\Controller;
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
||||||
use OC\Group\Manager;
|
use OC\Group\Manager;
|
||||||
|
use OC\KnownUser\KnownUserService;
|
||||||
use OCA\Settings\Controller\UsersController;
|
use OCA\Settings\Controller\UsersController;
|
||||||
use OCP\Accounts\IAccountManager;
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
|
@ -91,6 +92,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
private $securityManager;
|
private $securityManager;
|
||||||
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $encryptionManager;
|
private $encryptionManager;
|
||||||
|
/** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
private $knownUserService;
|
||||||
/** @var IEncryptionModule | \PHPUnit\Framework\MockObject\MockObject */
|
/** @var IEncryptionModule | \PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $encryptionModule;
|
private $encryptionModule;
|
||||||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
@ -111,6 +114,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock();
|
$this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock();
|
||||||
$this->jobList = $this->createMock(IJobList::class);
|
$this->jobList = $this->createMock(IJobList::class);
|
||||||
$this->encryptionManager = $this->createMock(IManager::class);
|
$this->encryptionManager = $this->createMock(IManager::class);
|
||||||
|
$this->knownUserService = $this->createMock(KnownUserService::class);
|
||||||
$this->dispatcher = $this->createMock(IEventDispatcher::class);
|
$this->dispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
|
|
||||||
$this->l->method('t')
|
$this->l->method('t')
|
||||||
|
@ -147,6 +151,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$this->securityManager,
|
$this->securityManager,
|
||||||
$this->jobList,
|
$this->jobList,
|
||||||
$this->encryptionManager,
|
$this->encryptionManager,
|
||||||
|
$this->knownUserService,
|
||||||
$this->dispatcher
|
$this->dispatcher
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -168,6 +173,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$this->securityManager,
|
$this->securityManager,
|
||||||
$this->jobList,
|
$this->jobList,
|
||||||
$this->encryptionManager,
|
$this->encryptionManager,
|
||||||
|
$this->knownUserService,
|
||||||
$this->dispatcher
|
$this->dispatcher
|
||||||
]
|
]
|
||||||
)->setMethods($mockedMethods)->getMock();
|
)->setMethods($mockedMethods)->getMock();
|
||||||
|
|
Loading…
Reference in New Issue