From 109917a94b39e061934c9f987e779be47a6ab95e Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 Jun 2016 10:44:26 -0700 Subject: [PATCH] Turn DarkConsole settings into real settings Summary: Ref T4103. These settings long-predate proper settings and are based on hard-coded user properties. Turn them into real settings. (I didn't try to migrate the value since they're trivial to restore and only useful to developers.) Test Plan: - Toggled console on/off. - Swapped tabs. - Reloaded page, everything stayed sticky. Reviewers: chad Reviewed By: chad Subscribers: eadler Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16029 --- .../20160603.user.01.removedcenabled.sql | 2 ++ .../20160603.user.02.removedctab.sql | 2 ++ .../20160603.user.03.removedcvisible.sql | 2 ++ src/__phutil_library_map__.php | 4 +++ .../controller/DarkConsoleController.php | 34 ++++++++++++++----- .../console/core/DarkConsoleCore.php | 3 +- .../people/storage/PhabricatorUser.php | 7 ---- .../PhabricatorDarkConsoleTabSetting.php | 12 +++++++ .../PhabricatorDarkConsoleVisibleSetting.php | 12 +++++++ src/view/page/PhabricatorStandardPageView.php | 14 ++++++-- 10 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 resources/sql/autopatches/20160603.user.01.removedcenabled.sql create mode 100644 resources/sql/autopatches/20160603.user.02.removedctab.sql create mode 100644 resources/sql/autopatches/20160603.user.03.removedcvisible.sql create mode 100644 src/applications/settings/setting/PhabricatorDarkConsoleTabSetting.php create mode 100644 src/applications/settings/setting/PhabricatorDarkConsoleVisibleSetting.php diff --git a/resources/sql/autopatches/20160603.user.01.removedcenabled.sql b/resources/sql/autopatches/20160603.user.01.removedcenabled.sql new file mode 100644 index 0000000000..92d6c354e3 --- /dev/null +++ b/resources/sql/autopatches/20160603.user.01.removedcenabled.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_user.user + DROP COLUMN consoleEnabled; diff --git a/resources/sql/autopatches/20160603.user.02.removedctab.sql b/resources/sql/autopatches/20160603.user.02.removedctab.sql new file mode 100644 index 0000000000..fea865908b --- /dev/null +++ b/resources/sql/autopatches/20160603.user.02.removedctab.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_user.user + DROP COLUMN consoleTab; diff --git a/resources/sql/autopatches/20160603.user.03.removedcvisible.sql b/resources/sql/autopatches/20160603.user.03.removedcvisible.sql new file mode 100644 index 0000000000..6cf5149f42 --- /dev/null +++ b/resources/sql/autopatches/20160603.user.03.removedcvisible.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_user.user + DROP COLUMN consoleVisible; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a8c8231787..d1e5874bd3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2240,6 +2240,8 @@ phutil_register_library_map(array( 'PhabricatorDaemonsSetupCheck' => 'applications/config/check/PhabricatorDaemonsSetupCheck.php', 'PhabricatorDailyRoutineTriggerClock' => 'infrastructure/daemon/workers/clock/PhabricatorDailyRoutineTriggerClock.php', 'PhabricatorDarkConsoleSetting' => 'applications/settings/setting/PhabricatorDarkConsoleSetting.php', + 'PhabricatorDarkConsoleTabSetting' => 'applications/settings/setting/PhabricatorDarkConsoleTabSetting.php', + 'PhabricatorDarkConsoleVisibleSetting' => 'applications/settings/setting/PhabricatorDarkConsoleVisibleSetting.php', 'PhabricatorDashboard' => 'applications/dashboard/storage/PhabricatorDashboard.php', 'PhabricatorDashboardAddPanelController' => 'applications/dashboard/controller/PhabricatorDashboardAddPanelController.php', 'PhabricatorDashboardApplication' => 'applications/dashboard/application/PhabricatorDashboardApplication.php', @@ -6797,6 +6799,8 @@ phutil_register_library_map(array( 'PhabricatorDaemonsSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorDailyRoutineTriggerClock' => 'PhabricatorTriggerClock', 'PhabricatorDarkConsoleSetting' => 'PhabricatorSelectSetting', + 'PhabricatorDarkConsoleTabSetting' => 'PhabricatorInternalSetting', + 'PhabricatorDarkConsoleVisibleSetting' => 'PhabricatorInternalSetting', 'PhabricatorDashboard' => array( 'PhabricatorDashboardDAO', 'PhabricatorApplicationTransactionInterface', diff --git a/src/applications/console/controller/DarkConsoleController.php b/src/applications/console/controller/DarkConsoleController.php index 3849ee0cb5..026083cb59 100644 --- a/src/applications/console/controller/DarkConsoleController.php +++ b/src/applications/console/controller/DarkConsoleController.php @@ -17,30 +17,48 @@ final class DarkConsoleController extends PhabricatorController { return true; } - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); $response = id(new AphrontAjaxResponse())->setDisableConsole(true); - if (!$user->isLoggedIn()) { + if (!$viewer->isLoggedIn()) { return $response; } $visible = $request->getStr('visible'); if (strlen($visible)) { - $user->setConsoleVisible((int)$visible); - $user->save(); + $this->writeDarkConsoleSetting( + PhabricatorDarkConsoleVisibleSetting::SETTINGKEY, + (int)$visible); return $response; } $tab = $request->getStr('tab'); if (strlen($tab)) { - $user->setConsoleTab($tab); - $user->save(); + $this->writeDarkConsoleSetting( + PhabricatorDarkConsoleTabSetting::SETTINGKEY, + $tab); return $response; } return new Aphront404Response(); } + private function writeDarkConsoleSetting($key, $value) { + $viewer = $this->getViewer(); + $request = $this->getRequest(); + + $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); + + $editor = id(new PhabricatorUserPreferencesEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $xactions = array(); + $xactions[] = $preferences->newTransaction($key, $value); + $editor->applyTransactions($preferences, $xactions); + } + } diff --git a/src/applications/console/core/DarkConsoleCore.php b/src/applications/console/core/DarkConsoleCore.php index 2898a56e41..ddb22b9cfe 100644 --- a/src/applications/console/core/DarkConsoleCore.php +++ b/src/applications/console/core/DarkConsoleCore.php @@ -93,7 +93,8 @@ final class DarkConsoleCore extends Phobject { public function render(AphrontRequest $request) { $user = $request->getUser(); - $visible = $user ? $user->getConsoleVisible() : true; + $visible = $user->getUserSetting( + PhabricatorDarkConsoleVisibleSetting::SETTINGKEY); return javelin_tag( 'div', diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index b18aa0e4cf..0640f3c1b2 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -34,10 +34,6 @@ final class PhabricatorUser protected $availabilityCache; protected $availabilityCacheTTL; - protected $consoleEnabled = 0; - protected $consoleVisible = 0; - protected $consoleTab = ''; - protected $conduitCertificate; protected $isSystemAgent = 0; @@ -190,9 +186,6 @@ final class PhabricatorUser 'passwordSalt' => 'text32?', 'passwordHash' => 'text128?', 'profileImagePHID' => 'phid?', - 'consoleEnabled' => 'bool', - 'consoleVisible' => 'bool', - 'consoleTab' => 'text64', 'conduitCertificate' => 'text255', 'isSystemAgent' => 'bool', 'isMailingList' => 'bool', diff --git a/src/applications/settings/setting/PhabricatorDarkConsoleTabSetting.php b/src/applications/settings/setting/PhabricatorDarkConsoleTabSetting.php new file mode 100644 index 0000000000..87d66d9546 --- /dev/null +++ b/src/applications/settings/setting/PhabricatorDarkConsoleTabSetting.php @@ -0,0 +1,12 @@ +getUserSetting($setting_tab); + $visible = $user->getUserSetting($setting_visible); + } else { + $tab = null; + $visible = true; + } + return array( // NOTE: We use a generic label here to prevent input reflection // and mitigate compression attacks like BREACH. See discussion in // T3684. 'uri' => pht('Main Request'), - 'selected' => $user ? $user->getConsoleTab() : null, - 'visible' => $user ? (int)$user->getConsoleVisible() : true, + 'selected' => $tab, + 'visible' => $visible, 'headers' => $headers, ); }