Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use specific email getter where necessary
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Sep 9, 2021
commit 27865d03c014e3b644408c32967cc7e7a56bf692
7 changes: 2 additions & 5 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,13 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
if (!$allowEnumeration) {
if ($allowEnumerationFullMatch) {
$users = $this->userManager->getByEmail($value);
$users = \array_filter($users, static function (IUser $user) use ($value) {
return $user->getEMailAddress() === $value;
});
} else {
$users = [];
}
} else {
$users = $this->userManager->getByEmail($value);
$users = \array_filter($users, function (IUser $user) use ($currentUser, $value, $limitEnumerationPhone, $limitEnumerationGroup, $allowEnumerationFullMatch, $currentUserGroups) {
if ($allowEnumerationFullMatch && $user->getEMailAddress() === $value) {
if ($allowEnumerationFullMatch && $user->getSystemEMailAddress() === $value) {
return true;
}

Expand Down Expand Up @@ -516,7 +513,7 @@ protected function userToPrincipal($user) {
'{http://nextcloud.com/ns}language' => $this->languageFactory->getUserLanguage($user),
];

$email = $user->getEMailAddress();
$email = $user->getSystemEMailAddress();
if (!empty($email)) {
$principal['{http://sabredav.org/ns}email-address'] = $email;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/GroupPrincipalBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected function userToPrincipal($user) {
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
];

$email = $user->getEMailAddress();
$email = $user->getSystemEMailAddress();
if (!empty($email)) {
$principal['{http://sabredav.org/ns}email-address'] = $email;
}
Expand Down
34 changes: 17 additions & 17 deletions apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
->willReturn('Dr. Foo-Bar');
$fooUser
->expects($this->once())
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('');
$barUser = $this->createMock(User::class);
$barUser
Expand All @@ -129,7 +129,7 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
->willReturn('bar');
$barUser
->expects($this->once())
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$this->userManager
->expects($this->once())
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testGetPrincipalsByPathWithMail(): void {
$fooUser = $this->createMock(User::class);
$fooUser
->expects($this->once())
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$fooUser
->expects($this->once())
Expand Down Expand Up @@ -605,15 +605,15 @@ public function testSearchPrincipalWithEnumerationDisabledDisplayname(): void {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user2->method('getDisplayName')->willReturn('User 22');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user2->method('getDisplayName')->willReturn('User 222');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');

$this->userManager->expects($this->at(0))
->method('searchDisplayName')
Expand Down Expand Up @@ -665,20 +665,20 @@ public function testSearchPrincipalWithEnumerationDisabledEmail(): void {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user2->method('getDisplayName')->willReturn('User 22');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user2->method('getDisplayName')->willReturn('User 222');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');

$this->userManager->expects($this->at(0))
$this->userManager->expects($this->once())
->method('getByEmail')
->with('[email protected]')
->willReturn([$user2, $user3, $user4]);
->willReturn([$user2]);

$this->assertEquals(['principals/users/user2'], $this->connector->searchPrincipals('principals/users',
['{http://sabredav.org/ns}email-address' => '[email protected]']));
Expand Down Expand Up @@ -726,15 +726,15 @@ public function testSearchPrincipalWithEnumerationLimitedDisplayname(): void {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user3->method('getDisplayName')->willReturn('User 22');
$user3->method('getEMailAddress')->willReturn('[email protected]');
$user3->method('getSystemEMailAddress')->willReturn('[email protected]');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user4->method('getDisplayName')->willReturn('User 222');
$user4->method('getEMailAddress')->willReturn('[email protected]');
$user4->method('getSystemEMailAddress')->willReturn('[email protected]');


$this->userSession->expects($this->at(0))
Expand Down Expand Up @@ -787,15 +787,15 @@ public function testSearchPrincipalWithEnumerationLimitedMail(): void {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('[email protected]');
$user2->method('getSystemEMailAddress')->willReturn('[email protected]');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user3->method('getDisplayName')->willReturn('User 22');
$user3->method('getEMailAddress')->willReturn('[email protected]');
$user3->method('getSystemEMailAddress')->willReturn('[email protected]');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user4->method('getDisplayName')->willReturn('User 222');
$user4->method('getEMailAddress')->willReturn('[email protected]');
$user4->method('getSystemEMailAddress')->willReturn('[email protected]');


$this->userSession->expects($this->at(0))
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
$result['share_with_displayname_unique'] = $sharedWith !== null ? (
$sharedWith->getEMailAddress() !== '' ? $sharedWith->getEMailAddress() : $sharedWith->getUID()
!empty($sharedWith->getSystemEMailAddress()) ? $sharedWith->getSystemEMailAddress() : $sharedWith->getUID()
) : $share->getSharedWith();
$result['status'] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
Expand Down Expand Up @@ -785,7 +786,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$user = $this->getMockBuilder(IUser::class)->getMock();
$user->method('getUID')->willReturn('userId');
$user->method('getDisplayName')->willReturn('userDisplay');
$user->method('getEMailAddress')->willReturn('[email protected]');
$user->method('getSystemEMailAddress')->willReturn('[email protected]');

$group = $this->getMockBuilder('OCP\IGroup')->getMock();
$group->method('getGID')->willReturn('groupId');
Expand Down Expand Up @@ -3586,7 +3587,7 @@ public function dataFormatShare() {
$initiator->method('getDisplayName')->willReturn('initiatorDN');
$recipient = $this->getMockBuilder(IUser::class)->getMock();
$recipient->method('getDisplayName')->willReturn('recipientDN');
$recipient->method('getEmailAddress')->willReturn('recipient');
$recipient->method('getSystemEMailAddress')->willReturn('recipient');


$result = [];
Expand Down Expand Up @@ -4387,7 +4388,7 @@ public function dataFormatShare() {
public function testFormatShare(array $expects, \OCP\Share\IShare $share, array $users, $exception) {
$this->userManager->method('get')->willReturnMap($users);

$recipientGroup = $this->createMock('\OCP\IGroup');
$recipientGroup = $this->createMock(IGroup::class);
$recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName');
$this->groupManager->method('get')->willReturnMap([
['recipientGroup', $recipientGroup],
Expand All @@ -4397,7 +4398,6 @@ public function testFormatShare(array $expects, \OCP\Share\IShare $share, array
->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken'])
->willReturn('myLink');


$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion apps/provisioning_api/lib/Controller/AUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function getUserData(string $userId, bool $includeScopes = false): arr
$data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope();
}

$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getSystemEMailAddress();
if ($includeScopes) {
$data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
}
break;
case IAccountManager::COLLECTION_EMAIL:
if (filter_var($value, FILTER_VALIDATE_EMAIL) && $value !== $targetUser->getEMailAddress()) {
if (filter_var($value, FILTER_VALIDATE_EMAIL) && $value !== $targetUser->getSystemEMailAddress()) {
$userAccount = $this->accountManager->getAccount($targetUser);
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
foreach ($mailCollection->getProperties() as $property) {
Expand Down
13 changes: 8 additions & 5 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ public function testGetUserDataAsAdmin() {
->disableOriginalConstructor()
->getMock();
$targetUser->expects($this->once())
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$this->userSession
->expects($this->once())
Expand Down Expand Up @@ -1067,6 +1067,7 @@ public function testGetUserDataAsAdmin() {
'setPassword' => true,
],
'additional_mail' => [],
'notify_email' => null,
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand All @@ -1083,9 +1084,9 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
->disableOriginalConstructor()
->getMock();
$targetUser
->expects($this->once())
->method('getEMailAddress')
->willReturn('[email protected]');
->expects($this->once())
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$this->userSession
->expects($this->once())
->method('getUser')
Expand Down Expand Up @@ -1195,6 +1196,7 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
'setPassword' => true,
],
'additional_mail' => [],
'notify_email' => null,
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -1306,7 +1308,7 @@ public function testGetUserDataAsSubAdminSelfLookup() {
->willReturn('Subadmin User');
$targetUser
->expects($this->once())
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$targetUser
->method('getUID')
Expand Down Expand Up @@ -1361,6 +1363,7 @@ public function testGetUserDataAsSubAdminSelfLookup() {
'setPassword' => false,
],
'additional_mail' => [],
'notify_email' => null,
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ protected function saveUserSettings(IAccount $userAccount): void {
}
}

$oldEmailAddress = $userAccount->getUser()->getEMailAddress();
$oldEmailAddress = $userAccount->getUser()->getSystemEMailAddress();
$oldEmailAddress = strtolower((string)$oldEmailAddress);
if ($oldEmailAddress !== $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue()) {
// this is the only permission a backend provides and is also used
// for the permission of setting a email address
if (!$userAccount->getUser()->canChangeDisplayName()) {
throw new ForbiddenException($this->l10n->t('Unable to change email address'));
}
$userAccount->getUser()->setEMailAddress($userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue());
$userAccount->getUser()->setSystemEMailAddress($userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue());
}

try {
Expand Down
9 changes: 4 additions & 5 deletions apps/settings/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,15 @@ public function testSaveUserSettings($data,
$user = $this->createMock(IUser::class);

$user->method('getDisplayName')->willReturn($oldDisplayName);
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
$user->method('getSystemEMailAddress')->willReturn($oldEmailAddress);
$user->method('canChangeDisplayName')->willReturn(true);

if ($data[IAccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
($oldEmailAddress === null && $data[IAccountManager::PROPERTY_EMAIL]['value'] === '')) {
$user->expects($this->never())->method('setEMailAddress');
$user->expects($this->never())->method('setSystemEMailAddress');
} else {
$user->expects($this->once())->method('setEMailAddress')
->with($data[IAccountManager::PROPERTY_EMAIL]['value'])
->willReturn(true);
$user->expects($this->once())->method('setSystemEMailAddress')
->with($data[IAccountManager::PROPERTY_EMAIL]['value']);
}

if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function updateEmail($valueFromLDAP = null) {
if ($email !== '') {
$user = $this->userManager->get($this->uid);
if (!is_null($user)) {
$currentEmail = (string)$user->getEMailAddress();
$currentEmail = (string)$user->getSystemEMailAddress();
if ($currentEmail !== $email) {
$user->setEMailAddress($email);
}
Expand Down
2 changes: 1 addition & 1 deletion core/Command/User/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$data = [
'user_id' => $user->getUID(),
'display_name' => $user->getDisplayName(),
'email' => $user->getEMailAddress() ? $user->getEMailAddress() : '',
'email' => (string)$user->getSystemEMailAddress(),
'cloud_id' => $user->getCloudId(),
'enabled' => $user->isEnabled(),
'groups' => $groups,
Expand Down
2 changes: 1 addition & 1 deletion core/Command/User/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function formatUsers(array $users, bool $detailed = false) {
return [
'user_id' => $user->getUID(),
'display_name' => $user->getDisplayName(),
'email' => $user->getEMailAddress() ? $user->getEMailAddress() : '',
'email' => (string)$user->getSystemEMailAddress(),
'cloud_id' => $user->getCloudId(),
'enabled' => $user->isEnabled(),
'groups' => $groups,
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$userStatuses = $this->userStatusManager->getUserStatuses(array_keys($users));
foreach ($users as $uid => $user) {
$userDisplayName = $user->getDisplayName();
$userEmail = $user->getEMailAddress();
$userEmail = $user->getSystemEMailAddress();
$uid = (string) $uid;

$status = [];
Expand Down Expand Up @@ -244,7 +244,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
if ($addUser) {
$status = [];
$uid = $user->getUID();
$userEmail = $user->getEMailAddress();
$userEmail = $user->getSystemEMailAddress();
if (array_key_exists($user->getUID(), $userStatuses)) {
$userStatus = $userStatuses[$user->getUID()];
$status = [
Expand Down
22 changes: 21 additions & 1 deletion tests/lib/AllConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @package Test
*/

use OC\SystemConfig;
use OCP\IDBConnection;

class AllConfigTest extends \Test\TestCase {
Expand Down Expand Up @@ -145,7 +147,7 @@ public function testSetUserValueUnexpectedValue($value) {
$config->setUserValue('userSetBool', 'appSetBool', 'keySetBool', $value);
}


public function testSetUserValueWithPreConditionFailure() {
$this->expectException(\OCP\PreConditionNotMetException::class);

Expand Down Expand Up @@ -437,4 +439,22 @@ public function testGetUsersForUserValue() {
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}

public function testGetUsersForUserValueCaseInsensitive() {
// mock the check for the database to run the correct SQL statements for each database type
$systemConfig = $this->createMock(SystemConfig::class);
$systemConfig->expects($this->once())
->method('getValue')
->with($this->equalTo('dbtype'), $this->equalTo('sqlite'))
->willReturn(\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite'));
$config = $this->getConfig($systemConfig);

$config->setUserValue('user1', 'myApp', 'myKey', 'test123');
$config->setUserValue('user2', 'myApp', 'myKey', 'TEST123');
$config->setUserValue('user3', 'myApp', 'myKey', 'test12345');

$users = $config->getUsersForUserValueCaseInsensitive('myApp', 'myKey', 'test123');
$this->assertSame(2, count($users));
$this->assertSame(['user1', 'user2'], $users);
}
}