@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix construction of default settings for users with no settings at all

Summary:
Ref T11098. Users with at least one setting set correctly fall back to the defaults, but users with no settings at all currently do not.

Make them fall back to global defaults properly.

Test Plan:
- Set global defaults to some non-default setting.
- Completely delete a user's settings.
- `bin/cache purge --purge-all` or `--purge-user`.
- View settings as the user.
- Before change: showed hard-coded defaults instead of global defaults until you save anything.
- After change: properly shows global defaults from the start.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11098

Differential Revision: https://secure.phabricator.com/D16112

+38 -4
+23 -3
src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
··· 31 31 ->setViewer($viewer) 32 32 ->withUserPHIDs($user_phids) 33 33 ->execute(); 34 + $preferences = mpull($preferences, null, 'getUserPHID'); 35 + 36 + // If some users don't have settings of their own yet, we need to load 37 + // the global default settings to generate caches for them. 38 + if (count($preferences) < count($user_phids)) { 39 + $global = id(new PhabricatorUserPreferencesQuery()) 40 + ->setViewer($viewer) 41 + ->withBuiltinKeys( 42 + array( 43 + PhabricatorUserPreferences::BUILTIN_GLOBAL_DEFAULT, 44 + )) 45 + ->executeOne(); 46 + } else { 47 + $global = null; 48 + } 34 49 35 50 $all_settings = PhabricatorSetting::getAllSettings(); 36 51 37 52 $settings = array(); 38 - foreach ($preferences as $preference) { 39 - $user_phid = $preference->getUserPHID(); 53 + foreach ($users as $user_phid => $user) { 54 + $preference = idx($preferences, $user_phid, $global); 55 + 56 + if (!$preference) { 57 + continue; 58 + } 59 + 40 60 foreach ($all_settings as $key => $setting) { 41 61 $value = $preference->getSettingValue($key); 42 62 43 63 // As an optimization, we omit the value from the cache if it is 44 64 // exactly the same as the hardcoded default. 45 65 $default_value = id(clone $setting) 46 - ->setViewer($users[$user_phid]) 66 + ->setViewer($user) 47 67 ->getSettingDefaultValue(); 48 68 if ($value === $default_value) { 49 69 continue;
+15 -1
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 130 130 return $preferences; 131 131 } 132 132 133 - return id(new self()) 133 + $preferences = id(new self()) 134 134 ->setUserPHID($user->getPHID()) 135 135 ->attachUser($user); 136 + 137 + $global = id(new PhabricatorUserPreferencesQuery()) 138 + ->setViewer($user) 139 + ->withBuiltinKeys( 140 + array( 141 + self::BUILTIN_GLOBAL_DEFAULT, 142 + )) 143 + ->executeOne(); 144 + 145 + if ($global) { 146 + $preferences->attachDefaultSettings($global); 147 + } 148 + 149 + return $preferences; 136 150 } 137 151 138 152 public function newTransaction($key, $value) {