3 final class PhabricatorPolicyManagementUnlockWorkflow
4 extends PhabricatorPolicyManagementWorkflow
{
6 protected function didConstruct() {
11 'Unlock one or more objects by changing their view policies, edit '.
12 'policies, or owners.'))
15 'Identify each __object__ by passing an object name '.
16 '(like "T123") or a PHID (like "PHID-ABCD-1234...").'.
18 'Not every type of object has an editable view policy, edit '.
19 'policy, or owner, so not all modes will work with all objects. '))
20 ->setExamples('**unlock** --view __user__ __object__ ...')
25 'param' => 'username',
27 'Change the view policy of an object so that the specified '.
32 'param' => 'username',
34 'Change the edit policy of an object so that the specified '.
39 'param' => 'username',
41 'Change the owner of an object to the specified user.'),
50 public function execute(PhutilArgumentParser
$args) {
51 $viewer = $this->getViewer();
53 $object_names = $args->getArg('objects');
55 throw new PhutilArgumentUsageException(
56 pht('Specify the name of an object to unlock.'));
57 } else if (count($object_names) > 1) {
58 throw new PhutilArgumentUsageException(
59 pht('Specify the name of exactly one object to unlock.'));
62 $object_name = head($object_names);
64 $object = id(new PhabricatorObjectQuery())
66 ->withNames(array($object_name))
69 throw new PhutilArgumentUsageException(
71 'Unable to find any object with the specified name ("%s").',
75 $view_user = $this->loadUser($args->getArg('view'));
76 $edit_user = $this->loadUser($args->getArg('edit'));
77 $owner_user = $this->loadUser($args->getArg('owner'));
79 if (!$view_user && !$edit_user && !$owner_user) {
80 throw new PhutilArgumentUsageException(
82 'Choose which capabilities to unlock with "--view", "--edit", '.
86 $handle = id(new PhabricatorHandleQuery())
88 ->withPHIDs(array($object->getPHID()))
92 "<bg:blue>** %s **</bg> %s\n",
94 pht('Unlocking: %s', $handle->getFullName()));
96 $engine = PhabricatorUnlockEngine
::newUnlockEngineForObject($object);
100 $xactions[] = $engine->newUnlockViewTransactions($object, $view_user);
103 $xactions[] = $engine->newUnlockEditTransactions($object, $edit_user);
106 $xactions[] = $engine->newUnlockOwnerTransactions($object, $owner_user);
108 $xactions = array_mergev($xactions);
110 $policy_application = new PhabricatorPolicyApplication();
111 $content_source = $this->newContentSource();
113 $editor = $object->getApplicationTransactionEditor()
115 ->setActingAsPHID($policy_application->getPHID())
116 ->setContinueOnMissingFields(true)
117 ->setContinueOnNoEffect(true)
118 ->setContentSource($content_source);
120 $editor->applyTransactions($object, $xactions);
123 "<bg:green>** %s **</bg> %s\n",
125 pht('Modified object policies.'));
127 $uri = $handle->getURI();
130 "\n **%s**: __%s__\n\n",
132 PhabricatorEnv
::getURI($uri));
138 private function loadUser($username) {
139 $viewer = $this->getViewer();
141 if ($username === null) {
145 $user = id(new PhabricatorPeopleQuery())
147 ->withUsernames(array($username))
151 throw new PhutilArgumentUsageException(
153 'No user with username "%s" exists.',