Skip to content

Commit fc34554

Browse files
author
epriestley
committedAug 21, 2019
Replace "bin/people profileimage" with "bin/user enable|empower"
Summary: Ref T13382. - Remove "bin/people profileimage" which previously generated profile image caches but now feels obsolete. - Replace it with "bin/user", with "enable" and "empower" flows. This command is now focused on regaining access to an install after you lock your keys inside. - Document the various ways to unlock objects and accounts from the CLI. Test Plan: - Ran `bin/user enable` and `bin/user empower` with various flags. - Grepped for `people profileimage` and found no references. - Grepped for `bin/people` and found no references. - Read documentation. Maniphest Tasks: T13382 Differential Revision: https://secure.phabricator.com/D20724
1 parent 721a864 commit fc34554

9 files changed

+253
-122
lines changed
 

‎bin/people

-1
This file was deleted.

‎bin/user

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_user.php

‎scripts/people/manage_people.php ‎scripts/setup/manage_user.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
$args = new PhutilArgumentParser($argv);
88
$args->setSynopsis(<<<EOSYNOPSIS
9-
**people** __command__ [__options__]
10-
Manage user profiles and accounts.
9+
**user** __command__ [__options__]
10+
Modify user accounts to regain access to an install.
1111
1212
EOSYNOPSIS
1313
);

‎src/__phutil_library_map__.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,8 @@
40514051
'PhabricatorPeopleMailEngine' => 'applications/people/mail/PhabricatorPeopleMailEngine.php',
40524052
'PhabricatorPeopleMailEngineException' => 'applications/people/mail/PhabricatorPeopleMailEngineException.php',
40534053
'PhabricatorPeopleManageProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php',
4054+
'PhabricatorPeopleManagementEmpowerWorkflow' => 'applications/people/management/PhabricatorPeopleManagementEmpowerWorkflow.php',
4055+
'PhabricatorPeopleManagementEnableWorkflow' => 'applications/people/management/PhabricatorPeopleManagementEnableWorkflow.php',
40544056
'PhabricatorPeopleManagementWorkflow' => 'applications/people/management/PhabricatorPeopleManagementWorkflow.php',
40554057
'PhabricatorPeopleNewController' => 'applications/people/controller/PhabricatorPeopleNewController.php',
40564058
'PhabricatorPeopleNoOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php',
@@ -4060,7 +4062,6 @@
40604062
'PhabricatorPeopleProfileCommitsController' => 'applications/people/controller/PhabricatorPeopleProfileCommitsController.php',
40614063
'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php',
40624064
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php',
4063-
'PhabricatorPeopleProfileImageWorkflow' => 'applications/people/management/PhabricatorPeopleProfileImageWorkflow.php',
40644065
'PhabricatorPeopleProfileManageController' => 'applications/people/controller/PhabricatorPeopleProfileManageController.php',
40654066
'PhabricatorPeopleProfileMenuEngine' => 'applications/people/engine/PhabricatorPeopleProfileMenuEngine.php',
40664067
'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php',
@@ -10332,6 +10333,8 @@
1033210333
'PhabricatorPeopleMailEngine' => 'Phobject',
1033310334
'PhabricatorPeopleMailEngineException' => 'Exception',
1033410335
'PhabricatorPeopleManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
10336+
'PhabricatorPeopleManagementEmpowerWorkflow' => 'PhabricatorPeopleManagementWorkflow',
10337+
'PhabricatorPeopleManagementEnableWorkflow' => 'PhabricatorPeopleManagementWorkflow',
1033510338
'PhabricatorPeopleManagementWorkflow' => 'PhabricatorManagementWorkflow',
1033610339
'PhabricatorPeopleNewController' => 'PhabricatorPeopleController',
1033710340
'PhabricatorPeopleNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
@@ -10341,7 +10344,6 @@
1034110344
'PhabricatorPeopleProfileCommitsController' => 'PhabricatorPeopleProfileController',
1034210345
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
1034310346
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleProfileController',
10344-
'PhabricatorPeopleProfileImageWorkflow' => 'PhabricatorPeopleManagementWorkflow',
1034510347
'PhabricatorPeopleProfileManageController' => 'PhabricatorPeopleProfileController',
1034610348
'PhabricatorPeopleProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
1034710349
'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleProfileController',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class PhabricatorPeopleManagementEmpowerWorkflow
4+
extends PhabricatorPeopleManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$arguments = array_merge(
8+
$this->getUserSelectionArguments(),
9+
array());
10+
11+
$this
12+
->setName('empower')
13+
->setExamples('**empower** --user __username__')
14+
->setSynopsis(pht('Turn a user account into an administrator account.'))
15+
->setArguments($arguments);
16+
}
17+
18+
public function execute(PhutilArgumentParser $args) {
19+
$user = $this->selectUser($args);
20+
$display_name = $user->getUsername();
21+
22+
if ($user->getIsAdmin()) {
23+
throw new PhutilArgumentUsageException(
24+
pht(
25+
'User account "%s" is already an administrator. You can only '.
26+
'empower accounts that are not yet administrators.',
27+
$display_name));
28+
}
29+
30+
$xactions = array();
31+
$xactions[] = $user->getApplicationTransactionTemplate()
32+
->setTransactionType(PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE)
33+
->setNewValue(true);
34+
35+
$this->applyTransactions($user, $xactions);
36+
37+
$this->logOkay(
38+
pht('DONE'),
39+
pht('Empowered user account "%s".', $display_name));
40+
41+
return 0;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class PhabricatorPeopleManagementEnableWorkflow
4+
extends PhabricatorPeopleManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$arguments = array_merge(
8+
$this->getUserSelectionArguments(),
9+
array());
10+
11+
$this
12+
->setName('enable')
13+
->setExamples('**enable** --user __username__')
14+
->setSynopsis(pht('Enable a disabled user account.'))
15+
->setArguments($arguments);
16+
}
17+
18+
public function execute(PhutilArgumentParser $args) {
19+
$user = $this->selectUser($args);
20+
$display_name = $user->getUsername();
21+
22+
if (!$user->getIsDisabled()) {
23+
throw new PhutilArgumentUsageException(
24+
pht(
25+
'User account "%s" is not disabled. You can only enable accounts '.
26+
'that are disabled.',
27+
$display_name));
28+
}
29+
30+
$xactions = array();
31+
$xactions[] = $user->getApplicationTransactionTemplate()
32+
->setTransactionType(PhabricatorUserDisableTransaction::TRANSACTIONTYPE)
33+
->setNewValue(false);
34+
35+
$this->applyTransactions($user, $xactions);
36+
37+
$this->logOkay(
38+
pht('DONE'),
39+
pht('Enabled user account "%s".', $display_name));
40+
41+
return 0;
42+
}
43+
44+
}

