@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 very simple `bin/policy` script for CLI policy administration

Summary:
Ref T603. I want to provide at least a basic CLI tool for fixing policy problems, since there are various ways users can lock themselves out of objects right now. Although I imagine we'll solve most of them in the application eventually, having a workaround in the meantime will probably make support a lot easier.

This implements `bin/policy show <object>`, which shows an object's policy settings. In a future diff, I'll implement something like `bin/policy set --capability view --policy users <object>`, although maybe just `bin/policy unlock <object>` (which sets view and edit to "all users") would be better for now. Whichever way we go, it will be some blanket answer to people showing up in IRC having locked themselves out of objects which unblocks them while we work on preventing the issue in the first place.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+118
+1
bin/policy
··· 1 + ../scripts/setup/manage_policy.php
+22
scripts/setup/manage_policy.php
··· 1 + #!/usr/bin/env php 2 + <?php 3 + 4 + $root = dirname(dirname(dirname(__FILE__))); 5 + require_once $root.'/scripts/__init_script__.php'; 6 + 7 + $args = new PhutilArgumentParser($argv); 8 + $args->setTagline('manage policies'); 9 + $args->setSynopsis(<<<EOSYNOPSIS 10 + **policy** __command__ [__options__] 11 + Administrative tool for reviewing and editing policies. 12 + 13 + EOSYNOPSIS 14 + ); 15 + $args->parseStandardArguments(); 16 + 17 + $workflows = array( 18 + new PhabricatorPolicyManagementShowWorkflow(), 19 + new PhutilHelpArgumentWorkflow(), 20 + ); 21 + 22 + $args->parseWorkflows($workflows);
+4
src/__phutil_library_map__.php
··· 1467 1467 'PhabricatorPolicyExplainController' => 'applications/policy/controller/PhabricatorPolicyExplainController.php', 1468 1468 'PhabricatorPolicyFilter' => 'applications/policy/filter/PhabricatorPolicyFilter.php', 1469 1469 'PhabricatorPolicyInterface' => 'applications/policy/interface/PhabricatorPolicyInterface.php', 1470 + 'PhabricatorPolicyManagementShowWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementShowWorkflow.php', 1471 + 'PhabricatorPolicyManagementWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementWorkflow.php', 1470 1472 'PhabricatorPolicyQuery' => 'applications/policy/query/PhabricatorPolicyQuery.php', 1471 1473 'PhabricatorPolicyTestCase' => 'applications/policy/__tests__/PhabricatorPolicyTestCase.php', 1472 1474 'PhabricatorPolicyTestObject' => 'applications/policy/__tests__/PhabricatorPolicyTestObject.php', ··· 3622 3624 'PhabricatorPolicyDataTestCase' => 'PhabricatorTestCase', 3623 3625 'PhabricatorPolicyException' => 'Exception', 3624 3626 'PhabricatorPolicyExplainController' => 'PhabricatorPolicyController', 3627 + 'PhabricatorPolicyManagementShowWorkflow' => 'PhabricatorPolicyManagementWorkflow', 3628 + 'PhabricatorPolicyManagementWorkflow' => 'PhutilArgumentWorkflow', 3625 3629 'PhabricatorPolicyQuery' => 'PhabricatorQuery', 3626 3630 'PhabricatorPolicyTestCase' => 'PhabricatorTestCase', 3627 3631 'PhabricatorPolicyTestObject' => 'PhabricatorPolicyInterface',
+81
src/applications/policy/management/PhabricatorPolicyManagementShowWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorPolicyManagementShowWorkflow 4 + extends PhabricatorPolicyManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('show') 9 + ->setSynopsis('Show policy information about an object.') 10 + ->setExamples( 11 + "**show** D123") 12 + ->setArguments( 13 + array( 14 + array( 15 + 'name' => 'objects', 16 + 'wildcard' => true, 17 + ), 18 + )); 19 + } 20 + 21 + public function execute(PhutilArgumentParser $args) { 22 + $console = PhutilConsole::getConsole(); 23 + $viewer = PhabricatorUser::getOmnipotentUser(); 24 + 25 + $obj_names = $args->getArg('objects'); 26 + if (!$obj_names) { 27 + throw new PhutilArgumentUsageException( 28 + pht( 29 + "Specify the name of an object to show policy information for.")); 30 + } else if (count($obj_names) > 1) { 31 + throw new PhutilArgumentUsageException( 32 + pht( 33 + "Specify the name of exactly one object to show policy information ". 34 + "for.")); 35 + } 36 + 37 + $object = id(new PhabricatorObjectQuery()) 38 + ->setViewer($viewer) 39 + ->withNames($obj_names) 40 + ->executeOne(); 41 + 42 + if (!$object) { 43 + $name = head($obj_names); 44 + throw new PhutilArgumentUsageException( 45 + pht( 46 + "No such object '%s'!", 47 + $name)); 48 + } 49 + 50 + $handle = id(new PhabricatorHandleQuery()) 51 + ->setViewer($viewer) 52 + ->withPHIDs(array($object->getPHID())) 53 + ->executeOne(); 54 + 55 + $policies = PhabricatorPolicyQuery::loadPolicies( 56 + $viewer, 57 + $object); 58 + 59 + $console->writeOut("__%s__\n\n", pht('OBJECT')); 60 + $console->writeOut(" %s\n", $handle->getFullName()); 61 + $console->writeOut("\n"); 62 + 63 + $console->writeOut("__%s__\n\n", pht('CAPABILITIES')); 64 + foreach ($policies as $capability => $policy) { 65 + $console->writeOut(" **%s**\n", $capability); 66 + $console->writeOut(" %s\n", $policy->renderDescription()); 67 + $console->writeOut(" %s\n", $policy->getExplanation($capability)); 68 + $console->writeOut("\n"); 69 + 70 + $more = (array)$object->describeAutomaticCapability($capability); 71 + if ($more) { 72 + foreach ($more as $line) { 73 + $console->writeOut(" %s\n", $line); 74 + } 75 + $console->writeOut("\n"); 76 + } 77 + } 78 + 79 + } 80 + 81 + }
+10
src/applications/policy/management/PhabricatorPolicyManagementWorkflow.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorPolicyManagementWorkflow 4 + extends PhutilArgumentWorkflow { 5 + 6 + final public function isExecutable() { 7 + return true; 8 + } 9 + 10 + }