Skip to content
Merged
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
feat(preset): Profile Visibility
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Aug 8, 2025
commit a4b9edc8ebe1517d9a0fecbee65333a94954487c
28 changes: 28 additions & 0 deletions lib/private/Profile/ProfileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OC\Profile;

use OC\AppFramework\Bootstrap\Coordinator;
use OC\Config\PresetManager;
use OC\Core\Db\ProfileConfig;
use OC\Core\Db\ProfileConfigMapper;
use OC\Core\ResponseDefinitions;
Expand All @@ -25,6 +26,7 @@
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Cache\CappedMemoryCache;
use OCP\Config\Lexicon\Preset;
use OCP\IConfig;
use OCP\IUser;
use OCP\L10N\IFactory;
Expand Down Expand Up @@ -85,6 +87,7 @@ public function __construct(
private IFactory $l10nFactory,
private LoggerInterface $logger,
private Coordinator $coordinator,
private readonly PresetManager $presetManager,
) {
$this->configCache = new CappedMemoryCache();
}
Expand Down Expand Up @@ -315,12 +318,37 @@ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser
// Construct the default config for account properties
$propertiesConfig = [];
foreach (self::DEFAULT_PROPERTY_VISIBILITY as $property => $visibility) {
$this->applyDefaultProfilePreset($property, $visibility);
$propertiesConfig[$property] = ['visibility' => $visibility];
}

return array_merge($actionsConfig, $propertiesConfig);
}

/**
* modify property visibility, based on current Preset
*/
private function applyDefaultProfilePreset(string $property, string &$visibility): void {
$overwrite = match($this->presetManager->getLexiconPreset()) {
Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match($property) {
IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
},
Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match($property) {
IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
},
Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match($property) {
IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
},
default => null,
};

if ($overwrite === null) {
return;
}

$visibility = $overwrite;
}

/**
* Return the profile config of the target user,
* if a config does not already exist a default config is created and returned
Expand Down