mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Provide new tool "bin/user approve" to approve an account.
Summary: T13578 Test Plan: This method uses the existing transaction. As such, most of the testing focused on the integration between the workflow and transaction. The only change made to the transaction was to allow an omnipotent user to make the change in addition to an admin. Other than that, I removed the "approved" flag from the user, then ran the command-line utilty until the user was successfully approved. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T13578 Differential Revision: https://secure.phabricator.com/D21587
This commit is contained in:
parent
33bce22ef2
commit
c0ac5be8a8
3 changed files with 50 additions and 1 deletions
|
@ -4164,6 +4164,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleMailEngine' => 'applications/people/mail/PhabricatorPeopleMailEngine.php',
|
||||
'PhabricatorPeopleMailEngineException' => 'applications/people/mail/PhabricatorPeopleMailEngineException.php',
|
||||
'PhabricatorPeopleManageProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php',
|
||||
'PhabricatorPeopleManagementApproveWorkflow' => 'applications/people/management/PhabricatorPeopleManagementApproveWorkflow.php',
|
||||
'PhabricatorPeopleManagementEmpowerWorkflow' => 'applications/people/management/PhabricatorPeopleManagementEmpowerWorkflow.php',
|
||||
'PhabricatorPeopleManagementEnableWorkflow' => 'applications/people/management/PhabricatorPeopleManagementEnableWorkflow.php',
|
||||
'PhabricatorPeopleManagementWorkflow' => 'applications/people/management/PhabricatorPeopleManagementWorkflow.php',
|
||||
|
@ -10807,6 +10808,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleMailEngine' => 'Phobject',
|
||||
'PhabricatorPeopleMailEngineException' => 'Exception',
|
||||
'PhabricatorPeopleManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorPeopleManagementApproveWorkflow' => 'PhabricatorPeopleManagementWorkflow',
|
||||
'PhabricatorPeopleManagementEmpowerWorkflow' => 'PhabricatorPeopleManagementWorkflow',
|
||||
'PhabricatorPeopleManagementEnableWorkflow' => 'PhabricatorPeopleManagementWorkflow',
|
||||
'PhabricatorPeopleManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
|
||||
final class PhabricatorPeopleManagementApproveWorkflow
|
||||
extends PhabricatorPeopleManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$arguments = array_merge(
|
||||
$this->getUserSelectionArguments(),
|
||||
array());
|
||||
|
||||
$this
|
||||
->setName('approve')
|
||||
->setExamples('**approve** --user __username__')
|
||||
->setSynopsis(pht('Approves a user.'))
|
||||
->setArguments($arguments);
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$user = $this->selectUser($args);
|
||||
$display_name = $user->getUsername();
|
||||
|
||||
if ($user->getIsApproved()) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'User account "%s" is already approved. You can only '.
|
||||
'approve accounts that are not yet approved.',
|
||||
$display_name));
|
||||
}
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = $user->getApplicationTransactionTemplate()
|
||||
->setTransactionType(PhabricatorUserApproveTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue(true);
|
||||
|
||||
$this->applyTransactions($user, $xactions);
|
||||
|
||||
$this->logOkay(
|
||||
pht('DONE'),
|
||||
pht('Approved user account "%s".', $display_name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -71,7 +71,10 @@ final class PhabricatorUserApproveTransaction
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!$actor->getIsAdmin()) {
|
||||
$is_admin = $actor->getIsAdmin();
|
||||
$is_omnipotent = $actor->isOmnipotent();
|
||||
|
||||
if (!$is_admin && !$is_omnipotent) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht('You must be an administrator to approve users.'));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue