From 5c8ff3d37c2a64840b054ce0b858b76f571bd2b2 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 Jun 2016 07:48:26 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 +++ .../controller/DiffusionBrowseController.php | 31 ++++++++++--------- .../PhabricatorDiffusionBlameSetting.php | 16 ++++++++++ .../PhabricatorDiffusionColorSetting.php | 16 ++++++++++ .../storage/PhabricatorUserPreferences.php | 31 +++++++++++++++++-- 5 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 src/applications/settings/setting/PhabricatorDiffusionBlameSetting.php create mode 100644 src/applications/settings/setting/PhabricatorDiffusionColorSetting.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 44b9a4c217..346f6797ab 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php index 1357bed620..30c2b8265d 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseController.php @@ -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) diff --git a/src/applications/settings/setting/PhabricatorDiffusionBlameSetting.php b/src/applications/settings/setting/PhabricatorDiffusionBlameSetting.php new file mode 100644 index 0000000000..bc98045506 --- /dev/null +++ b/src/applications/settings/setting/PhabricatorDiffusionBlameSetting.php @@ -0,0 +1,16 @@ +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 )----------------------------------------- */