Skip to content

Commit 814fa13

Browse files
author
epriestley
committed
Centralize "this is the current user for the request" code
Summary: Ref T11098. This primarily fixes Conduit calls to `*.edit` methods failing when trying to access user preferences. (The actual access is a little weird, since it seems like we're building some UI stuff inside a policy query, but that's an issue for another time.) To fix this, consolidate the "we're about to run some kind of request with this user" code and run it consistently for web, conduit, and SSH sessions. Additionally, make sure we swap things to the user's translation. Test Plan: - Ran `maniphest.edit` via `arc call-conduit`, no more settings exception. - Set translation to ALL CAPS, got all caps output from `ssh` and Conduit. Reviewers: avivey, chad Reviewed By: chad Maniphest Tasks: T11098 Differential Revision: https://secure.phabricator.com/D16066
1 parent 8a7ded6 commit 814fa13

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

scripts/ssh/ssh-exec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
'Invalid username ("%s"). There is no user with this username.',
104104
$user_name));
105105
}
106+
107+
id(new PhabricatorAuthSessionEngine())
108+
->willServeRequestForUser($user);
106109
} else if (strlen($device_name)) {
107110
if (!$remote_address) {
108111
throw new Exception(

src/applications/auth/engine/PhabricatorAuthSessionEngine.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public function loadUserForSession($session_type, $session_token) {
164164

165165
$cache_raw = $this->filterRawCacheData($user, $types_map, $cache_raw);
166166
$user->attachRawCacheData($cache_raw);
167-
$user->setAllowInlineCacheGeneration(true);
168167

169168
switch ($session_type) {
170169
case PhabricatorAuthSession::TYPE_WEB:
@@ -832,4 +831,12 @@ private function filterRawCacheData(
832831
return $cache_raw;
833832
}
834833

834+
public function willServeRequestForUser(PhabricatorUser $user) {
835+
// We allow the login user to generate any missing cache data inline.
836+
$user->setAllowInlineCacheGeneration(true);
837+
838+
// Switch to the user's translation.
839+
PhabricatorEnv::setLocaleCode($user->getTranslation());
840+
}
841+
835842
}

src/applications/base/controller/PhabricatorController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public function willBeginExecution() {
104104
$request->setUser($user);
105105
}
106106

107-
PhabricatorEnv::setLocaleCode($user->getTranslation());
107+
id(new PhabricatorAuthSessionEngine())
108+
->willServeRequestForUser($user);
108109

109110
if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
110111
$dark_console = PhabricatorDarkConsoleSetting::SETTINGKEY;

src/applications/conduit/controller/PhabricatorConduitAPIController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ private function validateAuthenticatedUser(
487487
}
488488

489489
$request->setUser($user);
490+
491+
id(new PhabricatorAuthSessionEngine())
492+
->willServeRequestForUser($user);
493+
490494
return null;
491495
}
492496

0 commit comments

Comments
 (0)