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

Nuance - conduit method to create items

Summary:
pretty simple. did the bare minimum in the editor, etc. to be able to create an item from the conduit console.

I put the work in the editor for initializing new values, rather than some initializeNewItem method, mainly because Items don't have policy directly but instead policy will be defined by the queue(s) the item is in. The editor is definitely going to host this work, so it felt like it might be better to do it this way in time...? anyway, easy to make an initializeNew method instead if you want to have that paradigm going all the time.

Test Plan: made an item from teh conduit console - success. verified errors for missing data as well

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

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

+187 -1
+4
src/__phutil_library_map__.php
··· 197 197 'ConduitAPI_maniphest_info_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_info_Method.php', 198 198 'ConduitAPI_maniphest_query_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_query_Method.php', 199 199 'ConduitAPI_maniphest_update_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_update_Method.php', 200 + 'ConduitAPI_nuance_Method' => 'applications/nuance/conduit/ConduitAPI_nuance_Method.php', 201 + 'ConduitAPI_nuance_createitem_Method' => 'applications/nuance/conduit/ConduitAPI_nuance_createitem_Method.php', 200 202 'ConduitAPI_owners_Method' => 'applications/owners/conduit/ConduitAPI_owners_Method.php', 201 203 'ConduitAPI_owners_query_Method' => 'applications/owners/conduit/ConduitAPI_owners_query_Method.php', 202 204 'ConduitAPI_paste_Method' => 'applications/paste/conduit/ConduitAPI_paste_Method.php', ··· 2612 2614 'ConduitAPI_maniphest_info_Method' => 'ConduitAPI_maniphest_Method', 2613 2615 'ConduitAPI_maniphest_query_Method' => 'ConduitAPI_maniphest_Method', 2614 2616 'ConduitAPI_maniphest_update_Method' => 'ConduitAPI_maniphest_Method', 2617 + 'ConduitAPI_nuance_Method' => 'ConduitAPIMethod', 2618 + 'ConduitAPI_nuance_createitem_Method' => 'ConduitAPI_nuance_Method', 2615 2619 'ConduitAPI_owners_Method' => 'ConduitAPIMethod', 2616 2620 'ConduitAPI_owners_query_Method' => 'ConduitAPI_owners_Method', 2617 2621 'ConduitAPI_paste_Method' => 'ConduitAPIMethod',
+17
src/applications/nuance/conduit/ConduitAPI_nuance_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + abstract class ConduitAPI_nuance_Method extends ConduitAPIMethod { 7 + 8 + public function getApplication() { 9 + return PhabricatorApplication::getByClass( 10 + 'PhabricatorApplicationNuance'); 11 + } 12 + 13 + public function getMethodStatus() { 14 + return self::METHOD_STATUS_UNSTABLE; 15 + } 16 + 17 + }
+73
src/applications/nuance/conduit/ConduitAPI_nuance_createitem_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_nuance_createitem_Method 7 + extends ConduitAPI_nuance_Method { 8 + 9 + public function getMethodDescription() { 10 + return pht('Create a new item.'); 11 + } 12 + 13 + public function defineParamTypes() { 14 + return array( 15 + 'requestorPHID' => 'required string', 16 + 'sourcePHID' => 'required string', 17 + 'ownerPHID' => 'optional string', 18 + ); 19 + } 20 + 21 + public function defineReturnType() { 22 + return 'nonempty dict'; 23 + } 24 + 25 + public function defineErrorTypes() { 26 + return array( 27 + 'ERR-NO-REQUESTOR-PHID' => pht('Items must have a requestor.'), 28 + 'ERR-NO-SOURCE-PHID' => pht('Items must have a source.'), 29 + ); 30 + } 31 + 32 + protected function execute(ConduitAPIRequest $request) { 33 + $source_phid = $request->getValue('sourcePHID'); 34 + $owner_phid = $request->getValue('ownerPHID'); 35 + $requestor_phid = $request->getValue('requestorPHID'); 36 + 37 + $user = $request->getUser(); 38 + 39 + $item = NuanceItem::initializeNewItem($user); 40 + $xactions = array(); 41 + 42 + if ($source_phid) { 43 + $xactions[] = id(new NuanceItemTransaction()) 44 + ->setTransactionType(NuanceItemTransaction::TYPE_SOURCE) 45 + ->setNewValue($source_phid); 46 + } else { 47 + throw new ConduitException('ERR-NO-SOURCE-PHID'); 48 + } 49 + 50 + if ($owner_phid) { 51 + $xactions[] = id(new NuanceItemTransaction()) 52 + ->setTransactionType(NuanceItemTransaction::TYPE_OWNER) 53 + ->setNewValue($owner_phid); 54 + } 55 + 56 + if ($requestor_phid) { 57 + $xactions[] = id(new NuanceItemTransaction()) 58 + ->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR) 59 + ->setNewValue($requestor_phid); 60 + } else { 61 + throw new ConduitException('ERR-NO-REQUESTOR-PHID'); 62 + } 63 + 64 + $source = PhabricatorContentSource::newFromConduitRequest($request); 65 + $editor = id(new NuanceItemEditor()) 66 + ->setActor($user) 67 + ->setContentSource($source) 68 + ->applyTransactions($item, $xactions); 69 + 70 + return $item->toDictionary(); 71 + } 72 + 73 + }
+65
src/applications/nuance/editor/NuanceItemEditor.php
··· 6 6 public function getTransactionTypes() { 7 7 $types = parent::getTransactionTypes(); 8 8 9 + $types[] = NuanceItemTransaction::TYPE_OWNER; 10 + $types[] = NuanceItemTransaction::TYPE_SOURCE; 11 + $types[] = NuanceItemTransaction::TYPE_REQUESTOR; 12 + 9 13 $types[] = PhabricatorTransactions::TYPE_EDGE; 10 14 $types[] = PhabricatorTransactions::TYPE_COMMENT; 11 15 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 12 16 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 13 17 14 18 return $types; 19 + } 20 + 21 + protected function getCustomTransactionOldValue( 22 + PhabricatorLiskDAO $object, 23 + PhabricatorApplicationTransaction $xaction) { 24 + 25 + switch ($xaction->getTransactionType()) { 26 + case NuanceItemTransaction::TYPE_REQUESTOR: 27 + return $object->getRequestorPHID(); 28 + case NuanceItemTransaction::TYPE_SOURCE: 29 + return $object->getSourcePHID(); 30 + case NuanceItemTransaction::TYPE_OWNER: 31 + return $object->getOwnerPHID(); 32 + } 33 + 34 + return parent::getCustomTransactionOldValue($object, $xaction); 35 + } 36 + 37 + protected function getCustomTransactionNewValue( 38 + PhabricatorLiskDAO $object, 39 + PhabricatorApplicationTransaction $xaction) { 40 + 41 + switch ($xaction->getTransactionType()) { 42 + case NuanceItemTransaction::TYPE_REQUESTOR: 43 + case NuanceItemTransaction::TYPE_SOURCE: 44 + case NuanceItemTransaction::TYPE_OWNER: 45 + return $xaction->getNewValue(); 46 + } 47 + 48 + return parent::getCustomTransactionNewValue($object, $xaction); 49 + } 50 + 51 + protected function applyCustomInternalTransaction( 52 + PhabricatorLiskDAO $object, 53 + PhabricatorApplicationTransaction $xaction) { 54 + 55 + switch ($xaction->getTransactionType()) { 56 + case NuanceItemTransaction::TYPE_REQUESTOR: 57 + $object->setRequestorPHID($xaction->getNewValue()); 58 + break; 59 + case NuanceItemTransaction::TYPE_SOURCE: 60 + $object->setSourcePHID($xaction->getNewValue()); 61 + break; 62 + case NuanceItemTransaction::TYPE_OWNER: 63 + $object->setOwnerPHID($xaction->getNewValue()); 64 + break; 65 + } 66 + } 67 + 68 + protected function applyCustomExternalTransaction( 69 + PhabricatorLiskDAO $object, 70 + PhabricatorApplicationTransaction $xaction) { 71 + 72 + switch ($xaction->getTransactionType()) { 73 + case NuanceItemTransaction::TYPE_REQUESTOR: 74 + case NuanceItemTransaction::TYPE_SOURCE: 75 + case NuanceItemTransaction::TYPE_OWNER: 76 + return; 77 + } 78 + 79 + return parent::applyCustomExternalTransaction($object, $xaction); 15 80 } 16 81 17 82 }
+24 -1
src/applications/nuance/storage/NuanceItem.php
··· 4 4 extends NuanceDAO 5 5 implements PhabricatorPolicyInterface { 6 6 7 + const STATUS_OPEN = 0; 8 + const STATUS_ASSIGNED = 10; 9 + const STATUS_CLOSED = 20; 10 + 11 + protected $status; 7 12 protected $ownerPHID; 8 13 protected $requestorPHID; 9 14 protected $sourcePHID; ··· 12 17 protected $mailKey; 13 18 protected $dateNuanced; 14 19 20 + public static function initializeNewItem(PhabricatorUser $user) { 21 + return id(new NuanceItem()) 22 + ->setDateNuanced(time()) 23 + ->setStatus(NuanceItem::STATUS_OPEN); 24 + } 15 25 public function getConfiguration() { 16 26 return array( 17 27 self::CONFIG_AUX_PHID => true, ··· 74 84 75 85 public function getPolicy($capability) { 76 86 // TODO - this should be based on the queues the item currently resides in 77 - return PhabricatorPolicies::POLICY_NOONE; 87 + return PhabricatorPolicies::POLICY_USER; 78 88 } 79 89 80 90 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { ··· 92 102 return null; 93 103 } 94 104 105 + public function toDictionary() { 106 + return array( 107 + 'id' => $this->getID(), 108 + 'phid' => $this->getPHID(), 109 + 'ownerPHID' => $this->getOwnerPHID(), 110 + 'requestorPHID' => $this->getRequestorPHID(), 111 + 'sourcePHID' => $this->getSourcePHID(), 112 + 'sourceLabel' => $this->getSourceLabel(), 113 + 'dateCreated' => $this->getDateCreated(), 114 + 'dateModified' => $this->getDateModified(), 115 + 'dateNuanced' => $this->getDateNuanced(), 116 + ); 117 + } 95 118 }
+4
src/applications/nuance/storage/NuanceItemTransaction.php
··· 3 3 final class NuanceItemTransaction 4 4 extends NuanceTransaction { 5 5 6 + const TYPE_OWNER = 'item-owner'; 7 + const TYPE_REQUESTOR = 'item-requestor'; 8 + const TYPE_SOURCE = 'item-source'; 9 + 6 10 public function getApplicationTransactionType() { 7 11 return NuancePHIDTypeItem::TYPECONST; 8 12 }