mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
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
This commit is contained in:
parent
39d415e90e
commit
65904d7c51
7 changed files with 178 additions and 0 deletions
|
@ -4562,6 +4562,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserCustomFieldNumericIndex' => 'applications/people/storage/PhabricatorUserCustomFieldNumericIndex.php',
|
||||
'PhabricatorUserCustomFieldStringIndex' => 'applications/people/storage/PhabricatorUserCustomFieldStringIndex.php',
|
||||
'PhabricatorUserDAO' => 'applications/people/storage/PhabricatorUserDAO.php',
|
||||
'PhabricatorUserEditEngine' => 'applications/people/editor/PhabricatorUserEditEngine.php',
|
||||
'PhabricatorUserEditor' => 'applications/people/editor/PhabricatorUserEditor.php',
|
||||
'PhabricatorUserEditorTestCase' => 'applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php',
|
||||
'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php',
|
||||
|
@ -5233,6 +5234,7 @@ phutil_register_library_map(array(
|
|||
'TransactionSearchConduitAPIMethod' => 'applications/transactions/conduit/TransactionSearchConduitAPIMethod.php',
|
||||
'UserConduitAPIMethod' => 'applications/people/conduit/UserConduitAPIMethod.php',
|
||||
'UserDisableConduitAPIMethod' => 'applications/people/conduit/UserDisableConduitAPIMethod.php',
|
||||
'UserEditConduitAPIMethod' => 'applications/people/conduit/UserEditConduitAPIMethod.php',
|
||||
'UserEnableConduitAPIMethod' => 'applications/people/conduit/UserEnableConduitAPIMethod.php',
|
||||
'UserFindConduitAPIMethod' => 'applications/people/conduit/UserFindConduitAPIMethod.php',
|
||||
'UserQueryConduitAPIMethod' => 'applications/people/conduit/UserQueryConduitAPIMethod.php',
|
||||
|
@ -10547,6 +10549,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
||||
'PhabricatorUserCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
|
||||
'PhabricatorUserDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorUserEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhabricatorUserEditor' => 'PhabricatorEditor',
|
||||
'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
|
||||
|
@ -11388,6 +11391,7 @@ phutil_register_library_map(array(
|
|||
'TransactionSearchConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'UserConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'UserDisableConduitAPIMethod' => 'UserConduitAPIMethod',
|
||||
'UserEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
'UserEnableConduitAPIMethod' => 'UserConduitAPIMethod',
|
||||
'UserFindConduitAPIMethod' => 'UserConduitAPIMethod',
|
||||
'UserQueryConduitAPIMethod' => 'UserConduitAPIMethod',
|
||||
|
|
20
src/applications/people/conduit/UserEditConduitAPIMethod.php
Normal file
20
src/applications/people/conduit/UserEditConduitAPIMethod.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
final class UserEditConduitAPIMethod
|
||||
extends PhabricatorEditEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'user.edit';
|
||||
}
|
||||
|
||||
public function newEditEngine() {
|
||||
return new PhabricatorUserEditEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht(
|
||||
'Apply transactions to edit a user. (Users can not be created via '.
|
||||
'the API.)');
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,14 @@ final class PhabricatorUserBlurbField
|
|||
return 'user:blurb';
|
||||
}
|
||||
|
||||
public function getModernFieldKey() {
|
||||
return 'blurb';
|
||||
}
|
||||
|
||||
public function getFieldKeyForConduit() {
|
||||
return $this->getModernFieldKey();
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Blurb');
|
||||
}
|
||||
|
@ -50,6 +58,11 @@ final class PhabricatorUserBlurbField
|
|||
$this->value = $request->getStr($this->getFieldKey());
|
||||
}
|
||||
|
||||
public function setValueFromStorage($value) {
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
return id(new PhabricatorRemarkupControl())
|
||||
->setUser($this->getViewer())
|
||||
|
@ -85,4 +98,12 @@ final class PhabricatorUserBlurbField
|
|||
return 'block';
|
||||
}
|
||||
|
||||
public function shouldAppearInConduitTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newConduitEditParameterType() {
|
||||
return new ConduitStringParameterType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ final class PhabricatorUserIconField
|
|||
return 'user:icon';
|
||||
}
|
||||
|
||||
public function getModernFieldKey() {
|
||||
return 'icon';
|
||||
}
|
||||
|
||||
public function getFieldKeyForConduit() {
|
||||
return $this->getModernFieldKey();
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Icon');
|
||||
}
|
||||
|
@ -50,6 +58,11 @@ final class PhabricatorUserIconField
|
|||
$this->value = $request->getStr($this->getFieldKey());
|
||||
}
|
||||
|
||||
public function setValueFromStorage($value) {
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
return id(new PHUIFormIconSetControl())
|
||||
->setName($this->getFieldKey())
|
||||
|
@ -58,4 +71,12 @@ final class PhabricatorUserIconField
|
|||
->setIconSet(new PhabricatorPeopleIconSet());
|
||||
}
|
||||
|
||||
public function shouldAppearInConduitTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newConduitEditParameterType() {
|
||||
return new ConduitStringParameterType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ final class PhabricatorUserRealNameField
|
|||
return 'user:realname';
|
||||
}
|
||||
|
||||
public function getModernFieldKey() {
|
||||
return 'realName';
|
||||
}
|
||||
|
||||
public function getFieldKeyForConduit() {
|
||||
return $this->getModernFieldKey();
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Real Name');
|
||||
}
|
||||
|
@ -53,6 +61,11 @@ final class PhabricatorUserRealNameField
|
|||
$this->value = $request->getStr($this->getFieldKey());
|
||||
}
|
||||
|
||||
public function setValueFromStorage($value) {
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
return id(new AphrontFormTextControl())
|
||||
->setName($this->getFieldKey())
|
||||
|
@ -65,4 +78,12 @@ final class PhabricatorUserRealNameField
|
|||
return PhabricatorEnv::getEnvConfig('account.editable');
|
||||
}
|
||||
|
||||
public function shouldAppearInConduitTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newConduitEditParameterType() {
|
||||
return new ConduitStringParameterType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ final class PhabricatorUserTitleField
|
|||
return 'user:title';
|
||||
}
|
||||
|
||||
public function getModernFieldKey() {
|
||||
return 'title';
|
||||
}
|
||||
|
||||
public function getFieldKeyForConduit() {
|
||||
return $this->getModernFieldKey();
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Title');
|
||||
}
|
||||
|
@ -50,6 +58,11 @@ final class PhabricatorUserTitleField
|
|||
$this->value = $request->getStr($this->getFieldKey());
|
||||
}
|
||||
|
||||
public function setValueFromStorage($value) {
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
return id(new AphrontFormTextControl())
|
||||
->setName($this->getFieldKey())
|
||||
|
@ -57,4 +70,12 @@ final class PhabricatorUserTitleField
|
|||
->setLabel($this->getFieldName());
|
||||
}
|
||||
|
||||
public function shouldAppearInConduitTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newConduitEditParameterType() {
|
||||
return new ConduitStringParameterType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
70
src/applications/people/editor/PhabricatorUserEditEngine.php
Normal file
70
src/applications/people/editor/PhabricatorUserEditEngine.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserEditEngine
|
||||
extends PhabricatorEditEngine {
|
||||
|
||||
const ENGINECONST = 'people.user';
|
||||
|
||||
public function isEngineConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Users');
|
||||
}
|
||||
|
||||
public function getSummaryHeader() {
|
||||
return pht('Configure User Forms');
|
||||
}
|
||||
|
||||
public function getSummaryText() {
|
||||
return pht('Configure creation and editing forms for users.');
|
||||
}
|
||||
|
||||
public function getEngineApplicationClass() {
|
||||
return 'PhabricatorPeopleApplication';
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
return new PhabricatorUser();
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return id(new PhabricatorPeopleQuery());
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
return pht('Create New User');
|
||||
}
|
||||
|
||||
protected function getObjectEditTitleText($object) {
|
||||
return pht('Edit User: %s', $object->getUsername());
|
||||
}
|
||||
|
||||
protected function getObjectEditShortText($object) {
|
||||
return $object->getMonogram();
|
||||
}
|
||||
|
||||
protected function getObjectCreateShortText() {
|
||||
return pht('Create User');
|
||||
}
|
||||
|
||||
protected function getObjectName() {
|
||||
return pht('User');
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
return $object->getURI();
|
||||
}
|
||||
|
||||
protected function getCreateNewObjectPolicy() {
|
||||
// At least for now, forbid creating new users via EditEngine. This is
|
||||
// primarily enforcing that "user.edit" can not create users via the API.
|
||||
return PhabricatorPolicies::POLICY_NOONE;
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue