@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.

at recaptime-dev/main 86 lines 2.4 kB view raw
1<?php 2 3final class PhabricatorPolicyManagementShowWorkflow 4 extends PhabricatorPolicyManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('show') 9 ->setSynopsis(pht('Show policy information about an object.')) 10 ->setExamples('**show** D123') 11 ->setArguments( 12 array( 13 array( 14 'name' => 'objects', 15 'wildcard' => true, 16 ), 17 )); 18 } 19 20 public function execute(PhutilArgumentParser $args) { 21 $console = PhutilConsole::getConsole(); 22 $viewer = $this->getViewer(); 23 24 $obj_names = $args->getArg('objects'); 25 if (!$obj_names) { 26 throw new PhutilArgumentUsageException( 27 pht('Specify the name of an object to show policy information for.')); 28 } else if (count($obj_names) > 1) { 29 throw new PhutilArgumentUsageException( 30 pht( 31 'Specify the name of exactly one object to show policy information '. 32 'for.')); 33 } 34 35 $object = id(new PhabricatorObjectQuery()) 36 ->setViewer($viewer) 37 ->withNames($obj_names) 38 ->executeOne(); 39 40 if (!$object) { 41 $name = head($obj_names); 42 throw new PhutilArgumentUsageException( 43 pht( 44 "No such object '%s'!", 45 $name)); 46 } 47 48 $handle = id(new PhabricatorHandleQuery()) 49 ->setViewer($viewer) 50 ->withPHIDs(array($object->getPHID())) 51 ->executeOne(); 52 53 $policies = PhabricatorPolicyQuery::loadPolicies( 54 $viewer, 55 $object); 56 57 $console->writeOut("__%s__\n\n", pht('OBJECT')); 58 $console->writeOut(" %s\n", $handle->getFullName()); 59 $console->writeOut("\n"); 60 61 $console->writeOut("__%s__\n\n", pht('CAPABILITIES')); 62 foreach ($policies as $capability => $policy) { 63 $ref = $policy->newRef($viewer); 64 65 $console->writeOut(" **%s**\n", $capability); 66 $console->writeOut(" %s\n", $ref->getPolicyDisplayName()); 67 $console->writeOut(" %s\n", 68 PhabricatorPolicy::getPolicyExplanation($viewer, $policy->getPHID())); 69 $console->writeOut("\n"); 70 } 71 72 if ($object instanceof PhabricatorPolicyCodexInterface) { 73 $codex = PhabricatorPolicyCodex::newFromObject($object, $viewer); 74 75 $rules = $codex->getPolicySpecialRuleDescriptions(); 76 foreach ($rules as $rule) { 77 echo tsprintf( 78 " - %s\n", 79 $rule->getDescription()); 80 } 81 82 echo "\n"; 83 } 84 } 85 86}