Skip to content

Commit

Permalink
Merge pull request #28780 from nextcloud/backport/28422/stable22
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Sep 10, 2021
2 parents c57a621 + cc9758e commit 317e04d
Show file tree
Hide file tree
Showing 46 changed files with 1,422 additions and 448 deletions.
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 @@ -295,16 +295,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 @@ -510,7 +507,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
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 @@ -113,7 +113,7 @@ public function testGetPrincipalsByPrefixWithUsers() {
->willReturn('Dr. Foo-Bar');
$fooUser
->expects($this->exactly(1))
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('');
$barUser = $this->createMock(User::class);
$barUser
Expand All @@ -122,7 +122,7 @@ public function testGetPrincipalsByPrefixWithUsers() {
->willReturn('bar');
$barUser
->expects($this->exactly(1))
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('bar@nextcloud.com');
$this->userManager
->expects($this->once())
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testGetPrincipalsByPathWithMail() {
$fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getEMailAddress')
->method('getSystemEMailAddress')
->willReturn('foo@nextcloud.com');
$fooUser
->expects($this->exactly(1))
Expand Down Expand Up @@ -576,15 +576,15 @@ public function testSearchPrincipalWithEnumerationDisabledDisplayname() {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user2->method('getDisplayName')->willReturn('User 22');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar123');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar123');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user2->method('getDisplayName')->willReturn('User 222');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar456');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar456');

$this->userManager->expects($this->at(0))
->method('searchDisplayName')
Expand Down Expand Up @@ -636,20 +636,20 @@ public function testSearchPrincipalWithEnumerationDisabledEmail() {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user2->method('getDisplayName')->willReturn('User 22');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar123');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar123');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user2->method('getDisplayName')->willReturn('User 222');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar456');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar456');

$this->userManager->expects($this->at(0))
$this->userManager->expects($this->once())
->method('getByEmail')
->with('user2@foo.bar')
->willReturn([$user2, $user3, $user4]);
->willReturn([$user2]);

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


$this->userSession->expects($this->at(0))
Expand Down Expand Up @@ -758,15 +758,15 @@ public function testSearchPrincipalWithEnumerationLimitedMail() {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('User 2');
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user3->method('getDisplayName')->willReturn('User 22');
$user3->method('getEMailAddress')->willReturn('user2@foo.bar123');
$user3->method('getSystemEMailAddress')->willReturn('user2@foo.bar123');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user4->method('getDisplayName')->willReturn('User 222');
$user4->method('getEMailAddress')->willReturn('user2@foo.bar456');
$user4->method('getSystemEMailAddress')->willReturn('user2@foo.bar456');


$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('userId@example.com');
$user->method('getSystemEMailAddress')->willReturn('userId@example.com');

$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
5 changes: 5 additions & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@
['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'],
['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'],
],
'routes' => [
// Verification
['name' => 'Verification#showVerifyMail', 'url' => '/mailVerification/{key}/{token}/{userId}', 'verb' => 'GET'],
['name' => 'Verification#verifyMail', 'url' => '/mailVerification/{key}/{token}/{userId}', 'verb' => 'POST'],
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
'OCA\\Provisioning_API\\Controller\\VerificationController' => $baseDir . '/../lib/Controller/VerificationController.php',
'OCA\\Provisioning_API\\FederatedShareProviderFactory' => $baseDir . '/../lib/FederatedShareProviderFactory.php',
'OCA\\Provisioning_API\\Listener\\UserDeletedListener' => $baseDir . '/../lib/Listener/UserDeletedListener.php',
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ComposerStaticInitProvisioning_API
'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
'OCA\\Provisioning_API\\Controller\\VerificationController' => __DIR__ . '/..' . '/../lib/Controller/VerificationController.php',
'OCA\\Provisioning_API\\FederatedShareProviderFactory' => __DIR__ . '/..' . '/../lib/FederatedShareProviderFactory.php',
'OCA\\Provisioning_API\\Listener\\UserDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/UserDeletedListener.php',
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
Expand Down
4 changes: 2 additions & 2 deletions apps/provisioning_api/composer/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
'reference' => 'fb5ee6087bfd1f4cc2f37cda7a7cab7072aaae86',
'reference' => '13a9cd28a5a5d92e285df040d084d5d608e2f768',
'name' => '__root__',
'dev' => false,
),
Expand All @@ -16,7 +16,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
'reference' => 'fb5ee6087bfd1f4cc2f37cda7a7cab7072aaae86',
'reference' => '13a9cd28a5a5d92e285df040d084d5d608e2f768',
'dev_requirement' => false,
),
),
Expand Down
20 changes: 14 additions & 6 deletions apps/provisioning_api/lib/Controller/AUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
abstract class AUserData extends OCSController {
public const SCOPE_SUFFIX = 'Scope';

public const USER_FIELD_DISPLAYNAME = 'display';
public const USER_FIELD_LANGUAGE = 'language';
public const USER_FIELD_LOCALE = 'locale';
public const USER_FIELD_PASSWORD = 'password';
public const USER_FIELD_QUOTA = 'quota';
public const USER_FIELD_NOTIFICATION_EMAIL = 'notify_email';

/** @var IUserManager */
protected $userManager;
/** @var IConfig */
Expand Down Expand Up @@ -139,14 +146,14 @@ protected function getUserData(string $userId, bool $includeScopes = false): arr
$data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
$data['backend'] = $targetUserObject->getBackendClassName();
$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
$data[self::USER_FIELD_QUOTA] = $this->fillStorageInfo($targetUserObject->getUID());

try {
if ($includeScopes) {
$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 Expand Up @@ -187,8 +194,9 @@ protected function getUserData(string $userId, bool $includeScopes = false): arr
}

$data['groups'] = $gids;
$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
$data[self::USER_FIELD_LANGUAGE] = $this->l10nFactory->getUserLanguage($targetUserObject);
$data[self::USER_FIELD_LOCALE] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
$data[self::USER_FIELD_NOTIFICATION_EMAIL] = $targetUserObject->getPrimaryEMailAddress();

$backend = $targetUserObject->getBackend();
$data['backendCapabilities'] = [
Expand Down Expand Up @@ -238,7 +246,7 @@ protected function fillStorageInfo(string $userId): array {
'used' => $storage['used'],
'total' => $storage['total'],
'relative' => $storage['relative'],
'quota' => $storage['quota'],
self::USER_FIELD_QUOTA => $storage['quota'],
];
} catch (NotFoundException $ex) {
// User fs is not setup yet
Expand All @@ -251,7 +259,7 @@ protected function fillStorageInfo(string $userId): array {
$quota = OC_Helper::computerFileSize($quota);
}
$data = [
'quota' => $quota !== false ? $quota : 'none',
self::USER_FIELD_QUOTA => $quota !== false ? $quota : 'none',
'used' => 0
];
}
Expand Down
Loading

0 comments on commit 317e04d

Please sign in to comment.