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

Allow "drydock.blueprint.edit" to create blueprints

Summary:
Depends on D18848. Ref PHI243. This puts a bit of logic up front to figure out the blueprint type before we actually start editing it.

This implementation is a little messy but it keeps the API clean. Eventually, the implementation could probably go in the TransactionTypes so more code is shared, but I'd like to wait for a couple more of these first.

This capability probably isn't too useful, but just pays down a bit of technical debt from the caveat introduced in D18822.

Test Plan:
- Created a new blueprint with the API.
- Tried to create a blueprint without a "type" (got a helpful error).
- Created and edited blueprints via the web UI.
- Tried to change the "type" of an existing blueprint (got a helpful error).

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

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

+104 -3
+2
src/__phutil_library_map__.php
··· 1025 1025 'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php', 1026 1026 'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php', 1027 1027 'DrydockBlueprintTransactionType' => 'applications/drydock/xaction/DrydockBlueprintTransactionType.php', 1028 + 'DrydockBlueprintTypeTransaction' => 'applications/drydock/xaction/DrydockBlueprintTypeTransaction.php', 1028 1029 'DrydockBlueprintViewController' => 'applications/drydock/controller/DrydockBlueprintViewController.php', 1029 1030 'DrydockCommand' => 'applications/drydock/storage/DrydockCommand.php', 1030 1031 'DrydockCommandError' => 'applications/drydock/exception/DrydockCommandError.php', ··· 6122 6123 'DrydockBlueprintTransaction' => 'PhabricatorModularTransaction', 6123 6124 'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6124 6125 'DrydockBlueprintTransactionType' => 'PhabricatorModularTransactionType', 6126 + 'DrydockBlueprintTypeTransaction' => 'DrydockBlueprintTransactionType', 6125 6127 'DrydockBlueprintViewController' => 'DrydockBlueprintController', 6126 6128 'DrydockCommand' => array( 6127 6129 'DrydockDAO',
+1 -2
src/applications/drydock/conduit/DrydockBlueprintEditConduitAPIMethod.php
··· 13 13 14 14 public function getMethodSummary() { 15 15 return pht( 16 - 'WARNING: Apply transactions to edit an existing blueprint. This method '. 17 - 'can not create new blueprints.'); 16 + 'Apply transactions to create or edit a blueprint.'); 18 17 } 19 18 20 19 }
+44 -1
src/applications/drydock/editor/DrydockBlueprintEditEngine.php
··· 51 51 return $blueprint; 52 52 } 53 53 54 + protected function newEditableObjectFromConduit(array $raw_xactions) { 55 + $type = null; 56 + foreach ($raw_xactions as $raw_xaction) { 57 + if ($raw_xaction['type'] !== 'type') { 58 + continue; 59 + } 60 + 61 + $type = $raw_xaction['value']; 62 + } 63 + 64 + if ($type === null) { 65 + throw new Exception( 66 + pht( 67 + 'When creating a new Drydock blueprint via the Conduit API, you '. 68 + 'must provide a "type" transaction to select a type.')); 69 + } 70 + 71 + $map = DrydockBlueprintImplementation::getAllBlueprintImplementations(); 72 + if (!isset($map[$type])) { 73 + throw new Exception( 74 + pht( 75 + 'Blueprint type "%s" is unrecognized. Valid types are: %s.', 76 + $type, 77 + implode(', ', array_keys($map)))); 78 + } 79 + 80 + $impl = clone $map[$type]; 81 + $this->setBlueprintImplementation($impl); 82 + 83 + return $this->newEditableObject(); 84 + } 85 + 54 86 protected function newEditableObjectForDocumentation() { 55 87 // In order to generate the proper list of fields/transactions for a 56 88 // blueprint, a blueprint's type needs to be known upfront, and there's ··· 112 144 $impl = $object->getImplementation(); 113 145 114 146 return array( 147 + // This field appears in the web UI 115 148 id(new PhabricatorStaticEditField()) 116 - ->setKey('type') 149 + ->setKey('displayType') 117 150 ->setLabel(pht('Blueprint Type')) 118 151 ->setDescription(pht('Type of blueprint.')) 119 152 ->setValue($impl->getBlueprintName()), 153 + id(new PhabricatorTextEditField()) 154 + ->setKey('type') 155 + ->setLabel(pht('Type')) 156 + ->setIsConduitOnly(true) 157 + ->setTransactionType( 158 + DrydockBlueprintTypeTransaction::TRANSACTIONTYPE) 159 + ->setDescription(pht('When creating a blueprint, set the type.')) 160 + ->setConduitDescription(pht('Set the blueprint type.')) 161 + ->setConduitTypeDescription(pht('Blueprint type.')) 162 + ->setValue($object->getClassName()), 120 163 id(new PhabricatorTextEditField()) 121 164 ->setKey('name') 122 165 ->setLabel(pht('Name'))
+57
src/applications/drydock/xaction/DrydockBlueprintTypeTransaction.php
··· 1 + <?php 2 + 3 + final class DrydockBlueprintTypeTransaction 4 + extends DrydockBlueprintTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'drydock.blueprint.type'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getClassName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setClassName($value); 14 + } 15 + 16 + public function getTitle() { 17 + // These transactions can only be applied during object creation and never 18 + // generate a timeline event. 19 + return null; 20 + } 21 + 22 + public function validateTransactions($object, array $xactions) { 23 + $errors = array(); 24 + 25 + $name = $object->getClassName(); 26 + if ($this->isEmptyTextTransaction($name, $xactions)) { 27 + $errors[] = $this->newRequiredError( 28 + pht('You must select a blueprint type when creating a blueprint.')); 29 + } 30 + 31 + $map = DrydockBlueprintImplementation::getAllBlueprintImplementations(); 32 + 33 + foreach ($xactions as $xaction) { 34 + if (!$this->isNewObject()) { 35 + $errors[] = $this->newInvalidError( 36 + pht( 37 + 'The type of a blueprint can not be changed once it has '. 38 + 'been created.'), 39 + $xaction); 40 + continue; 41 + } 42 + 43 + $new = $xaction->getNewValue(); 44 + if (!isset($map[$new])) { 45 + $errors[] = $this->newInvalidError( 46 + pht( 47 + 'Blueprint type "%s" is not valid. Valid types are: %s.', 48 + $new, 49 + implode(', ', array_keys($map)))); 50 + continue; 51 + } 52 + } 53 + 54 + return $errors; 55 + } 56 + 57 + }