@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 "almanac.service.edit" to create services

Summary:
Depends on D19317. Ref T13120. Ref T12414. See PHI145. See PHI473.

This adds a Conduit-only "type" transaction for Almanac services. This is very similar to the approach in D18849 for Drydock blueprints.

Test Plan:
- Tried to create an empty service via "almanac.service.edit", was told to pick a type.
- Tried to pick a bad type, was told to pick a good type.
- Created a new Almanac service via "almanac.service.edit".
- Tried to edit the service to change the type, wasn't allowed to.
- Created and edited via the web UI, nothing changed from before.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13120, T12414

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

+100 -2
+2
src/__phutil_library_map__.php
··· 126 126 'AlmanacServiceType' => 'applications/almanac/servicetype/AlmanacServiceType.php', 127 127 'AlmanacServiceTypeDatasource' => 'applications/almanac/typeahead/AlmanacServiceTypeDatasource.php', 128 128 'AlmanacServiceTypeTestCase' => 'applications/almanac/servicetype/__tests__/AlmanacServiceTypeTestCase.php', 129 + 'AlmanacServiceTypeTransaction' => 'applications/almanac/xaction/AlmanacServiceTypeTransaction.php', 129 130 'AlmanacServiceViewController' => 'applications/almanac/controller/AlmanacServiceViewController.php', 130 131 'AlmanacTransaction' => 'applications/almanac/storage/AlmanacTransaction.php', 131 132 'AlmanacTransactionType' => 'applications/almanac/xaction/AlmanacTransactionType.php', ··· 5331 5332 'AlmanacServiceType' => 'Phobject', 5332 5333 'AlmanacServiceTypeDatasource' => 'PhabricatorTypeaheadDatasource', 5333 5334 'AlmanacServiceTypeTestCase' => 'PhabricatorTestCase', 5335 + 'AlmanacServiceTypeTransaction' => 'AlmanacServiceTransactionType', 5334 5336 'AlmanacServiceViewController' => 'AlmanacServiceController', 5335 5337 'AlmanacTransaction' => 'PhabricatorApplicationTransaction', 5336 5338 'AlmanacTransactionType' => 'PhabricatorModularTransactionType',
+41
src/applications/almanac/editor/AlmanacServiceEditEngine.php
··· 41 41 return AlmanacService::initializeNewService($service_type); 42 42 } 43 43 44 + protected function newEditableObjectFromConduit(array $raw_xactions) { 45 + $type = null; 46 + foreach ($raw_xactions as $raw_xaction) { 47 + if ($raw_xaction['type'] !== 'type') { 48 + continue; 49 + } 50 + 51 + $type = $raw_xaction['value']; 52 + } 53 + 54 + if ($type === null) { 55 + throw new Exception( 56 + pht( 57 + 'When creating a new Almanac service via the Conduit API, you '. 58 + 'must provide a "type" transaction to select a type.')); 59 + } 60 + 61 + $map = AlmanacServiceType::getAllServiceTypes(); 62 + if (!isset($map[$type])) { 63 + throw new Exception( 64 + pht( 65 + 'Service type "%s" is unrecognized. Valid types are: %s.', 66 + $type, 67 + implode(', ', array_keys($map)))); 68 + } 69 + 70 + $this->setServiceType($type); 71 + 72 + return $this->newEditableObject(); 73 + } 74 + 44 75 protected function newEditableObjectForDocumentation() { 45 76 $service_type = new AlmanacCustomServiceType(); 46 77 $this->setServiceType($service_type->getServiceTypeConstant()); ··· 101 132 ->setTransactionType(AlmanacServiceNameTransaction::TRANSACTIONTYPE) 102 133 ->setIsRequired(true) 103 134 ->setValue($object->getName()), 135 + id(new PhabricatorTextEditField()) 136 + ->setKey('type') 137 + ->setLabel(pht('Type')) 138 + ->setIsConduitOnly(true) 139 + ->setTransactionType( 140 + AlmanacServiceTypeTransaction::TRANSACTIONTYPE) 141 + ->setDescription(pht('When creating a service, set the type.')) 142 + ->setConduitDescription(pht('Set the service type.')) 143 + ->setConduitTypeDescription(pht('Service type.')) 144 + ->setValue($object->getServiceType()), 104 145 ); 105 146 } 106 147
+2 -2
src/applications/almanac/xaction/AlmanacServiceNameTransaction.php
··· 16 16 public function getTitle() { 17 17 return pht( 18 18 '%s renamed this service from %s to %s.', 19 - $this->renderAuthorLink(), 19 + $this->renderAuthor(), 20 20 $this->renderOldValue(), 21 21 $this->renderNewValue()); 22 22 } ··· 24 24 public function getTitleForFeed() { 25 25 return pht( 26 26 '%s renamed %s from %s to %s.', 27 - $this->renderAuthorLink(), 27 + $this->renderAuthor(), 28 28 $this->renderObject(), 29 29 $this->renderOldValue(), 30 30 $this->renderNewValue());
+55
src/applications/almanac/xaction/AlmanacServiceTypeTransaction.php
··· 1 + <?php 2 + 3 + final class AlmanacServiceTypeTransaction 4 + extends AlmanacServiceTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'almanac:service:type'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getServiceType(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setServiceType($value); 14 + } 15 + 16 + public function getTitle() { 17 + // This transaction can only be applied during object creation via 18 + // Conduit and never generates a timeline event. 19 + return null; 20 + } 21 + 22 + public function validateTransactions($object, array $xactions) { 23 + $errors = array(); 24 + 25 + if ($this->isEmptyTextTransaction($object->getServiceType(), $xactions)) { 26 + $errors[] = $this->newRequiredError( 27 + pht('You must select a service type when creating a service.')); 28 + } 29 + 30 + $map = AlmanacServiceType::getAllServiceTypes(); 31 + 32 + foreach ($xactions as $xaction) { 33 + if (!$this->isNewObject()) { 34 + $errors[] = $this->newInvalidError( 35 + pht( 36 + 'The type of a service can not be changed once it has '. 37 + 'been created.'), 38 + $xaction); 39 + continue; 40 + } 41 + 42 + $new = $xaction->getNewValue(); 43 + if (!isset($map[$new])) { 44 + $errors[] = $this->newInvalidError( 45 + pht( 46 + 'Service type "%s" is not valid. Valid types are: %s.', 47 + $new, 48 + implode(', ', array_keys($map)))); 49 + continue; 50 + } 51 + } 52 + 53 + return $errors; 54 + } 55 + }