mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 10:41:08 +01:00
Convert Diffusion blame and color into standard internal settings
Summary: Ref T4103. Modernize the blame/color toggles in Diffusion. These have no separate settings UI. Test Plan: Toggled blame and colors, reloaded pages, settings stuck. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16026
This commit is contained in:
parent
1e17fd31a4
commit
5c8ff3d37c
5 changed files with 81 additions and 17 deletions
|
@ -2319,6 +2319,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDifferentialManagementWorkflow' => 'applications/differential/management/PhabricatorDifferentialManagementWorkflow.php',
|
||||
'PhabricatorDifferentialRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php',
|
||||
'PhabricatorDiffusionApplication' => 'applications/diffusion/application/PhabricatorDiffusionApplication.php',
|
||||
'PhabricatorDiffusionBlameSetting' => 'applications/settings/setting/PhabricatorDiffusionBlameSetting.php',
|
||||
'PhabricatorDiffusionColorSetting' => 'applications/settings/setting/PhabricatorDiffusionColorSetting.php',
|
||||
'PhabricatorDiffusionConfigOptions' => 'applications/diffusion/config/PhabricatorDiffusionConfigOptions.php',
|
||||
'PhabricatorDisabledUserController' => 'applications/auth/controller/PhabricatorDisabledUserController.php',
|
||||
'PhabricatorDisplayPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDisplayPreferencesSettingsPanel.php',
|
||||
|
@ -6889,6 +6891,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDifferentialManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorDifferentialRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorDiffusionApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorDiffusionBlameSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorDiffusionColorSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorDiffusionConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorDisabledUserController' => 'PhabricatorAuthController',
|
||||
'PhabricatorDisplayPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
|
||||
|
|
|
@ -105,28 +105,31 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
$path = $drequest->getPath();
|
||||
|
||||
$preferences = $viewer->loadPreferences();
|
||||
$blame_key = PhabricatorDiffusionBlameSetting::SETTINGKEY;
|
||||
$color_key = PhabricatorDiffusionColorSetting::SETTINGKEY;
|
||||
|
||||
$show_blame = $request->getBool(
|
||||
'blame',
|
||||
$preferences->getPreference(
|
||||
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
|
||||
false));
|
||||
$viewer->getUserSetting($blame_key));
|
||||
|
||||
$show_color = $request->getBool(
|
||||
'color',
|
||||
$preferences->getPreference(
|
||||
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
|
||||
true));
|
||||
$viewer->getUserSetting($color_key));
|
||||
|
||||
$view = $request->getStr('view');
|
||||
if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) {
|
||||
$preferences->setPreference(
|
||||
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
|
||||
$show_blame);
|
||||
$preferences->setPreference(
|
||||
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
|
||||
$show_color);
|
||||
$preferences->save();
|
||||
$preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
|
||||
|
||||
$editor = id(new PhabricatorUserPreferencesEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true);
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = $preferences->newTransaction($blame_key, $show_blame);
|
||||
$xactions[] = $preferences->newTransaction($color_key, $show_color);
|
||||
$editor->applyTransactions($preferences, $xactions);
|
||||
|
||||
$uri = $request->getRequestURI()
|
||||
->alter('blame', null)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDiffusionBlameSetting
|
||||
extends PhabricatorInternalSetting {
|
||||
|
||||
const SETTINGKEY = 'diffusion-blame';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('Diffusion Blame');
|
||||
}
|
||||
|
||||
public function getSettingDefaultValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDiffusionColorSetting
|
||||
extends PhabricatorInternalSetting {
|
||||
|
||||
const SETTINGKEY = 'diffusion-color';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('Diffusion Color');
|
||||
}
|
||||
|
||||
public function getSettingDefaultValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,9 +24,6 @@ final class PhabricatorUserPreferences
|
|||
const PREFERENCE_VARY_SUBJECT = 'vary-subject';
|
||||
const PREFERENCE_HTML_EMAILS = 'html-emails';
|
||||
|
||||
const PREFERENCE_DIFFUSION_BLAME = 'diffusion-blame';
|
||||
const PREFERENCE_DIFFUSION_COLOR = 'diffusion-color';
|
||||
|
||||
const PREFERENCE_NAV_COLLAPSED = 'nav-collapsed';
|
||||
const PREFERENCE_NAV_WIDTH = 'nav-width';
|
||||
const PREFERENCE_APP_TILES = 'app-tiles';
|
||||
|
@ -172,6 +169,34 @@ final class PhabricatorUserPreferences
|
|||
return parent::save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load or create a preferences object for the given user.
|
||||
*
|
||||
* @param PhabricatorUser User to load or create preferences for.
|
||||
*/
|
||||
public static function loadUserPreferences(PhabricatorUser $user) {
|
||||
$preferences = id(new PhabricatorUserPreferencesQuery())
|
||||
->setViewer($user)
|
||||
->withUsers(array($user))
|
||||
->executeOne();
|
||||
if ($preferences) {
|
||||
return $preferences;
|
||||
}
|
||||
|
||||
return id(new self())
|
||||
->setUserPHID($user->getPHID())
|
||||
->attachUser($user);
|
||||
}
|
||||
|
||||
public function newTransaction($key, $value) {
|
||||
$setting_property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
|
||||
$xaction_type = PhabricatorUserPreferencesTransaction::TYPE_SETTING;
|
||||
|
||||
return id(clone $this->getApplicationTransactionTemplate())
|
||||
->setTransactionType($xaction_type)
|
||||
->setMetadataValue($setting_property, $key)
|
||||
->setNewValue($value);
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
|
Loading…
Reference in a new issue