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

Add a modern "user.edit" API method for users

Summary:
Depends on D19576. Ref T13164. See PHI642. This adds an EditEngine for users and a `user.edit` modern API method.

For now, all it supports is editing real name, blurb, title, and icon (same as "Edit Profile" from the UI).

Test Plan:
- Edited my stuff via the new API method.
- Tried to edit another user, got rejected by policies.
- Tried to create a user, got rejected by policies.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13164

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

+178
+4
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 + 'PhabricatorUserEditEngine' => 'applications/people/editor/PhabricatorUserEditEngine.php', 4565 4566 'PhabricatorUserEditor' => 'applications/people/editor/PhabricatorUserEditor.php', 4566 4567 'PhabricatorUserEditorTestCase' => 'applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php', 4567 4568 'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php', ··· 5233 5234 'TransactionSearchConduitAPIMethod' => 'applications/transactions/conduit/TransactionSearchConduitAPIMethod.php', 5234 5235 'UserConduitAPIMethod' => 'applications/people/conduit/UserConduitAPIMethod.php', 5235 5236 'UserDisableConduitAPIMethod' => 'applications/people/conduit/UserDisableConduitAPIMethod.php', 5237 + 'UserEditConduitAPIMethod' => 'applications/people/conduit/UserEditConduitAPIMethod.php', 5236 5238 'UserEnableConduitAPIMethod' => 'applications/people/conduit/UserEnableConduitAPIMethod.php', 5237 5239 'UserFindConduitAPIMethod' => 'applications/people/conduit/UserFindConduitAPIMethod.php', 5238 5240 'UserQueryConduitAPIMethod' => 'applications/people/conduit/UserQueryConduitAPIMethod.php', ··· 10547 10549 'PhabricatorUserCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 10548 10550 'PhabricatorUserCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 10549 10551 'PhabricatorUserDAO' => 'PhabricatorLiskDAO', 10552 + 'PhabricatorUserEditEngine' => 'PhabricatorEditEngine', 10550 10553 'PhabricatorUserEditor' => 'PhabricatorEditor', 10551 10554 'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase', 10552 10555 'PhabricatorUserEmail' => 'PhabricatorUserDAO', ··· 11388 11391 'TransactionSearchConduitAPIMethod' => 'ConduitAPIMethod', 11389 11392 'UserConduitAPIMethod' => 'ConduitAPIMethod', 11390 11393 'UserDisableConduitAPIMethod' => 'UserConduitAPIMethod', 11394 + 'UserEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 11391 11395 'UserEnableConduitAPIMethod' => 'UserConduitAPIMethod', 11392 11396 'UserFindConduitAPIMethod' => 'UserConduitAPIMethod', 11393 11397 'UserQueryConduitAPIMethod' => 'UserConduitAPIMethod',
+20
src/applications/people/conduit/UserEditConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class UserEditConduitAPIMethod 4 + extends PhabricatorEditEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'user.edit'; 8 + } 9 + 10 + public function newEditEngine() { 11 + return new PhabricatorUserEditEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht( 16 + 'Apply transactions to edit a user. (Users can not be created via '. 17 + 'the API.)'); 18 + } 19 + 20 + }
+21
src/applications/people/customfield/PhabricatorUserBlurbField.php
··· 9 9 return 'user:blurb'; 10 10 } 11 11 12 + public function getModernFieldKey() { 13 + return 'blurb'; 14 + } 15 + 16 + public function getFieldKeyForConduit() { 17 + return $this->getModernFieldKey(); 18 + } 19 + 12 20 public function getFieldName() { 13 21 return pht('Blurb'); 14 22 } ··· 50 58 $this->value = $request->getStr($this->getFieldKey()); 51 59 } 52 60 61 + public function setValueFromStorage($value) { 62 + $this->value = $value; 63 + return $this; 64 + } 65 + 53 66 public function renderEditControl(array $handles) { 54 67 return id(new PhabricatorRemarkupControl()) 55 68 ->setUser($this->getViewer()) ··· 83 96 84 97 public function getStyleForPropertyView() { 85 98 return 'block'; 99 + } 100 + 101 + public function shouldAppearInConduitTransactions() { 102 + return true; 103 + } 104 + 105 + protected function newConduitEditParameterType() { 106 + return new ConduitStringParameterType(); 86 107 } 87 108 88 109 }
+21
src/applications/people/customfield/PhabricatorUserIconField.php
··· 9 9 return 'user:icon'; 10 10 } 11 11 12 + public function getModernFieldKey() { 13 + return 'icon'; 14 + } 15 + 16 + public function getFieldKeyForConduit() { 17 + return $this->getModernFieldKey(); 18 + } 19 + 12 20 public function getFieldName() { 13 21 return pht('Icon'); 14 22 } ··· 50 58 $this->value = $request->getStr($this->getFieldKey()); 51 59 } 52 60 61 + public function setValueFromStorage($value) { 62 + $this->value = $value; 63 + return $this; 64 + } 65 + 53 66 public function renderEditControl(array $handles) { 54 67 return id(new PHUIFormIconSetControl()) 55 68 ->setName($this->getFieldKey()) 56 69 ->setValue($this->value) 57 70 ->setLabel($this->getFieldName()) 58 71 ->setIconSet(new PhabricatorPeopleIconSet()); 72 + } 73 + 74 + public function shouldAppearInConduitTransactions() { 75 + return true; 76 + } 77 + 78 + protected function newConduitEditParameterType() { 79 + return new ConduitStringParameterType(); 59 80 } 60 81 61 82 }
+21
src/applications/people/customfield/PhabricatorUserRealNameField.php
··· 9 9 return 'user:realname'; 10 10 } 11 11 12 + public function getModernFieldKey() { 13 + return 'realName'; 14 + } 15 + 16 + public function getFieldKeyForConduit() { 17 + return $this->getModernFieldKey(); 18 + } 19 + 12 20 public function getFieldName() { 13 21 return pht('Real Name'); 14 22 } ··· 53 61 $this->value = $request->getStr($this->getFieldKey()); 54 62 } 55 63 64 + public function setValueFromStorage($value) { 65 + $this->value = $value; 66 + return $this; 67 + } 68 + 56 69 public function renderEditControl(array $handles) { 57 70 return id(new AphrontFormTextControl()) 58 71 ->setName($this->getFieldKey()) ··· 63 76 64 77 private function isEditable() { 65 78 return PhabricatorEnv::getEnvConfig('account.editable'); 79 + } 80 + 81 + public function shouldAppearInConduitTransactions() { 82 + return true; 83 + } 84 + 85 + protected function newConduitEditParameterType() { 86 + return new ConduitStringParameterType(); 66 87 } 67 88 68 89 }
+21
src/applications/people/customfield/PhabricatorUserTitleField.php
··· 9 9 return 'user:title'; 10 10 } 11 11 12 + public function getModernFieldKey() { 13 + return 'title'; 14 + } 15 + 16 + public function getFieldKeyForConduit() { 17 + return $this->getModernFieldKey(); 18 + } 19 + 12 20 public function getFieldName() { 13 21 return pht('Title'); 14 22 } ··· 50 58 $this->value = $request->getStr($this->getFieldKey()); 51 59 } 52 60 61 + public function setValueFromStorage($value) { 62 + $this->value = $value; 63 + return $this; 64 + } 65 + 53 66 public function renderEditControl(array $handles) { 54 67 return id(new AphrontFormTextControl()) 55 68 ->setName($this->getFieldKey()) 56 69 ->setValue($this->value) 57 70 ->setLabel($this->getFieldName()); 71 + } 72 + 73 + public function shouldAppearInConduitTransactions() { 74 + return true; 75 + } 76 + 77 + protected function newConduitEditParameterType() { 78 + return new ConduitStringParameterType(); 58 79 } 59 80 60 81 }
+70
src/applications/people/editor/PhabricatorUserEditEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorUserEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'people.user'; 7 + 8 + public function isEngineConfigurable() { 9 + return false; 10 + } 11 + 12 + public function getEngineName() { 13 + return pht('Users'); 14 + } 15 + 16 + public function getSummaryHeader() { 17 + return pht('Configure User Forms'); 18 + } 19 + 20 + public function getSummaryText() { 21 + return pht('Configure creation and editing forms for users.'); 22 + } 23 + 24 + public function getEngineApplicationClass() { 25 + return 'PhabricatorPeopleApplication'; 26 + } 27 + 28 + protected function newEditableObject() { 29 + return new PhabricatorUser(); 30 + } 31 + 32 + protected function newObjectQuery() { 33 + return id(new PhabricatorPeopleQuery()); 34 + } 35 + 36 + protected function getObjectCreateTitleText($object) { 37 + return pht('Create New User'); 38 + } 39 + 40 + protected function getObjectEditTitleText($object) { 41 + return pht('Edit User: %s', $object->getUsername()); 42 + } 43 + 44 + protected function getObjectEditShortText($object) { 45 + return $object->getMonogram(); 46 + } 47 + 48 + protected function getObjectCreateShortText() { 49 + return pht('Create User'); 50 + } 51 + 52 + protected function getObjectName() { 53 + return pht('User'); 54 + } 55 + 56 + protected function getObjectViewURI($object) { 57 + return $object->getURI(); 58 + } 59 + 60 + protected function getCreateNewObjectPolicy() { 61 + // At least for now, forbid creating new users via EditEngine. This is 62 + // primarily enforcing that "user.edit" can not create users via the API. 63 + return PhabricatorPolicies::POLICY_NOONE; 64 + } 65 + 66 + protected function buildCustomEditFields($object) { 67 + return array(); 68 + } 69 + 70 + }