[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorPolicyManagementUnlockWorkflow 4 extends PhabricatorPolicyManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('unlock') 9 ->setSynopsis( 10 'Unlock an object by setting its policies to allow anyone to view '. 11 'and edit it.') 12 ->setExamples( 13 '**unlock** D123') 14 ->setArguments( 15 array( 16 array( 17 'name' => 'objects', 18 'wildcard' => true, 19 ), 20 )); 21 } 22 23 public function execute(PhutilArgumentParser $args) { 24 $console = PhutilConsole::getConsole(); 25 $viewer = $this->getViewer(); 26 27 $obj_names = $args->getArg('objects'); 28 if (!$obj_names) { 29 throw new PhutilArgumentUsageException( 30 pht( 31 'Specify the name of an object to unlock.')); 32 } else if (count($obj_names) > 1) { 33 throw new PhutilArgumentUsageException( 34 pht( 35 'Specify the name of exactly one object to unlock.')); 36 } 37 38 $object = id(new PhabricatorObjectQuery()) 39 ->setViewer($viewer) 40 ->withNames($obj_names) 41 ->executeOne(); 42 43 if (!$object) { 44 $name = head($obj_names); 45 throw new PhutilArgumentUsageException( 46 pht( 47 "No such object '%s'!", 48 $name)); 49 } 50 51 $handle = id(new PhabricatorHandleQuery()) 52 ->setViewer($viewer) 53 ->withPHIDs(array($object->getPHID())) 54 ->executeOne(); 55 56 if ($object instanceof PhabricatorApplication) { 57 $application = $object; 58 59 $console->writeOut( 60 "%s\n", 61 pht('Unlocking Application: %s', $handle->getFullName())); 62 63 // For applications, we can't unlock them in a normal way and don't want 64 // to unlock every capability, just view and edit. 65 $capabilities = array( 66 PhabricatorPolicyCapability::CAN_VIEW, 67 PhabricatorPolicyCapability::CAN_EDIT, 68 ); 69 70 $key = 'phabricator.application-settings'; 71 $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); 72 $value = $config_entry->getValue(); 73 74 foreach ($capabilities as $capability) { 75 if ($application->isCapabilityEditable($capability)) { 76 unset($value[$application->getPHID()]['policy'][$capability]); 77 } 78 } 79 80 $config_entry->setValue($value); 81 $config_entry->save(); 82 83 $console->writeOut("%s\n", pht('Saved application.')); 84 85 return 0; 86 } 87 88 $console->writeOut("%s\n", pht('Unlocking: %s', $handle->getFullName())); 89 90 $updated = false; 91 foreach ($object->getCapabilities() as $capability) { 92 switch ($capability) { 93 case PhabricatorPolicyCapability::CAN_VIEW: 94 try { 95 $object->setViewPolicy(PhabricatorPolicies::POLICY_USER); 96 $console->writeOut("%s\n", pht('Unlocked view policy.')); 97 $updated = true; 98 } catch (Exception $ex) { 99 $console->writeOut("%s\n", pht('View policy is not mutable.')); 100 } 101 break; 102 case PhabricatorPolicyCapability::CAN_EDIT: 103 try { 104 $object->setEditPolicy(PhabricatorPolicies::POLICY_USER); 105 $console->writeOut("%s\n", pht('Unlocked edit policy.')); 106 $updated = true; 107 } catch (Exception $ex) { 108 $console->writeOut("%s\n", pht('Edit policy is not mutable.')); 109 } 110 break; 111 case PhabricatorPolicyCapability::CAN_JOIN: 112 try { 113 $object->setJoinPolicy(PhabricatorPolicies::POLICY_USER); 114 $console->writeOut("%s\n", pht('Unlocked join policy.')); 115 $updated = true; 116 } catch (Exception $ex) { 117 $console->writeOut("%s\n", pht('Join policy is not mutable.')); 118 } 119 break; 120 } 121 } 122 123 if ($updated) { 124 $object->save(); 125 $console->writeOut("%s\n", pht('Saved object.')); 126 } else { 127 $console->writeOut( 128 "%s\n", 129 pht( 130 'Object has no mutable policies. Try unlocking parent/container '. 131 'object instead. For example, to gain access to a commit, unlock '. 132 'the repository it belongs to.')); 133 } 134 } 135 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |