1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Give EditEngine a Conduit-specific initialization pathway for objects

Summary:
Depends on D18845. See PHI243 for context and more details.

Briefly, some objects need a "type" transaction (or something similar) very early on, and we can't generate their fields until we know the object type. Drydock blueprints are an example: a blueprint's fields depend on the blueprint's type.

In web interfaces, the workflow just forces the user to select a type first. For Conduit workflows, I think the cleanest approach is to proactively extract and apply type information before processing the request. This will make the implementation a little messier, but the API cleaner.

An alternative is to add more fields to the API, like a "type" field. This makes the implementation cleaner, but the API messier. I think we're better off favoring a cleaner API here.

This change just makes it possible for `DrydockBlueprintEditEngine` to look at the incoming transactions and extract a "type"; it doesn't actually change any behavior.

Test Plan: Performed edits via API, but this change doesn't alter any behavior.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D18847
This commit is contained in:
epriestley 2017-12-13 07:47:18 -08:00
parent 83c528c464
commit 6d9776fa89

View file

@ -630,6 +630,17 @@ abstract class PhabricatorEditEngine
return $this->isCreate; return $this->isCreate;
} }
/**
* Initialize a new object for object creation via Conduit.
*
* @return object Newly initialized object.
* @param list<wild> Raw transactions.
* @task load
*/
protected function newEditableObjectFromConduit(array $raw_xactions) {
return $this->newEditableObject();
}
/** /**
* Initialize a new object for documentation creation. * Initialize a new object for documentation creation.
* *
@ -2031,6 +2042,8 @@ abstract class PhabricatorEditEngine
get_class($this))); get_class($this)));
} }
$raw_xactions = $this->getRawConduitTransactions($request);
$identifier = $request->getValue('objectIdentifier'); $identifier = $request->getValue('objectIdentifier');
if ($identifier) { if ($identifier) {
$this->setIsCreate(false); $this->setIsCreate(false);
@ -2039,7 +2052,7 @@ abstract class PhabricatorEditEngine
$this->requireCreateCapability(); $this->requireCreateCapability();
$this->setIsCreate(true); $this->setIsCreate(true);
$object = $this->newEditableObject(); $object = $this->newEditableObjectFromConduit($raw_xactions);
} }
$this->validateObject($object); $this->validateObject($object);
@ -2049,7 +2062,11 @@ abstract class PhabricatorEditEngine
$types = $this->getConduitEditTypesFromFields($fields); $types = $this->getConduitEditTypesFromFields($fields);
$template = $object->getApplicationTransactionTemplate(); $template = $object->getApplicationTransactionTemplate();
$xactions = $this->getConduitTransactions($request, $types, $template); $xactions = $this->getConduitTransactions(
$request,
$raw_xactions,
$types,
$template);
$editor = $object->getApplicationTransactionEditor() $editor = $object->getApplicationTransactionEditor()
->setActor($viewer) ->setActor($viewer)
@ -2078,23 +2095,7 @@ abstract class PhabricatorEditEngine
); );
} }
private function getRawConduitTransactions(ConduitAPIRequest $request) {
/**
* Generate transactions which can be applied from edit actions in a Conduit
* request.
*
* @param ConduitAPIRequest The request.
* @param list<PhabricatorEditType> Supported edit types.
* @param PhabricatorApplicationTransaction Template transaction.
* @return list<PhabricatorApplicationTransaction> Generated transactions.
* @task conduit
*/
private function getConduitTransactions(
ConduitAPIRequest $request,
array $types,
PhabricatorApplicationTransaction $template) {
$viewer = $request->getUser();
$transactions_key = 'transactions'; $transactions_key = 'transactions';
$xactions = $request->getValue($transactions_key); $xactions = $request->getValue($transactions_key);
@ -2124,7 +2125,33 @@ abstract class PhabricatorEditEngine
$transactions_key, $transactions_key,
$key)); $key));
} }
}
return $xactions;
}
/**
* Generate transactions which can be applied from edit actions in a Conduit
* request.
*
* @param ConduitAPIRequest The request.
* @param list<wild> Raw conduit transactions.
* @param list<PhabricatorEditType> Supported edit types.
* @param PhabricatorApplicationTransaction Template transaction.
* @return list<PhabricatorApplicationTransaction> Generated transactions.
* @task conduit
*/
private function getConduitTransactions(
ConduitAPIRequest $request,
array $xactions,
array $types,
PhabricatorApplicationTransaction $template) {
$viewer = $request->getUser();
$results = array();
foreach ($xactions as $key => $xaction) {
$type = $xaction['type']; $type = $xaction['type'];
if (empty($types[$type])) { if (empty($types[$type])) {
throw new Exception( throw new Exception(
@ -2137,8 +2164,6 @@ abstract class PhabricatorEditEngine
} }
} }
$results = array();
if ($this->getIsCreate()) { if ($this->getIsCreate()) {
$results[] = id(clone $template) $results[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_CREATE); ->setTransactionType(PhabricatorTransactions::TYPE_CREATE);