mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
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
This commit is contained in:
parent
64d6593e9c
commit
109917a94b
10 changed files with 74 additions and 18 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_user.user
|
||||
DROP COLUMN consoleEnabled;
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_user.user
|
||||
DROP COLUMN consoleTab;
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_user.user
|
||||
DROP COLUMN consoleVisible;
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDarkConsoleTabSetting
|
||||
extends PhabricatorInternalSetting {
|
||||
|
||||
const SETTINGKEY = 'darkconsole.tab';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('DarkConsole Tab');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDarkConsoleVisibleSetting
|
||||
extends PhabricatorInternalSetting {
|
||||
|
||||
const SETTINGKEY = 'darkconsole.visible';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('DarkConsole Visible');
|
||||
}
|
||||
|
||||
}
|
|
@ -639,13 +639,23 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
|
|||
$headers[DarkConsoleServicesPlugin::getQueryAnalyzerHeader()] = true;
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$setting_tab = PhabricatorDarkConsoleTabSetting::SETTINGKEY;
|
||||
$setting_visible = PhabricatorDarkConsoleVisibleSetting::SETTINGKEY;
|
||||
$tab = $user->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,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue