1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-31 14:38:15 +02:00
phorge-phorge/src/applications/harbormaster/controller/HarbormasterStepAddController.php
epriestley 081300c7f8 Modernize some Harbormaster Controller/Policy infrastructure
Summary:
Ref T8095. This is just general groundwork for more exciting changes:

  - Use more modern conventions around controllers, UI elements, and dialogs.
  - Provide real CAN_EDIT policies and policy checks (they just don't do anything yet).

Test Plan:
  - Used all affected controllers.
  - Faked CAN_EDIT to POLICY_NOONE and verified everything was greyed out and unselectable.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8095

Differential Revision: https://secure.phabricator.com/D13344
2015-06-21 09:02:44 -07:00

64 lines
1.9 KiB
PHP

<?php
final class HarbormasterStepAddController extends HarbormasterController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$this->requireApplicationCapability(
HarbormasterManagePlansCapability::CAPABILITY);
$plan = id(new HarbormasterBuildPlanQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$plan) {
return new Aphront404Response();
}
$plan_id = $plan->getID();
$cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
$errors = array();
if ($request->isFormPost()) {
$class = $request->getStr('class');
if (!HarbormasterBuildStepImplementation::getImplementation($class)) {
$errors[] = pht('Choose the type of build step you want to add.');
}
if (!$errors) {
$new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
return id(new AphrontRedirectResponse())->setURI($new_uri);
}
}
$control = id(new AphrontFormRadioButtonControl())
->setName('class');
$all = HarbormasterBuildStepImplementation::getImplementations();
foreach ($all as $class => $implementation) {
$control->addButton(
$class,
$implementation->getName(),
$implementation->getGenericDescription());
}
if ($errors) {
$errors = id(new PHUIInfoView())
->setErrors($errors);
}
return $this->newDialog()
->setTitle(pht('Add New Step'))
->addSubmitButton(pht('Add Build Step'))
->addCancelButton($cancel_uri)
->appendChild($errors)
->appendParagraph(pht('Choose a type of build step to add:'))
->appendChild($control);
}
}