‎src/applications/people/management/PhabricatorPeopleManagementWorkflow.php

+42-32
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,55 @@
33
abstract class PhabricatorPeopleManagementWorkflow
44
extends PhabricatorManagementWorkflow {
55

6-
protected function buildIterator(PhutilArgumentParser $args) {
7-
$usernames = $args->getArg('users');
8-
9-
if ($args->getArg('all')) {
10-
if ($usernames) {
11-
throw new PhutilArgumentUsageException(
12-
pht(
13-
'Specify either a list of users or `%s`, but not both.',
14-
'--all'));
15-
}
16-
return new LiskMigrationIterator(new PhabricatorUser());
6+
final protected function getUserSelectionArguments() {
7+
return array(
8+
array(
9+
'name' => 'user',
10+
'param' => 'username',
11+
'help' => pht('User account to act on.'),
12+
),
13+
);
14+
}
15+
16+
final protected function selectUser(PhutilArgumentParser $argv) {
17+
$username = $argv->getArg('user');
18+
19+
if (!strlen($username)) {
20+
throw new PhutilArgumentUsageException(
21+
pht(
22+
'Select a user account to act on with "--user <username>".'));
1723
}
1824

19-
if ($usernames) {
20-
return $this->loadUsersWithUsernames($usernames);
25+
$user = id(new PhabricatorPeopleQuery())
26+
->setViewer($this->getViewer())
27+
->withUsernames(array($username))
28+
->executeOne();
29+
if (!$user) {
30+
throw new PhutilArgumentUsageException(
31+
pht(
32+
'No user with username "%s" exists.',
33+
$username));
2134
}
2235

23-
return null;
36+
return $user;
2437
}
2538

26-
protected function loadUsersWithUsernames(array $usernames) {
27-
$users = array();
28-
foreach($usernames as $username) {
29-
$query = id(new PhabricatorPeopleQuery())
30-
->setViewer($this->getViewer())
31-
->withUsernames(array($username))
32-
->executeOne();
33-
34-
if (!$query) {
35-
throw new PhutilArgumentUsageException(
36-
pht(
37-
'"%s" is not a valid username.',
38-
$username));
39-
}
40-
$users[] = $query;
41-
}
39+
final protected function applyTransactions(
40+
PhabricatorUser $user,
41+
array $xactions) {
42+
assert_instances_of($xactions, 'PhabricatorUserTransaction');
4243

43-
return $users;
44-
}
44+
$viewer = $this->getViewer();
45+
$application = id(new PhabricatorPeopleApplication())->getPHID();
46+
$content_source = $this->newContentSource();
47+
48+
$editor = $user->getApplicationTransactionEditor()
49+
->setActor($viewer)
50+
->setActingAsPHID($application)
51+
->setContentSource($content_source)
52+
->setContinueOnMissingFields(true);
4553

54+
return $editor->applyTransactions($user, $xactions);
55+
}
4656

4757
}

‎src/applications/people/management/PhabricatorPeopleProfileImageWorkflow.php

-85
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.