mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Use EditEngine for Almanac Services, Devices, and Networks
Summary: Ref T10411. This cleans up / modernizes things and lets me get an `almanac.network.edit` API in the future. This is mostly straightforward, except that Services have an extra "choose type" screen in front of them. Test Plan: - Created and edited Almanac networks, services, and devices. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10411 Differential Revision: https://secure.phabricator.com/D15326
This commit is contained in:
parent
ab86523ac4
commit
24104be67d
5 changed files with 103 additions and 149 deletions
|
@ -79,6 +79,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacNetwork' => 'applications/almanac/storage/AlmanacNetwork.php',
|
'AlmanacNetwork' => 'applications/almanac/storage/AlmanacNetwork.php',
|
||||||
'AlmanacNetworkController' => 'applications/almanac/controller/AlmanacNetworkController.php',
|
'AlmanacNetworkController' => 'applications/almanac/controller/AlmanacNetworkController.php',
|
||||||
'AlmanacNetworkEditController' => 'applications/almanac/controller/AlmanacNetworkEditController.php',
|
'AlmanacNetworkEditController' => 'applications/almanac/controller/AlmanacNetworkEditController.php',
|
||||||
|
'AlmanacNetworkEditEngine' => 'applications/almanac/editor/AlmanacNetworkEditEngine.php',
|
||||||
'AlmanacNetworkEditor' => 'applications/almanac/editor/AlmanacNetworkEditor.php',
|
'AlmanacNetworkEditor' => 'applications/almanac/editor/AlmanacNetworkEditor.php',
|
||||||
'AlmanacNetworkListController' => 'applications/almanac/controller/AlmanacNetworkListController.php',
|
'AlmanacNetworkListController' => 'applications/almanac/controller/AlmanacNetworkListController.php',
|
||||||
'AlmanacNetworkNameNgrams' => 'applications/almanac/storage/AlmanacNetworkNameNgrams.php',
|
'AlmanacNetworkNameNgrams' => 'applications/almanac/storage/AlmanacNetworkNameNgrams.php',
|
||||||
|
@ -4072,7 +4073,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorNgramsInterface',
|
'PhabricatorNgramsInterface',
|
||||||
),
|
),
|
||||||
'AlmanacNamespaceController' => 'AlmanacController',
|
'AlmanacNamespaceController' => 'AlmanacController',
|
||||||
'AlmanacNamespaceEditController' => 'AlmanacController',
|
'AlmanacNamespaceEditController' => 'AlmanacNamespaceController',
|
||||||
'AlmanacNamespaceEditEngine' => 'PhabricatorEditEngine',
|
'AlmanacNamespaceEditEngine' => 'PhabricatorEditEngine',
|
||||||
'AlmanacNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
'AlmanacNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'AlmanacNamespaceListController' => 'AlmanacNamespaceController',
|
'AlmanacNamespaceListController' => 'AlmanacNamespaceController',
|
||||||
|
@ -4092,6 +4093,7 @@ phutil_register_library_map(array(
|
||||||
),
|
),
|
||||||
'AlmanacNetworkController' => 'AlmanacController',
|
'AlmanacNetworkController' => 'AlmanacController',
|
||||||
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
||||||
|
'AlmanacNetworkEditEngine' => 'PhabricatorEditEngine',
|
||||||
'AlmanacNetworkEditor' => 'PhabricatorApplicationTransactionEditor',
|
'AlmanacNetworkEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'AlmanacNetworkListController' => 'AlmanacNetworkController',
|
'AlmanacNetworkListController' => 'AlmanacNetworkController',
|
||||||
'AlmanacNetworkNameNgrams' => 'PhabricatorSearchNgrams',
|
'AlmanacNetworkNameNgrams' => 'PhabricatorSearchNgrams',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class AlmanacNamespaceEditController extends AlmanacController {
|
final class AlmanacNamespaceEditController extends AlmanacNamespaceController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
return id(new AlmanacNamespaceEditEngine())
|
return id(new AlmanacNamespaceEditEngine())
|
||||||
|
|
|
@ -1,142 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class AlmanacNetworkEditController
|
final class AlmanacNetworkEditController extends AlmanacNetworkController {
|
||||||
extends AlmanacNetworkController {
|
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $request->getViewer();
|
return id(new AlmanacNetworkEditEngine())
|
||||||
|
->setController($this)
|
||||||
$list_uri = $this->getApplicationURI('network/');
|
->buildResponse();
|
||||||
|
|
||||||
$id = $request->getURIData('id');
|
|
||||||
if ($id) {
|
|
||||||
$network = id(new AlmanacNetworkQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withIDs(array($id))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
if (!$network) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
$is_new = false;
|
|
||||||
$network_uri = $this->getApplicationURI('network/'.$network->getID().'/');
|
|
||||||
$cancel_uri = $network_uri;
|
|
||||||
$title = pht('Edit Network');
|
|
||||||
$save_button = pht('Save Changes');
|
|
||||||
} else {
|
|
||||||
$this->requireApplicationCapability(
|
|
||||||
AlmanacCreateNetworksCapability::CAPABILITY);
|
|
||||||
|
|
||||||
$network = AlmanacNetwork::initializeNewNetwork();
|
|
||||||
$is_new = true;
|
|
||||||
|
|
||||||
$cancel_uri = $list_uri;
|
|
||||||
$title = pht('Create Network');
|
|
||||||
$save_button = pht('Create Network');
|
|
||||||
}
|
|
||||||
|
|
||||||
$v_name = $network->getName();
|
|
||||||
$e_name = true;
|
|
||||||
$validation_exception = null;
|
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
|
||||||
$v_name = $request->getStr('name');
|
|
||||||
$v_view = $request->getStr('viewPolicy');
|
|
||||||
$v_edit = $request->getStr('editPolicy');
|
|
||||||
|
|
||||||
$type_name = AlmanacNetworkTransaction::TYPE_NAME;
|
|
||||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
|
||||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
|
||||||
|
|
||||||
$xactions = array();
|
|
||||||
|
|
||||||
$xactions[] = id(new AlmanacNetworkTransaction())
|
|
||||||
->setTransactionType($type_name)
|
|
||||||
->setNewValue($v_name);
|
|
||||||
|
|
||||||
$xactions[] = id(new AlmanacNetworkTransaction())
|
|
||||||
->setTransactionType($type_view)
|
|
||||||
->setNewValue($v_view);
|
|
||||||
|
|
||||||
$xactions[] = id(new AlmanacNetworkTransaction())
|
|
||||||
->setTransactionType($type_edit)
|
|
||||||
->setNewValue($v_edit);
|
|
||||||
|
|
||||||
$editor = id(new AlmanacNetworkEditor())
|
|
||||||
->setActor($viewer)
|
|
||||||
->setContentSourceFromRequest($request)
|
|
||||||
->setContinueOnNoEffect(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$editor->applyTransactions($network, $xactions);
|
|
||||||
|
|
||||||
$id = $network->getID();
|
|
||||||
$network_uri = $this->getApplicationURI("network/{$id}/");
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($network_uri);
|
|
||||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
||||||
$validation_exception = $ex;
|
|
||||||
$e_name = $ex->getShortMessage($type_name);
|
|
||||||
|
|
||||||
$network->setViewPolicy($v_view);
|
|
||||||
$network->setEditPolicy($v_edit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$policies = id(new PhabricatorPolicyQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->setObject($network)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
|
||||||
->setUser($viewer)
|
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormTextControl())
|
|
||||||
->setLabel(pht('Name'))
|
|
||||||
->setName('name')
|
|
||||||
->setValue($v_name)
|
|
||||||
->setError($e_name))
|
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormPolicyControl())
|
|
||||||
->setName('viewPolicy')
|
|
||||||
->setPolicyObject($network)
|
|
||||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
|
||||||
->setPolicies($policies))
|
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormPolicyControl())
|
|
||||||
->setName('editPolicy')
|
|
||||||
->setPolicyObject($network)
|
|
||||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
|
||||||
->setPolicies($policies))
|
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormSubmitControl())
|
|
||||||
->addCancelButton($cancel_uri)
|
|
||||||
->setValue($save_button));
|
|
||||||
|
|
||||||
$box = id(new PHUIObjectBoxView())
|
|
||||||
->setValidationException($validation_exception)
|
|
||||||
->setHeaderText($title)
|
|
||||||
->setForm($form);
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
|
||||||
if ($is_new) {
|
|
||||||
$crumbs->addTextCrumb(pht('Create Network'));
|
|
||||||
} else {
|
|
||||||
$crumbs->addTextCrumb($network->getName(), $network_uri);
|
|
||||||
$crumbs->addTextCrumb(pht('Edit'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->newPage()
|
|
||||||
->setTitle($title)
|
|
||||||
->setCrumbs($crumbs)
|
|
||||||
->appendChild(
|
|
||||||
array(
|
|
||||||
$box,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
86
src/applications/almanac/editor/AlmanacNetworkEditEngine.php
Normal file
86
src/applications/almanac/editor/AlmanacNetworkEditEngine.php
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class AlmanacNetworkEditEngine
|
||||||
|
extends PhabricatorEditEngine {
|
||||||
|
|
||||||
|
const ENGINECONST = 'almanac.network';
|
||||||
|
|
||||||
|
public function isEngineConfigurable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEngineName() {
|
||||||
|
return pht('Almanac Networks');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummaryHeader() {
|
||||||
|
return pht('Edit Almanac Network Configurations');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummaryText() {
|
||||||
|
return pht('This engine is used to edit Almanac networks.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEngineApplicationClass() {
|
||||||
|
return 'PhabricatorAlmanacApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newEditableObject() {
|
||||||
|
return AlmanacNetwork::initializeNewNetwork();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newObjectQuery() {
|
||||||
|
return new AlmanacNetworkQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectCreateTitleText($object) {
|
||||||
|
return pht('Create Network');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectCreateButtonText($object) {
|
||||||
|
return pht('Create Network');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectEditTitleText($object) {
|
||||||
|
return pht('Edit Network: %s', $object->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectEditShortText($object) {
|
||||||
|
return pht('Edit Network');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectCreateShortText() {
|
||||||
|
return pht('Create Network');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getEditorURI() {
|
||||||
|
return '/almanac/network/edit/';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectCreateCancelURI($object) {
|
||||||
|
return '/almanac/network/';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectViewURI($object) {
|
||||||
|
$id = $object->getID();
|
||||||
|
return "/almanac/network/{$id}/";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getCreateNewObjectPolicy() {
|
||||||
|
return $this->getApplication()->getPolicy(
|
||||||
|
AlmanacCreateNetworksCapability::CAPABILITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildCustomEditFields($object) {
|
||||||
|
return array(
|
||||||
|
id(new PhabricatorTextEditField())
|
||||||
|
->setKey('name')
|
||||||
|
->setLabel(pht('Name'))
|
||||||
|
->setDescription(pht('Name of the network.'))
|
||||||
|
->setTransactionType(AlmanacNetworkTransaction::TYPE_NAME)
|
||||||
|
->setIsRequired(true)
|
||||||
|
->setValue($object->getName()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,20 +24,17 @@ final class AlmanacNetworkTransaction
|
||||||
$new = $this->getNewValue();
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_NAME:
|
case PhabricatorTransactions::TYPE_CREATE:
|
||||||
if ($old === null) {
|
|
||||||
return pht(
|
return pht(
|
||||||
'%s created this network.',
|
'%s created this network.',
|
||||||
$this->renderHandleLink($author_phid));
|
$this->renderHandleLink($author_phid));
|
||||||
} else {
|
case self::TYPE_NAME:
|
||||||
return pht(
|
return pht(
|
||||||
'%s renamed this network from "%s" to "%s".',
|
'%s renamed this network from "%s" to "%s".',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
$old,
|
$old,
|
||||||
$new);
|
$new);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue