mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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
This commit is contained in:
parent
d63e530608
commit
cba959635e
6 changed files with 187 additions and 1 deletions
|
@ -197,6 +197,8 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_maniphest_info_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_info_Method.php',
|
||||
'ConduitAPI_maniphest_query_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_query_Method.php',
|
||||
'ConduitAPI_maniphest_update_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_update_Method.php',
|
||||
'ConduitAPI_nuance_Method' => 'applications/nuance/conduit/ConduitAPI_nuance_Method.php',
|
||||
'ConduitAPI_nuance_createitem_Method' => 'applications/nuance/conduit/ConduitAPI_nuance_createitem_Method.php',
|
||||
'ConduitAPI_owners_Method' => 'applications/owners/conduit/ConduitAPI_owners_Method.php',
|
||||
'ConduitAPI_owners_query_Method' => 'applications/owners/conduit/ConduitAPI_owners_query_Method.php',
|
||||
'ConduitAPI_paste_Method' => 'applications/paste/conduit/ConduitAPI_paste_Method.php',
|
||||
|
@ -2612,6 +2614,8 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_maniphest_info_Method' => 'ConduitAPI_maniphest_Method',
|
||||
'ConduitAPI_maniphest_query_Method' => 'ConduitAPI_maniphest_Method',
|
||||
'ConduitAPI_maniphest_update_Method' => 'ConduitAPI_maniphest_Method',
|
||||
'ConduitAPI_nuance_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_nuance_createitem_Method' => 'ConduitAPI_nuance_Method',
|
||||
'ConduitAPI_owners_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_owners_query_Method' => 'ConduitAPI_owners_Method',
|
||||
'ConduitAPI_paste_Method' => 'ConduitAPIMethod',
|
||||
|
|
17
src/applications/nuance/conduit/ConduitAPI_nuance_Method.php
Normal file
17
src/applications/nuance/conduit/ConduitAPI_nuance_Method.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
abstract class ConduitAPI_nuance_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getApplication() {
|
||||
return PhabricatorApplication::getByClass(
|
||||
'PhabricatorApplicationNuance');
|
||||
}
|
||||
|
||||
public function getMethodStatus() {
|
||||
return self::METHOD_STATUS_UNSTABLE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_nuance_createitem_Method
|
||||
extends ConduitAPI_nuance_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return pht('Create a new item.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'requestorPHID' => 'required string',
|
||||
'sourcePHID' => 'required string',
|
||||
'ownerPHID' => 'optional string',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
'ERR-NO-REQUESTOR-PHID' => pht('Items must have a requestor.'),
|
||||
'ERR-NO-SOURCE-PHID' => pht('Items must have a source.'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$source_phid = $request->getValue('sourcePHID');
|
||||
$owner_phid = $request->getValue('ownerPHID');
|
||||
$requestor_phid = $request->getValue('requestorPHID');
|
||||
|
||||
$user = $request->getUser();
|
||||
|
||||
$item = NuanceItem::initializeNewItem($user);
|
||||
$xactions = array();
|
||||
|
||||
if ($source_phid) {
|
||||
$xactions[] = id(new NuanceItemTransaction())
|
||||
->setTransactionType(NuanceItemTransaction::TYPE_SOURCE)
|
||||
->setNewValue($source_phid);
|
||||
} else {
|
||||
throw new ConduitException('ERR-NO-SOURCE-PHID');
|
||||
}
|
||||
|
||||
if ($owner_phid) {
|
||||
$xactions[] = id(new NuanceItemTransaction())
|
||||
->setTransactionType(NuanceItemTransaction::TYPE_OWNER)
|
||||
->setNewValue($owner_phid);
|
||||
}
|
||||
|
||||
if ($requestor_phid) {
|
||||
$xactions[] = id(new NuanceItemTransaction())
|
||||
->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR)
|
||||
->setNewValue($requestor_phid);
|
||||
} else {
|
||||
throw new ConduitException('ERR-NO-REQUESTOR-PHID');
|
||||
}
|
||||
|
||||
$source = PhabricatorContentSource::newFromConduitRequest($request);
|
||||
$editor = id(new NuanceItemEditor())
|
||||
->setActor($user)
|
||||
->setContentSource($source)
|
||||
->applyTransactions($item, $xactions);
|
||||
|
||||
return $item->toDictionary();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,10 @@ final class NuanceItemEditor
|
|||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
$types[] = NuanceItemTransaction::TYPE_OWNER;
|
||||
$types[] = NuanceItemTransaction::TYPE_SOURCE;
|
||||
$types[] = NuanceItemTransaction::TYPE_REQUESTOR;
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
|
@ -14,4 +18,65 @@ final class NuanceItemEditor
|
|||
return $types;
|
||||
}
|
||||
|
||||
protected function getCustomTransactionOldValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case NuanceItemTransaction::TYPE_REQUESTOR:
|
||||
return $object->getRequestorPHID();
|
||||
case NuanceItemTransaction::TYPE_SOURCE:
|
||||
return $object->getSourcePHID();
|
||||
case NuanceItemTransaction::TYPE_OWNER:
|
||||
return $object->getOwnerPHID();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
||||
}
|
||||
|
||||
protected function getCustomTransactionNewValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case NuanceItemTransaction::TYPE_REQUESTOR:
|
||||
case NuanceItemTransaction::TYPE_SOURCE:
|
||||
case NuanceItemTransaction::TYPE_OWNER:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
||||
}
|
||||
|
||||
protected function applyCustomInternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case NuanceItemTransaction::TYPE_REQUESTOR:
|
||||
$object->setRequestorPHID($xaction->getNewValue());
|
||||
break;
|
||||
case NuanceItemTransaction::TYPE_SOURCE:
|
||||
$object->setSourcePHID($xaction->getNewValue());
|
||||
break;
|
||||
case NuanceItemTransaction::TYPE_OWNER:
|
||||
$object->setOwnerPHID($xaction->getNewValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyCustomExternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case NuanceItemTransaction::TYPE_REQUESTOR:
|
||||
case NuanceItemTransaction::TYPE_SOURCE:
|
||||
case NuanceItemTransaction::TYPE_OWNER:
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@ final class NuanceItem
|
|||
extends NuanceDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
const STATUS_OPEN = 0;
|
||||
const STATUS_ASSIGNED = 10;
|
||||
const STATUS_CLOSED = 20;
|
||||
|
||||
protected $status;
|
||||
protected $ownerPHID;
|
||||
protected $requestorPHID;
|
||||
protected $sourcePHID;
|
||||
|
@ -12,6 +17,11 @@ final class NuanceItem
|
|||
protected $mailKey;
|
||||
protected $dateNuanced;
|
||||
|
||||
public static function initializeNewItem(PhabricatorUser $user) {
|
||||
return id(new NuanceItem())
|
||||
->setDateNuanced(time())
|
||||
->setStatus(NuanceItem::STATUS_OPEN);
|
||||
}
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
|
@ -74,7 +84,7 @@ final class NuanceItem
|
|||
|
||||
public function getPolicy($capability) {
|
||||
// TODO - this should be based on the queues the item currently resides in
|
||||
return PhabricatorPolicies::POLICY_NOONE;
|
||||
return PhabricatorPolicies::POLICY_USER;
|
||||
}
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||
|
@ -92,4 +102,17 @@ final class NuanceItem
|
|||
return null;
|
||||
}
|
||||
|
||||
public function toDictionary() {
|
||||
return array(
|
||||
'id' => $this->getID(),
|
||||
'phid' => $this->getPHID(),
|
||||
'ownerPHID' => $this->getOwnerPHID(),
|
||||
'requestorPHID' => $this->getRequestorPHID(),
|
||||
'sourcePHID' => $this->getSourcePHID(),
|
||||
'sourceLabel' => $this->getSourceLabel(),
|
||||
'dateCreated' => $this->getDateCreated(),
|
||||
'dateModified' => $this->getDateModified(),
|
||||
'dateNuanced' => $this->getDateNuanced(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
final class NuanceItemTransaction
|
||||
extends NuanceTransaction {
|
||||
|
||||
const TYPE_OWNER = 'item-owner';
|
||||
const TYPE_REQUESTOR = 'item-requestor';
|
||||
const TYPE_SOURCE = 'item-source';
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return NuancePHIDTypeItem::TYPECONST;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue