mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Allow Drydock blueprints to define and use custom fields
Summary: This allows Drydock blueprints to define custom fields for blueprint settings. Test Plan: Pulled out of EC2 allocator diff. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10224
This commit is contained in:
parent
efc82c727b
commit
e48aaa563a
7 changed files with 136 additions and 5 deletions
|
@ -569,7 +569,9 @@ phutil_register_library_map(array(
|
||||||
'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php',
|
'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php',
|
||||||
'DrydockBlueprint' => 'applications/drydock/storage/DrydockBlueprint.php',
|
'DrydockBlueprint' => 'applications/drydock/storage/DrydockBlueprint.php',
|
||||||
'DrydockBlueprintController' => 'applications/drydock/controller/DrydockBlueprintController.php',
|
'DrydockBlueprintController' => 'applications/drydock/controller/DrydockBlueprintController.php',
|
||||||
|
'DrydockBlueprintCoreCustomField' => 'applications/drydock/customfield/DrydockBlueprintCoreCustomField.php',
|
||||||
'DrydockBlueprintCreateController' => 'applications/drydock/controller/DrydockBlueprintCreateController.php',
|
'DrydockBlueprintCreateController' => 'applications/drydock/controller/DrydockBlueprintCreateController.php',
|
||||||
|
'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php',
|
||||||
'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php',
|
'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php',
|
||||||
'DrydockBlueprintEditor' => 'applications/drydock/editor/DrydockBlueprintEditor.php',
|
'DrydockBlueprintEditor' => 'applications/drydock/editor/DrydockBlueprintEditor.php',
|
||||||
'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php',
|
'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php',
|
||||||
|
@ -3306,9 +3308,15 @@ phutil_register_library_map(array(
|
||||||
'DrydockBlueprint' => array(
|
'DrydockBlueprint' => array(
|
||||||
'DrydockDAO',
|
'DrydockDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
'PhabricatorCustomFieldInterface',
|
||||||
),
|
),
|
||||||
'DrydockBlueprintController' => 'DrydockController',
|
'DrydockBlueprintController' => 'DrydockController',
|
||||||
|
'DrydockBlueprintCoreCustomField' => array(
|
||||||
|
'DrydockBlueprintCustomField',
|
||||||
|
'PhabricatorStandardCustomFieldInterface',
|
||||||
|
),
|
||||||
'DrydockBlueprintCreateController' => 'DrydockBlueprintController',
|
'DrydockBlueprintCreateController' => 'DrydockBlueprintController',
|
||||||
|
'DrydockBlueprintCustomField' => 'PhabricatorCustomField',
|
||||||
'DrydockBlueprintEditController' => 'DrydockBlueprintController',
|
'DrydockBlueprintEditController' => 'DrydockBlueprintController',
|
||||||
'DrydockBlueprintEditor' => 'PhabricatorApplicationTransactionEditor',
|
'DrydockBlueprintEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'DrydockBlueprintListController' => 'DrydockBlueprintController',
|
'DrydockBlueprintListController' => 'DrydockBlueprintController',
|
||||||
|
|
|
@ -56,6 +56,14 @@ abstract class DrydockBlueprintImplementation {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFieldSpecifications() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDetail($key, $default = null) {
|
||||||
|
return $this->getInstance()->getDetail($key, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Lease Acquisition )-------------------------------------------------- */
|
/* -( Lease Acquisition )-------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,17 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
|
||||||
$cancel_uri = $this->getApplicationURI('blueprint/');
|
$cancel_uri = $this->getApplicationURI('blueprint/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$field_list = PhabricatorCustomField::getObjectFields(
|
||||||
|
$blueprint,
|
||||||
|
PhabricatorCustomField::ROLE_EDIT);
|
||||||
|
$field_list
|
||||||
|
->setViewer($viewer)
|
||||||
|
->readFieldsFromStorage($blueprint);
|
||||||
|
|
||||||
$v_name = $blueprint->getBlueprintName();
|
$v_name = $blueprint->getBlueprintName();
|
||||||
$e_name = true;
|
$e_name = true;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
$validation_exception = null;
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$v_view_policy = $request->getStr('viewPolicy');
|
$v_view_policy = $request->getStr('viewPolicy');
|
||||||
|
@ -60,6 +68,10 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
|
$xactions = $field_list->buildFieldTransactionsFromRequest(
|
||||||
|
new DrydockBlueprintTransaction(),
|
||||||
|
$request);
|
||||||
|
|
||||||
$xactions[] = id(new DrydockBlueprintTransaction())
|
$xactions[] = id(new DrydockBlueprintTransaction())
|
||||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||||
->setNewValue($v_view_policy);
|
->setNewValue($v_view_policy);
|
||||||
|
@ -77,12 +89,16 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
|
||||||
->setContentSourceFromRequest($request)
|
->setContentSourceFromRequest($request)
|
||||||
->setContinueOnNoEffect(true);
|
->setContinueOnNoEffect(true);
|
||||||
|
|
||||||
$editor->applyTransactions($blueprint, $xactions);
|
try {
|
||||||
|
$editor->applyTransactions($blueprint, $xactions);
|
||||||
|
|
||||||
$id = $blueprint->getID();
|
$id = $blueprint->getID();
|
||||||
$save_uri = $this->getApplicationURI("blueprint/{$id}/");
|
$save_uri = $this->getApplicationURI("blueprint/{$id}/");
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($save_uri);
|
return id(new AphrontRedirectResponse())->setURI($save_uri);
|
||||||
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||||
|
$validation_exception = $ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +133,8 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
|
||||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||||
->setPolicies($policies));
|
->setPolicies($policies));
|
||||||
|
|
||||||
|
$field_list->appendFieldsToForm($form);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
|
||||||
if ($blueprint->getID()) {
|
if ($blueprint->getID()) {
|
||||||
|
@ -139,6 +157,7 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
|
||||||
|
|
||||||
$box = id(new PHUIObjectBoxView())
|
$box = id(new PHUIObjectBoxView())
|
||||||
->setHeaderText($header)
|
->setHeaderText($header)
|
||||||
|
->setValidationException($validation_exception)
|
||||||
->setFormErrors($errors)
|
->setFormErrors($errors)
|
||||||
->setForm($form);
|
->setForm($form);
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,18 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
|
||||||
->withObjectPHIDs(array($blueprint->getPHID()))
|
->withObjectPHIDs(array($blueprint->getPHID()))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
$field_list = PhabricatorCustomField::getObjectFields(
|
||||||
|
$blueprint,
|
||||||
|
PhabricatorCustomField::ROLE_VIEW);
|
||||||
|
$field_list
|
||||||
|
->setViewer($viewer)
|
||||||
|
->readFieldsFromStorage($blueprint);
|
||||||
|
|
||||||
|
$field_list->appendFieldsToPropertyList(
|
||||||
|
$blueprint,
|
||||||
|
$viewer,
|
||||||
|
$properties);
|
||||||
|
|
||||||
$engine = id(new PhabricatorMarkupEngine())
|
$engine = id(new PhabricatorMarkupEngine())
|
||||||
->setViewer($viewer);
|
->setViewer($viewer);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DrydockBlueprintCoreCustomField
|
||||||
|
extends DrydockBlueprintCustomField
|
||||||
|
implements PhabricatorStandardCustomFieldInterface {
|
||||||
|
|
||||||
|
public function getStandardCustomFieldNamespace() {
|
||||||
|
return 'drydock:core';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createFields($object) {
|
||||||
|
$impl = $object->getImplementation();
|
||||||
|
$specs = $impl->getFieldSpecifications();
|
||||||
|
|
||||||
|
return PhabricatorStandardCustomField::buildStandardFields($this, $specs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldUseStorage() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
|
||||||
|
$key = $this->getProxy()->getRawStandardFieldKey();
|
||||||
|
$this->setValueFromStorage($object->getDetail($key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyApplicationTransactionInternalEffects(
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
$object = $this->getObject();
|
||||||
|
$key = $this->getProxy()->getRawStandardFieldKey();
|
||||||
|
|
||||||
|
$this->setValueFromApplicationTransactions($xaction->getNewValue());
|
||||||
|
$value = $this->getValueForStorage();
|
||||||
|
|
||||||
|
$object->setDetail($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyApplicationTransactionExternalEffects(
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class DrydockBlueprintCustomField
|
||||||
|
extends PhabricatorCustomField {
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockBlueprint extends DrydockDAO
|
final class DrydockBlueprint extends DrydockDAO
|
||||||
implements PhabricatorPolicyInterface {
|
implements
|
||||||
|
PhabricatorPolicyInterface,
|
||||||
|
PhabricatorCustomFieldInterface {
|
||||||
|
|
||||||
protected $className;
|
protected $className;
|
||||||
protected $blueprintName;
|
protected $blueprintName;
|
||||||
|
@ -10,6 +12,7 @@ final class DrydockBlueprint extends DrydockDAO
|
||||||
protected $details = array();
|
protected $details = array();
|
||||||
|
|
||||||
private $implementation = self::ATTACHABLE;
|
private $implementation = self::ATTACHABLE;
|
||||||
|
private $customFields = self::ATTACHABLE;
|
||||||
|
|
||||||
public static function initializeNewBlueprint(PhabricatorUser $actor) {
|
public static function initializeNewBlueprint(PhabricatorUser $actor) {
|
||||||
$app = id(new PhabricatorApplicationQuery())
|
$app = id(new PhabricatorApplicationQuery())
|
||||||
|
@ -58,6 +61,15 @@ final class DrydockBlueprint extends DrydockDAO
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDetail($key, $default = null) {
|
||||||
|
return idx($this->details, $key, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDetail($key, $value) {
|
||||||
|
$this->details[$key] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
@ -86,4 +98,27 @@ final class DrydockBlueprint extends DrydockDAO
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
public function getCustomFieldSpecificationForRole($role) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomFieldBaseClass() {
|
||||||
|
return 'DrydockBlueprintCustomField';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomFields() {
|
||||||
|
return $this->assertAttached($this->customFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
|
||||||
|
$this->customFields = $fields;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue