Skip to content

Commit

Permalink
Map old account scope properties to new names
Browse files Browse the repository at this point in the history
Use new scope values in settings page.
Adjust all consumers to use the new constants.
Map old scope values to new ones in account property getter.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Mar 26, 2021
1 parent 9fb447e commit 278a737
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 113 deletions.
4 changes: 2 additions & 2 deletions apps/dav/lib/CardDAV/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function createCardFromUser(IUser $user) {

foreach ($userData as $property => $value) {
$shareWithTrustedServers =
$value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
$value['scope'] === AccountManager::VISIBILITY_PUBLIC;
$value['scope'] === AccountManager::SCOPE_FEDERATED ||
$value['scope'] === AccountManager::SCOPE_PUBLISHED;

$emptyValue = !isset($value['value']) || $value['value'] === '';

Expand Down
14 changes: 7 additions & 7 deletions apps/dav/tests/unit/CardDAV/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,36 @@ public function getAccountManager(IUser $user) {
IAccountManager::PROPERTY_DISPLAYNAME =>
[
'value' => $user->getDisplayName(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
],
IAccountManager::PROPERTY_ADDRESS =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_WEBSITE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_EMAIL =>
[
'value' => $user->getEMailAddress(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
],
IAccountManager::PROPERTY_AVATAR =>
[
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
'scope' => AccountManager::SCOPE_FEDERATED
],
IAccountManager::PROPERTY_PHONE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_TWITTER =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
]
);
Expand Down
14 changes: 7 additions & 7 deletions apps/dav/tests/unit/CardDAV/SyncServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,36 @@ public function testUpdateAndDeleteUser($activated, $createCalls, $updateCalls,
IAccountManager::PROPERTY_DISPLAYNAME =>
[
'value' => $user->getDisplayName(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
],
IAccountManager::PROPERTY_ADDRESS =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_WEBSITE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_EMAIL =>
[
'value' => $user->getEMailAddress(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
],
IAccountManager::PROPERTY_AVATAR =>
[
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
'scope' => AccountManager::SCOPE_FEDERATED
],
IAccountManager::PROPERTY_PHONE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
IAccountManager::PROPERTY_TWITTER =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
],
]
);
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function showShare($path = ''): TemplateResponse {
$ownerAccount = $this->accountManager->getAccount($owner);

$ownerName = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
if ($ownerName->getScope() === IAccountManager::VISIBILITY_PUBLIC) {
if ($ownerName->getScope() === IAccountManager::SCOPE_PUBLISHED) {
$shareTmpl['owner'] = $owner->getUID();
$shareTmpl['shareOwner'] = $owner->getDisplayName();
}
Expand Down
8 changes: 4 additions & 4 deletions apps/files_sharing/tests/Controller/ShareControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function testShowShare() {

$accountName = $this->createMock(IAccountProperty::class);
$accountName->method('getScope')
->willReturn(IAccountManager::VISIBILITY_PUBLIC);
->willReturn(IAccountManager::SCOPE_PUBLISHED);
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
->with(IAccountManager::PROPERTY_DISPLAYNAME)
Expand Down Expand Up @@ -381,7 +381,7 @@ public function testShowShareWithPrivateName() {

$accountName = $this->createMock(IAccountProperty::class);
$accountName->method('getScope')
->willReturn(IAccountManager::VISIBILITY_PRIVATE);
->willReturn(IAccountManager::SCOPE_LOCAL);
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
->with(IAccountManager::PROPERTY_DISPLAYNAME)
Expand Down Expand Up @@ -528,7 +528,7 @@ public function testShowShareHideDownload() {

$accountName = $this->createMock(IAccountProperty::class);
$accountName->method('getScope')
->willReturn(IAccountManager::VISIBILITY_PUBLIC);
->willReturn(IAccountManager::SCOPE_PUBLISHED);
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
->with(IAccountManager::PROPERTY_DISPLAYNAME)
Expand Down Expand Up @@ -688,7 +688,7 @@ public function testShareFileDrop() {

$accountName = $this->createMock(IAccountProperty::class);
$accountName->method('getScope')
->willReturn(IAccountManager::VISIBILITY_PUBLIC);
->willReturn(IAccountManager::SCOPE_PUBLISHED);
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
->with(IAccountManager::PROPERTY_DISPLAYNAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected function getUserAccountData(IUser $user): array {

$publicData = [];
foreach ($account->getProperties() as $property) {
if ($property->getScope() === IAccountManager::VISIBILITY_PUBLIC) {
if ($property->getScope() === IAccountManager::SCOPE_PUBLISHED) {
$publicData[$property->getName()] = $property->getValue();
}
}
Expand Down
8 changes: 4 additions & 4 deletions apps/settings/js/federationscopemenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
active: false
},
{
name: 'private',
name: 'v2-local',
displayName: t('settings', 'Local'),
tooltip: t('settings', "Don't synchronize to servers"),
iconClass: 'icon-password',
active: false
},
{
name: 'contacts',
displayName: t('settings', 'Trusted'),
name: 'v2-federated',
displayName: t('settings', 'Federated'),
tooltip: t('settings', 'Only synchronize to trusted servers'),
iconClass: 'icon-contacts-dark',
active: false
},
{
name: 'public',
name: 'v2-published',
displayName: t('settings', 'Published'),
tooltip: t('settings', 'Synchronize to trusted servers and the global and public address book'),
iconClass: 'icon-link',
Expand Down
10 changes: 5 additions & 5 deletions apps/settings/js/federationsettingsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
}

if (!self.showFederationScopes) {
excludedScopes.push('contacts');
excludedScopes.push('public');
excludedScopes.push('v2-federated');
excludedScopes.push('v2-published');
}

var scopeMenu = new OC.Settings.FederationScopeMenu({
Expand Down Expand Up @@ -237,16 +237,16 @@
$icon.addClass('hidden');

switch (scope) {
case 'private':
case 'v2-private':
case 'v2-local':
$icon.addClass('icon-password');
$icon.removeClass('hidden');
break;
case 'contacts':
case 'v2-federated':
$icon.addClass('icon-contacts-dark');
$icon.removeClass('hidden');
break;
case 'public':
case 'v2-published':
$icon.addClass('icon-link');
$icon.removeClass('hidden');
break;
Expand Down
43 changes: 22 additions & 21 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

use OC\Accounts\AccountManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function getForm(): TemplateResponse {

$uid = \OC_User::getUser();
$user = $this->userManager->get($uid);
$userData = $this->accountManager->getUser($user);
$account = $this->accountManager->getAccount($user);

// make sure FS is setup before querying storage related stuff...
\OC_Util::setupFS($user->getUID());
Expand All @@ -110,7 +111,7 @@ public function getForm(): TemplateResponse {

$languageParameters = $this->getLanguages($user);
$localeParameters = $this->getLocales($user);
$messageParameters = $this->getMessageParameters($userData);
$messageParameters = $this->getMessageParameters($account);

$parameters = [
'total_space' => $totalSpace,
Expand All @@ -119,23 +120,23 @@ public function getForm(): TemplateResponse {
'quota' => $storageInfo['quota'],
'avatarChangeSupported' => $user->canChangeAvatar(),
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
'avatarScope' => $userData[IAccountManager::PROPERTY_AVATAR]['scope'],
'avatarScope' => $account->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(),
'displayNameChangeSupported' => $user->canChangeDisplayName(),
'displayName' => $userData[IAccountManager::PROPERTY_DISPLAYNAME]['value'],
'displayNameScope' => $userData[IAccountManager::PROPERTY_DISPLAYNAME]['scope'],
'email' => $userData[IAccountManager::PROPERTY_EMAIL]['value'],
'emailScope' => $userData[IAccountManager::PROPERTY_EMAIL]['scope'],
'emailVerification' => $userData[IAccountManager::PROPERTY_EMAIL]['verified'],
'phone' => $userData[IAccountManager::PROPERTY_PHONE]['value'],
'phoneScope' => $userData[IAccountManager::PROPERTY_PHONE]['scope'],
'address' => $userData[IAccountManager::PROPERTY_ADDRESS]['value'],
'addressScope' => $userData[IAccountManager::PROPERTY_ADDRESS]['scope'],
'website' => $userData[IAccountManager::PROPERTY_WEBSITE]['value'],
'websiteScope' => $userData[IAccountManager::PROPERTY_WEBSITE]['scope'],
'websiteVerification' => $userData[IAccountManager::PROPERTY_WEBSITE]['verified'],
'twitter' => $userData[IAccountManager::PROPERTY_TWITTER]['value'],
'twitterScope' => $userData[IAccountManager::PROPERTY_TWITTER]['scope'],
'twitterVerification' => $userData[IAccountManager::PROPERTY_TWITTER]['verified'],
'displayName' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getValue(),
'displayNameScope' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(),
'email' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(),
'emailScope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(),
'emailVerification' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(),
'phone' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(),
'phoneScope' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getScope(),
'address' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getValue(),
'addressScope' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getScope(),
'website' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getValue(),
'websiteScope' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getScope(),
'websiteVerification' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getVerified(),
'twitter' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(),
'twitterScope' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getScope(),
'twitterVerification' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getVerified(),
'groups' => $this->getGroups($user),
] + $messageParameters + $languageParameters + $localeParameters;

Expand Down Expand Up @@ -263,14 +264,14 @@ private function getLocales(IUser $user): array {
}

/**
* @param array $userData
* @param IAccount $account
* @return array
*/
private function getMessageParameters(array $userData): array {
private function getMessageParameters(IAccount $account): array {
$needVerifyMessage = [IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER];
$messageParameters = [];
foreach ($needVerifyMessage as $property) {
switch ($userData[$property]['verified']) {
switch ($account->getProperty($property)->getVerified()) {
case AccountManager::VERIFIED:
$message = $this->l->t('Verifying');
break;
Expand Down
28 changes: 14 additions & 14 deletions apps/settings/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,41 +208,41 @@ public function testSetUserSettings($email, $validEmail, $expectedStatus) {
IAccountManager::PROPERTY_DISPLAYNAME =>
[
'value' => 'Display name',
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
'verified' => AccountManager::NOT_VERIFIED,
],
IAccountManager::PROPERTY_ADDRESS =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
'verified' => AccountManager::NOT_VERIFIED,
],
IAccountManager::PROPERTY_WEBSITE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
'verified' => AccountManager::NOT_VERIFIED,
],
IAccountManager::PROPERTY_EMAIL =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'scope' => AccountManager::SCOPE_FEDERATED,
'verified' => AccountManager::NOT_VERIFIED,
],
IAccountManager::PROPERTY_AVATAR =>
[
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
'scope' => AccountManager::SCOPE_FEDERATED
],
IAccountManager::PROPERTY_PHONE =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
'verified' => AccountManager::NOT_VERIFIED,
],
IAccountManager::PROPERTY_TWITTER =>
[
'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'scope' => AccountManager::SCOPE_LOCAL,
'verified' => AccountManager::NOT_VERIFIED,
],
]);
Expand All @@ -255,19 +255,19 @@ public function testSetUserSettings($email, $validEmail, $expectedStatus) {
}

$result = $controller->setUserSettings(//
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
'displayName',
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
'47658468',
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
$email,
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
'nextcloud.com',
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
'street and city',
AccountManager::VISIBILITY_CONTACTS_ONLY,
AccountManager::SCOPE_FEDERATED,
'@nextclouders',
AccountManager::VISIBILITY_CONTACTS_ONLY
AccountManager::SCOPE_FEDERATED
);

$this->assertSame($expectedStatus, $result->getStatus());
Expand Down
Loading

0 comments on commit 278a737

Please sign in to comment.