@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.

Allow "user.edit" to enable or disable users

Summary:
Depends on D19577. Ref T13164. See PHI642. This adds modern transaction-oriented enable/disable support.

Currently, this also doesn't let you disable normal users even when you're an administrator. I'll refine the policy model later in this change series, since that's also the goal here (let users set "Can Disable Users" to some more broad set of users than "Administrators").

This also leaves us with two different edit pathways: the old UserEditor one and the new UserTransactionEditor one. The next couple diffs will redefine the other pathways in terms of this pathway.

Test Plan:
- Enabled/disabled a bot.
- Tried to disable another non-bot user. This isn't allowed yet, since even as an administrator you don't have CAN_EDIT on them and currently need it: right now, there's no way for a particular set of transactions to say they can move forward with reduced permissions.
- Tried to enable/disable myself. This isn't allowed since you can't enable/disable yourself.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13164

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

+96 -2
+2
src/__phutil_library_map__.php
··· 4562 4562 'PhabricatorUserCustomFieldNumericIndex' => 'applications/people/storage/PhabricatorUserCustomFieldNumericIndex.php', 4563 4563 'PhabricatorUserCustomFieldStringIndex' => 'applications/people/storage/PhabricatorUserCustomFieldStringIndex.php', 4564 4564 'PhabricatorUserDAO' => 'applications/people/storage/PhabricatorUserDAO.php', 4565 + 'PhabricatorUserDisableTransaction' => 'applications/people/xaction/PhabricatorUserDisableTransaction.php', 4565 4566 'PhabricatorUserEditEngine' => 'applications/people/editor/PhabricatorUserEditEngine.php', 4566 4567 'PhabricatorUserEditor' => 'applications/people/editor/PhabricatorUserEditor.php', 4567 4568 'PhabricatorUserEditorTestCase' => 'applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php', ··· 10549 10550 'PhabricatorUserCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 10550 10551 'PhabricatorUserCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 10551 10552 'PhabricatorUserDAO' => 'PhabricatorLiskDAO', 10553 + 'PhabricatorUserDisableTransaction' => 'PhabricatorUserTransactionType', 10552 10554 'PhabricatorUserEditEngine' => 'PhabricatorEditEngine', 10553 10555 'PhabricatorUserEditor' => 'PhabricatorEditor', 10554 10556 'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase',
+12 -1
src/applications/people/editor/PhabricatorUserEditEngine.php
··· 64 64 } 65 65 66 66 protected function buildCustomEditFields($object) { 67 - return array(); 67 + return array( 68 + id(new PhabricatorBoolEditField()) 69 + ->setKey('disabled') 70 + ->setOptions(pht('Active'), pht('Disabled')) 71 + ->setLabel(pht('Disabled')) 72 + ->setDescription(pht('Disable the user.')) 73 + ->setTransactionType(PhabricatorUserDisableTransaction::TRANSACTIONTYPE) 74 + ->setIsConduitOnly(true) 75 + ->setConduitDescription(pht('Disable or enable the user.')) 76 + ->setConduitTypeDescription(pht('True to disable the user.')) 77 + ->setValue($object->getIsDisabled()), 78 + ); 68 79 } 69 80 70 81 }
+72
src/applications/people/xaction/PhabricatorUserDisableTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorUserDisableTransaction 4 + extends PhabricatorUserTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'user.disable'; 7 + 8 + public function generateOldValue($object) { 9 + return (bool)$object->getIsDisabled(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (bool)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setIsDisabled((int)$value); 18 + 19 + $this->newUserLog(PhabricatorUserLog::ACTION_DISABLE) 20 + ->setOldValue((bool)$object->getIsDisabled()) 21 + ->setNewValue((bool)$value) 22 + ->save(); 23 + } 24 + 25 + public function getTitle() { 26 + $new = $this->getNewValue(); 27 + if ($new) { 28 + return pht( 29 + '%s disabled this user.', 30 + $this->renderAuthor()); 31 + } else { 32 + return pht( 33 + '%s enabled this user.', 34 + $this->renderAuthor()); 35 + } 36 + } 37 + 38 + public function getTitleForFeed() { 39 + $new = $this->getNewValue(); 40 + if ($new) { 41 + return pht( 42 + '%s disabled %s.', 43 + $this->renderAuthor(), 44 + $this->renderObject()); 45 + } else { 46 + return pht( 47 + '%s enabled %s.', 48 + $this->renderAuthor(), 49 + $this->renderObject()); 50 + } 51 + } 52 + 53 + public function validateTransactions($object, array $xactions) { 54 + $errors = array(); 55 + 56 + foreach ($xactions as $xaction) { 57 + $is_disabled = (bool)$object->getIsDisabled(); 58 + 59 + if ((bool)$xaction->getNewValue() === $is_disabled) { 60 + continue; 61 + } 62 + 63 + if ($this->getActingAsPHID() === $object->getPHID()) { 64 + $errors[] = $this->newInvalidError( 65 + pht('You can not enable or disable your own account.')); 66 + } 67 + } 68 + 69 + return $errors; 70 + } 71 + 72 + }
+10 -1
src/applications/people/xaction/PhabricatorUserTransactionType.php
··· 1 1 <?php 2 2 3 3 abstract class PhabricatorUserTransactionType 4 - extends PhabricatorModularTransactionType {} 4 + extends PhabricatorModularTransactionType { 5 + 6 + protected function newUserLog($action) { 7 + return PhabricatorUserLog::initializeNewLog( 8 + $this->getActor(), 9 + $this->getObject()->getPHID(), 10 + $action); 11 + } 12 + 13 + }