@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Deprecate "user.enable" and "user.disable" API methods, redefine them in terms of "user.edit"

Summary:
Depends on D19604. Ref T13189. See PHI642. Deprecates these in favor of "user.edit", redefines them in terms of it, and removes the old `disableUser()` method.

I kept the "is admin" permissions check for consistency, since these methods have always said "(admin only)". This check may not be the most tailored check soon, but we can just keep executing it in addition to the real check.

For now, this change stops this method from actually disabling non-bot users (since it implicitly adds a CAN_EDIT requirement, and even administrators don't have that). An upcoming change will fix that.

Test Plan: Enabled and disabled a (bot) user via these methods. Checked API UI, saw them marked as "disabled".

Reviewers: amckinley

Maniphest Tasks: T13189

Differential Revision: https://secure.phabricator.com/D19605

+48 -47
+24 -4
src/applications/people/conduit/UserDisableConduitAPIMethod.php
··· 10 10 return pht('Permanently disable specified users (admin only).'); 11 11 } 12 12 13 + public function getMethodStatus() { 14 + return self::METHOD_STATUS_DEPRECATED; 15 + } 16 + 17 + public function getMethodStatusDescription() { 18 + return pht('Obsoleted by method "user.edit".'); 19 + } 20 + 13 21 protected function defineParamTypes() { 14 22 return array( 15 23 'phids' => 'required list<phid>', ··· 43 51 throw new ConduitException('ERR-BAD-PHID'); 44 52 } 45 53 46 - foreach ($users as $user) { 47 - id(new PhabricatorUserEditor()) 48 - ->setActor($actor) 49 - ->disableUser($user, true); 54 + foreach ($phids as $phid) { 55 + $params = array( 56 + 'transactions' => array( 57 + array( 58 + 'type' => 'disabled', 59 + 'value' => true, 60 + ), 61 + ), 62 + 'objectIdentifier' => $phid, 63 + ); 64 + 65 + id(new ConduitCall('user.edit', $params)) 66 + ->setUser($actor) 67 + ->execute(); 50 68 } 69 + 70 + return null; 51 71 } 52 72 53 73 }
+24 -4
src/applications/people/conduit/UserEnableConduitAPIMethod.php
··· 10 10 return pht('Re-enable specified users (admin only).'); 11 11 } 12 12 13 + public function getMethodStatus() { 14 + return self::METHOD_STATUS_DEPRECATED; 15 + } 16 + 17 + public function getMethodStatusDescription() { 18 + return pht('Obsoleted by method "user.edit".'); 19 + } 20 + 13 21 protected function defineParamTypes() { 14 22 return array( 15 23 'phids' => 'required list<phid>', ··· 43 51 throw new ConduitException('ERR-BAD-PHID'); 44 52 } 45 53 46 - foreach ($users as $user) { 47 - id(new PhabricatorUserEditor()) 48 - ->setActor($actor) 49 - ->disableUser($user, false); 54 + foreach ($phids as $phid) { 55 + $params = array( 56 + 'transactions' => array( 57 + array( 58 + 'type' => 'disabled', 59 + 'value' => false, 60 + ), 61 + ), 62 + 'objectIdentifier' => $phid, 63 + ); 64 + 65 + id(new ConduitCall('user.edit', $params)) 66 + ->setUser($actor) 67 + ->execute(); 50 68 } 69 + 70 + return null; 51 71 } 52 72 53 73 }
-39
src/applications/people/editor/PhabricatorUserEditor.php
··· 296 296 /** 297 297 * @task role 298 298 */ 299 - public function disableUser(PhabricatorUser $user, $disable) { 300 - $actor = $this->requireActor(); 301 - 302 - if (!$user->getID()) { 303 - throw new Exception(pht('User has not been created yet!')); 304 - } 305 - 306 - $user->openTransaction(); 307 - $user->beginWriteLocking(); 308 - 309 - $user->reload(); 310 - if ($user->getIsDisabled() == $disable) { 311 - $user->endWriteLocking(); 312 - $user->killTransaction(); 313 - return $this; 314 - } 315 - 316 - $log = PhabricatorUserLog::initializeNewLog( 317 - $actor, 318 - $user->getPHID(), 319 - PhabricatorUserLog::ACTION_DISABLE); 320 - $log->setOldValue($user->getIsDisabled()); 321 - $log->setNewValue($disable); 322 - 323 - $user->setIsDisabled((int)$disable); 324 - $user->save(); 325 - 326 - $log->save(); 327 - 328 - $user->endWriteLocking(); 329 - $user->saveTransaction(); 330 - 331 - return $this; 332 - } 333 - 334 - 335 - /** 336 - * @task role 337 - */ 338 299 public function approveUser(PhabricatorUser $user, $approve) { 339 300 $actor = $this->requireActor(); 340 301