1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 19:02:41 +01:00
phorge-phorge/src/applications/drydock/controller/DrydockBlueprintCreateController.php
James Rhodes ba16df0fed Restructure Drydock so that blueprints are instances in the DB
Summary:
//(this diff used to be about applying policies to blueprints)//

This restructures Drydock so that blueprints are instances in the DB, with an associated implementation class.  Thus resources now have a `blueprintPHID` instead of `blueprintClass` and DrydockBlueprint becomes a DAO.  The old DrydockBlueprint is renamed to DrydockBlueprintImplementation, and the DrydockBlueprint DAO has a `blueprintClass` column on it.

This now just implements CAN_VIEW and CAN_EDIT policies for blueprints, although they are probably not enforced in all of the places they could be.

Test Plan: Used the `create-resource` and `lease` commands.  Closed resources and leases in the UI.  Clicked around the new and old lists to make sure everything is still working.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4111, T2015

Differential Revision: https://secure.phabricator.com/D7638
2013-12-03 11:09:07 +11:00

68 lines
2 KiB
PHP

<?php
final class DrydockBlueprintCreateController
extends DrydockController {
public function willProcessRequest(array $data) {
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$implementations =
DrydockBlueprintImplementation::getAllBlueprintImplementations();
if ($request->isFormPost()) {
$class = $request->getStr('blueprint-type');
if (!isset($implementations[$class])) {
return $this->createDialog($implementations);
}
$blueprint = new DrydockBlueprint();
$blueprint->setClassName($class);
$blueprint->setDetails(array());
$blueprint->setViewPolicy(PhabricatorPolicies::POLICY_ADMIN);
$blueprint->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
$blueprint->save();
$edit_uri = $this->getApplicationURI(
"blueprint/edit/".$blueprint->getID()."/");
return id(new AphrontRedirectResponse())->setURI($edit_uri);
}
return $this->createDialog($implementations);
}
function createDialog(array $implementations) {
$request = $this->getRequest();
$viewer = $request->getUser();
$control = id(new AphrontFormRadioButtonControl())
->setName('blueprint-type');
foreach ($implementations as $implementation_name => $implementation) {
$control
->addButton(
$implementation_name,
$implementation->getBlueprintClass(),
$implementation->getDescription());
}
$dialog = new AphrontDialogView();
$dialog->setTitle(pht('Create New Blueprint'))
->setUser($viewer)
->addSubmitButton(pht('Create Blueprint'))
->addCancelButton($this->getApplicationURI('blueprint/'));
$dialog->appendChild(
phutil_tag(
'p',
array(),
pht(
'Select what type of blueprint you want to create: ')));
$dialog->appendChild($control);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}