summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2021-10-20 18:26:25 +0200
committerGitHub <noreply@github.com>2021-10-20 18:26:25 +0200
commit07863f3de3dd1d034c0b31beac99eb798ecfca7c (patch)
treecc00ecb63e9532364777ea7864428cf0a1628046
parent49e727fe6a655c01e55c45b36603186f41a6a905 (diff)
parentbff02f5e51e6c04c28a410be1c6920b3b89cebbb (diff)
downloadnextcloud-server-07863f3de3dd1d034c0b31beac99eb798ecfca7c.tar.gz
nextcloud-server-07863f3de3dd1d034c0b31beac99eb798ecfca7c.zip
Merge pull request #29330 from nextcloud/fix/missing-profile-config-defaults
Populate missing profile config defaults
-rw-r--r--lib/private/Profile/ProfileManager.php97
1 files changed, 53 insertions, 44 deletions
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php
index 6a38f4ae16d..e0c619725e7 100644
--- a/lib/private/Profile/ProfileManager.php
+++ b/lib/private/Profile/ProfileManager.php
@@ -27,7 +27,6 @@ declare(strict_types=1);
namespace OC\Profile;
use function Safe\usort;
-
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Core\Db\ProfileConfig;
use OC\Core\Db\ProfileConfigMapper;
@@ -46,9 +45,6 @@ use OCP\Profile\ILinkAction;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
-/**
- * @inheritDoc
- */
class ProfileManager {
/** @var IAccountManager */
@@ -78,6 +74,9 @@ class ProfileManager {
/** @var ILinkAction[] */
private $actions = [];
+ /**
+ * Array of account property actions
+ */
private const ACCOUNT_PROPERTY_ACTIONS = [
EmailAction::class,
PhoneAction::class,
@@ -233,7 +232,7 @@ class ProfileManager {
}
/**
- * @inheritDoc
+ * Return the profile parameters
*/
public function getProfileParams(IUser $targetUser, ?IUser $visitingUser): array {
$account = $this->accountManager->getAccount($targetUser);
@@ -279,51 +278,61 @@ class ProfileManager {
}
/**
- * @inheritDoc
+ * Return the default profile config
+ */
+ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser): array {
+ // Contruct the default config for actions
+ $actionsConfig = [];
+ foreach ($this->getActions($targetUser, $visitingUser) as $action) {
+ $actionsConfig[$action->getId()] = [
+ 'displayId' => $action->getDisplayId(),
+ 'visibility' => ProfileConfig::DEFAULT_VISIBILITY,
+ ];
+ }
+
+ // Map of account properties to display IDs
+ $propertyDisplayMap = [
+ IAccountManager::PROPERTY_ADDRESS => $this->l10nFactory->get('core')->t('Address'),
+ IAccountManager::PROPERTY_AVATAR => $this->l10nFactory->get('core')->t('Avatar'),
+ IAccountManager::PROPERTY_BIOGRAPHY => $this->l10nFactory->get('core')->t('About'),
+ IAccountManager::PROPERTY_DISPLAYNAME => $this->l10nFactory->get('core')->t('Full name'),
+ IAccountManager::PROPERTY_HEADLINE => $this->l10nFactory->get('core')->t('Headline'),
+ IAccountManager::PROPERTY_ORGANISATION => $this->l10nFactory->get('core')->t('Organisation'),
+ IAccountManager::PROPERTY_ROLE => $this->l10nFactory->get('core')->t('Role'),
+ IAccountManager::PROPERTY_EMAIL => $this->l10nFactory->get('core')->t('Email'),
+ IAccountManager::PROPERTY_PHONE => $this->l10nFactory->get('core')->t('Phone'),
+ IAccountManager::PROPERTY_TWITTER => $this->l10nFactory->get('core')->t('Twitter'),
+ IAccountManager::PROPERTY_WEBSITE => $this->l10nFactory->get('core')->t('Website'),
+ ];
+
+ // Contruct the default config for account properties
+ $propertiesConfig = [];
+ foreach ($propertyDisplayMap as $property => $displayId) {
+ $propertiesConfig[$property] = [
+ 'displayId' => $displayId,
+ 'visibility' => ProfileConfig::DEFAULT_PROPERTY_VISIBILITY[$property],
+ ];
+ }
+
+ return array_merge($actionsConfig, $propertiesConfig);
+ }
+
+ /**
+ * Return the profile config
*/
public function getProfileConfig(IUser $targetUser, ?IUser $visitingUser): array {
+ $defaultProfileConfig = $this->getDefaultProfileConfig($targetUser, $visitingUser);
try {
- $configArray = $this->configMapper->getArray($targetUser->getUID());
+ $config = $this->configMapper->get($targetUser->getUID());
+ // Merge defaults with the existing config in case the defaults are missing
+ $config->setConfigArray(array_merge($defaultProfileConfig, $config->getConfigArray()));
+ $this->configMapper->update($config);
+ $configArray = $config->getConfigArray();
} catch (DoesNotExistException $e) {
+ // Create a new default config if it does not exist
$config = new ProfileConfig();
$config->setUserId($targetUser->getUID());
-
- // Map of account properties to display IDs
- $propertyDisplayMap = [
- IAccountManager::PROPERTY_ADDRESS => $this->l10nFactory->get('core')->t('Address'),
- IAccountManager::PROPERTY_AVATAR => $this->l10nFactory->get('core')->t('Avatar'),
- IAccountManager::PROPERTY_BIOGRAPHY => $this->l10nFactory->get('core')->t('About'),
- IAccountManager::PROPERTY_DISPLAYNAME => $this->l10nFactory->get('core')->t('Full name'),
- IAccountManager::PROPERTY_HEADLINE => $this->l10nFactory->get('core')->t('Headline'),
- IAccountManager::PROPERTY_ORGANISATION => $this->l10nFactory->get('core')->t('Organisation'),
- IAccountManager::PROPERTY_ROLE => $this->l10nFactory->get('core')->t('Role'),
- IAccountManager::PROPERTY_EMAIL => $this->l10nFactory->get('core')->t('Email'),
- IAccountManager::PROPERTY_PHONE => $this->l10nFactory->get('core')->t('Phone'),
- IAccountManager::PROPERTY_TWITTER => $this->l10nFactory->get('core')->t('Twitter'),
- IAccountManager::PROPERTY_WEBSITE => $this->l10nFactory->get('core')->t('Website'),
- ];
-
- // Contruct the default config for account properties
- $propertiesConfig = [];
- foreach ($propertyDisplayMap as $property => $displayId) {
- $propertiesConfig[$property] = [
- 'displayId' => $displayId,
- 'visibility' => ProfileConfig::DEFAULT_PROPERTY_VISIBILITY[$property] ?: ProfileConfig::DEFAULT_VISIBILITY,
- ];
- }
-
- // Contruct the default config for actions
- $actionsConfig = [];
- /** @var ILinkAction $action */
- foreach ($this->getActions($targetUser, $visitingUser) as $action) {
- $actionsConfig[$action->getId()] = [
- 'displayId' => $action->getDisplayId(),
- 'visibility' => ProfileConfig::DEFAULT_VISIBILITY,
- ];
- }
-
- // Set the default config
- $config->setConfigArray(array_merge($propertiesConfig, $actionsConfig));
+ $config->setConfigArray($defaultProfileConfig);
$this->configMapper->insert($config);
$configArray = $config->getConfigArray();
}