diff options
author | Christopher Ng <chrng8@gmail.com> | 2021-10-14 08:05:17 +0000 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2021-10-19 04:44:40 +0000 |
commit | 7215148a242815a5064ce5d00a387c634dc936f3 (patch) | |
tree | 4edf67253bd8c3bbe3ea2f1fba17e21b221e9282 /lib/private | |
parent | 382ba66ab5e1a675347e86d93593eb228da253bb (diff) | |
download | nextcloud-server-7215148a242815a5064ce5d00a387c634dc936f3.tar.gz nextcloud-server-7215148a242815a5064ce5d00a387c634dc936f3.zip |
Add new account properties
- New properties
- Organisation
- Role
- Headline
- Biography
- Profile Enabled property
- Fix errors with building default account properties
- Fix L10N factory method `getLanguage` not public error
- Update tests
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 60 | ||||
-rw-r--r-- | lib/private/Accounts/TAccountsHelper.php | 6 | ||||
-rw-r--r-- | lib/private/L10N/Factory.php | 44 |
3 files changed, 77 insertions, 33 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index a3f971df6a1..3416db56ba5 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -1,4 +1,5 @@ <?php + /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, Björn Schießle @@ -30,6 +31,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OC\Accounts; use Exception; @@ -337,7 +339,7 @@ class AccountManager implements IAccountManager { return $this->buildDefaultUserRecord($user); } - return $this->addMissingDefaultValues($userDataArray); + return $this->addMissingDefaultValues($userDataArray, $this->buildDefaultUserRecord($user)); } public function searchUsers(string $property, array $values): array { @@ -384,7 +386,8 @@ class AccountManager implements IAccountManager { } $oldMail = isset($oldData[self::PROPERTY_EMAIL]) ? $oldData[self::PROPERTY_EMAIL]['value']['value'] : ''; if ($oldMail !== $property->getValue()) { - $this->jobList->add(VerifyUserData::class, + $this->jobList->add( + VerifyUserData::class, [ 'verificationCode' => '', 'data' => $property->getValue(), @@ -416,12 +419,14 @@ class AccountManager implements IAccountManager { $key = $this->crypto->encrypt($email); $token = $this->verificationToken->create($user, 'verifyMail' . $ref, $email); - $link = $this->urlGenerator->linkToRouteAbsolute('provisioning_api.Verification.verifyMail', + $link = $this->urlGenerator->linkToRouteAbsolute( + 'provisioning_api.Verification.verifyMail', [ 'userId' => $user->getUID(), 'token' => $token, 'key' => $key - ]); + ] + ); $emailTemplate = $this->mailer->createEMailTemplate('core.EmailVerification', [ 'link' => $link, @@ -465,14 +470,18 @@ class AccountManager implements IAccountManager { } /** - * make sure that all expected data are set - * + * Make sure that all expected data are set */ - protected function addMissingDefaultValues(array $userData): array { - foreach ($userData as $i => $value) { - if (!isset($value['verified'])) { - $userData[$i]['verified'] = self::NOT_VERIFIED; + protected function addMissingDefaultValues(array $userData, array $defaultUserData): array { + foreach ($defaultUserData as $i => $value) { + // If property doesn't exists, initialize it + if (!array_key_exists($i, $userData)) { + $userData[$i] = []; } + + // Merge and extend default missing values + $defaultValueIndex = array_search($value['name'], array_column($defaultUserData, 'name')); + $userData[$i] = array_merge($defaultUserData[$defaultValueIndex], $userData[$i]); } return $userData; @@ -499,7 +508,7 @@ class AccountManager implements IAccountManager { || $property->getValue() !== $oldData[$propertyName]['value']) && ($property->getVerified() !== self::NOT_VERIFIED || $wasVerified) - ) { + ) { $property->setVerified(self::NOT_VERIFIED); } } @@ -629,7 +638,6 @@ class AccountManager implements IAccountManager { */ protected function buildDefaultUserRecord(IUser $user) { return [ - [ 'name' => self::PROPERTY_DISPLAYNAME, 'value' => $user->getDisplayName(), @@ -677,6 +685,34 @@ class AccountManager implements IAccountManager { 'verified' => self::NOT_VERIFIED, ], + [ + 'name' => self::PROPERTY_ORGANISATION, + 'value' => '', + 'scope' => self::SCOPE_LOCAL, + ], + + [ + 'name' => self::PROPERTY_ROLE, + 'value' => '', + 'scope' => self::SCOPE_LOCAL, + ], + + [ + 'name' => self::PROPERTY_HEADLINE, + 'value' => '', + 'scope' => self::SCOPE_LOCAL, + ], + + [ + 'name' => self::PROPERTY_BIOGRAPHY, + 'value' => '', + 'scope' => self::SCOPE_LOCAL, + ], + + [ + 'name' => self::PROPERTY_PROFILE_ENABLED, + 'value' => '1', + ], ]; } diff --git a/lib/private/Accounts/TAccountsHelper.php b/lib/private/Accounts/TAccountsHelper.php index 530204b451f..f3be6523d29 100644 --- a/lib/private/Accounts/TAccountsHelper.php +++ b/lib/private/Accounts/TAccountsHelper.php @@ -29,8 +29,12 @@ namespace OC\Accounts; use OCP\Accounts\IAccountManager; trait TAccountsHelper { + /** + * returns whether the property is a collection + */ protected function isCollection(string $propertyName): bool { - return in_array($propertyName, + return in_array( + $propertyName, [ IAccountManager::COLLECTION_EMAIL, ], diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 8aa09ab87bc..a3ff7bf70e2 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -37,6 +37,7 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OC\L10N; use OCP\IConfig; @@ -104,10 +105,12 @@ class Factory implements IFactory { * @param IUserSession $userSession * @param string $serverRoot */ - public function __construct(IConfig $config, - IRequest $request, - IUserSession $userSession, - $serverRoot) { + public function __construct( + IConfig $config, + IRequest $request, + IUserSession $userSession, + $serverRoot + ) { $this->config = $config; $this->request = $request; $this->userSession = $userSession; @@ -149,7 +152,10 @@ class Factory implements IFactory { if (!isset($this->instances[$lang][$app])) { $this->instances[$lang][$app] = new L10N( - $this, $app, $lang, $locale, + $this, + $app, + $lang, + $locale, $this->getL10nFilesForApp($app, $lang) ); } @@ -391,7 +397,7 @@ class Factory implements IFactory { * @return bool */ public function languageExists($app, $lang) { - if ($lang === 'en') {//english is always available + if ($lang === 'en') { //english is always available return true; } @@ -493,7 +499,8 @@ class Factory implements IFactory { // use formal version of german ("Sie" instead of "Du") if the default // language is set to 'de_DE' if possible - if (is_string($defaultLanguage) && + if ( + is_string($defaultLanguage) && strtolower($lang) === 'de' && strtolower($defaultLanguage) === 'de_de' && $this->languageExists($app, 'de_DE') @@ -542,9 +549,9 @@ class Factory implements IFactory { if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') - ) - && file_exists($transFile)) { + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')) + && file_exists($transFile) + ) { // load the translations file $languageFiles[] = $transFile; } @@ -599,9 +606,9 @@ class Factory implements IFactory { $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); $body = str_replace( - [ 'plural', 'n', '$n$plurals', ], - [ '$plural', '$n', '$nplurals', ], - 'nplurals='. $nplurals . '; plural=' . $plural + ['plural', 'n', '$n$plurals',], + ['$plural', '$n', '$nplurals',], + 'nplurals=' . $nplurals . '; plural=' . $plural ); // add parents @@ -645,12 +652,9 @@ class Factory implements IFactory { } /** - * returns the common language and other languages in an - * associative array - * - * @return array + * @inheritDoc */ - public function getLanguages() { + public function getLanguages(): array { $forceLanguage = $this->config->getSystemValue('force_language', false); if ($forceLanguage !== false) { $l = $this->get('lib', $forceLanguage); @@ -674,7 +678,7 @@ class Factory implements IFactory { $l = $this->get('lib', $lang); // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version $potentialName = $l->t('__language_name__'); - if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file + if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') { //first check if the language name is in the translation file $ln = [ 'code' => $lang, 'name' => $potentialName @@ -684,7 +688,7 @@ class Factory implements IFactory { 'code' => $lang, 'name' => 'English (US)' ]; - } else {//fallback to language code + } else { //fallback to language code $ln = [ 'code' => $lang, 'name' => $lang |