1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +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:
James Rhodes 2014-08-12 08:39:00 +10:00
parent efc82c727b
commit e48aaa563a
7 changed files with 136 additions and 5 deletions

View file

@ -569,7 +569,9 @@ phutil_register_library_map(array(
'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php',
'DrydockBlueprint' => 'applications/drydock/storage/DrydockBlueprint.php',
'DrydockBlueprintController' => 'applications/drydock/controller/DrydockBlueprintController.php',
'DrydockBlueprintCoreCustomField' => 'applications/drydock/customfield/DrydockBlueprintCoreCustomField.php',
'DrydockBlueprintCreateController' => 'applications/drydock/controller/DrydockBlueprintCreateController.php',
'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php',
'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php',
'DrydockBlueprintEditor' => 'applications/drydock/editor/DrydockBlueprintEditor.php',
'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php',
@ -3306,9 +3308,15 @@ phutil_register_library_map(array(
'DrydockBlueprint' => array(
'DrydockDAO',
'PhabricatorPolicyInterface',
'PhabricatorCustomFieldInterface',
),
'DrydockBlueprintController' => 'DrydockController',
'DrydockBlueprintCoreCustomField' => array(
'DrydockBlueprintCustomField',
'PhabricatorStandardCustomFieldInterface',
),
'DrydockBlueprintCreateController' => 'DrydockBlueprintController',
'DrydockBlueprintCustomField' => 'PhabricatorCustomField',
'DrydockBlueprintEditController' => 'DrydockBlueprintController',
'DrydockBlueprintEditor' => 'PhabricatorApplicationTransactionEditor',
'DrydockBlueprintListController' => 'DrydockBlueprintController',

View file

@ -56,6 +56,14 @@ abstract class DrydockBlueprintImplementation {
return $this;
}
public function getFieldSpecifications() {
return array();
}
public function getDetail($key, $default = null) {
return $this->getInstance()->getDetail($key, $default);
}
/* -( Lease Acquisition )-------------------------------------------------- */

View file

@ -44,9 +44,17 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$cancel_uri = $this->getApplicationURI('blueprint/');
}
$field_list = PhabricatorCustomField::getObjectFields(
$blueprint,
PhabricatorCustomField::ROLE_EDIT);
$field_list
->setViewer($viewer)
->readFieldsFromStorage($blueprint);
$v_name = $blueprint->getBlueprintName();
$e_name = true;
$errors = array();
$validation_exception = null;
if ($request->isFormPost()) {
$v_view_policy = $request->getStr('viewPolicy');
@ -60,6 +68,10 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
if (!$errors) {
$xactions = array();
$xactions = $field_list->buildFieldTransactionsFromRequest(
new DrydockBlueprintTransaction(),
$request);
$xactions[] = id(new DrydockBlueprintTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
->setNewValue($v_view_policy);
@ -77,12 +89,16 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
$editor->applyTransactions($blueprint, $xactions);
try {
$editor->applyTransactions($blueprint, $xactions);
$id = $blueprint->getID();
$save_uri = $this->getApplicationURI("blueprint/{$id}/");
$id = $blueprint->getID();
$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)
->setPolicies($policies));
$field_list->appendFieldsToForm($form);
$crumbs = $this->buildApplicationCrumbs();
if ($blueprint->getID()) {
@ -139,6 +157,7 @@ final class DrydockBlueprintEditController extends DrydockBlueprintController {
$box = id(new PHUIObjectBoxView())
->setHeaderText($header)
->setValidationException($validation_exception)
->setFormErrors($errors)
->setForm($form);

View file

@ -61,6 +61,18 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
->withObjectPHIDs(array($blueprint->getPHID()))
->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())
->setViewer($viewer);

View file

@ -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;
}
}

View file

@ -0,0 +1,6 @@
<?php
abstract class DrydockBlueprintCustomField
extends PhabricatorCustomField {
}

View file

@ -1,7 +1,9 @@
<?php
final class DrydockBlueprint extends DrydockDAO
implements PhabricatorPolicyInterface {
implements
PhabricatorPolicyInterface,
PhabricatorCustomFieldInterface {
protected $className;
protected $blueprintName;
@ -10,6 +12,7 @@ final class DrydockBlueprint extends DrydockDAO
protected $details = array();
private $implementation = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
public static function initializeNewBlueprint(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
@ -58,6 +61,15 @@ final class DrydockBlueprint extends DrydockDAO
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 )----------------------------------------- */
@ -86,4 +98,27 @@ final class DrydockBlueprint extends DrydockDAO
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;
}
}