mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +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:
parent
83c528c464
commit
6d9776fa89
1 changed files with 46 additions and 21 deletions
|
@ -630,6 +630,17 @@ abstract class PhabricatorEditEngine
|
|||
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.
|
||||
*
|
||||
|
@ -2031,6 +2042,8 @@ abstract class PhabricatorEditEngine
|
|||
get_class($this)));
|
||||
}
|
||||
|
||||
$raw_xactions = $this->getRawConduitTransactions($request);
|
||||
|
||||
$identifier = $request->getValue('objectIdentifier');
|
||||
if ($identifier) {
|
||||
$this->setIsCreate(false);
|
||||
|
@ -2039,7 +2052,7 @@ abstract class PhabricatorEditEngine
|
|||
$this->requireCreateCapability();
|
||||
|
||||
$this->setIsCreate(true);
|
||||
$object = $this->newEditableObject();
|
||||
$object = $this->newEditableObjectFromConduit($raw_xactions);
|
||||
}
|
||||
|
||||
$this->validateObject($object);
|
||||
|
@ -2049,7 +2062,11 @@ abstract class PhabricatorEditEngine
|
|||
$types = $this->getConduitEditTypesFromFields($fields);
|
||||
$template = $object->getApplicationTransactionTemplate();
|
||||
|
||||
$xactions = $this->getConduitTransactions($request, $types, $template);
|
||||
$xactions = $this->getConduitTransactions(
|
||||
$request,
|
||||
$raw_xactions,
|
||||
$types,
|
||||
$template);
|
||||
|
||||
$editor = $object->getApplicationTransactionEditor()
|
||||
->setActor($viewer)
|
||||
|
@ -2078,23 +2095,7 @@ abstract class PhabricatorEditEngine
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
private function getRawConduitTransactions(ConduitAPIRequest $request) {
|
||||
$transactions_key = 'transactions';
|
||||
|
||||
$xactions = $request->getValue($transactions_key);
|
||||
|
@ -2124,7 +2125,33 @@ abstract class PhabricatorEditEngine
|
|||
$transactions_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'];
|
||||
if (empty($types[$type])) {
|
||||
throw new Exception(
|
||||
|
@ -2137,8 +2164,6 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
}
|
||||
|
||||
$results = array();
|
||||
|
||||
if ($this->getIsCreate()) {
|
||||
$results[] = id(clone $template)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_CREATE);
|
||||
|
|
Loading…
Reference in a new issue