forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDarkConsoleController.php
75 lines (59 loc) · 2.13 KB
/
DarkConsoleController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
final class DarkConsoleController extends PhabricatorController {
protected $op;
protected $data;
public function shouldRequireLogin() {
return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
}
public function shouldRequireEnabledUser() {
return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
}
public function shouldAllowPartialSessions() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$response = id(new AphrontAjaxResponse())->setDisableConsole(true);
if (!$viewer->isLoggedIn()) {
return $response;
}
$visible = $request->getStr('visible');
if (strlen($visible)) {
$this->writeDarkConsoleSetting(
PhabricatorDarkConsoleVisibleSetting::SETTINGKEY,
(int)$visible);
return $response;
}
$tab = $request->getStr('tab');
if (strlen($tab)) {
$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);
// Reload the user to regenerate their preferences cache. If we don't
// do this, the "Services" tab gets misleadingly spammed up with cache
// fills that are only filling because you toggled the console or switched
// tabs. This makes it harder to see what's really going on, so just force
// a cache regeneration here.
id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($viewer->getPHID()))
->needUserSettings(true)
->execute();
}
}