Projects - merge create + edit interface code paths

Summary:
Fixes T6145, T4016.

Filed T6287 and T6288 for some polish on this.

Test Plan: Made new projects from Maniphest - great success. Made new projects from project / create - also great success.

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4016, T6145

Differential Revision: https://secure.phabricator.com/D10679
This commit is contained in:
Bob Trahan
2014-10-10 16:57:05 -07:00
parent 159e56d58a
commit ee8004ab4d
7 changed files with 130 additions and 162 deletions

View File

@@ -6,25 +6,37 @@ final class PhabricatorProjectEditDetailsController
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->needSlugs(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$project) {
return new Aphront404Response();
if ($this->id) {
$is_new = false;
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->needSlugs(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
} else {
$is_new = true;
$this->requireApplicationCapability(
ProjectCreateProjectsCapability::CAPABILITY);
$project = PhabricatorProject::initializeNewProject($viewer);
}
$field_list = PhabricatorCustomField::getObjectFields(
@@ -114,10 +126,37 @@ final class PhabricatorProjectEditDetailsController
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
if ($is_new) {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue(
'edge:type',
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setNewValue(
array(
'+' => array($viewer->getPHID() => $viewer->getPHID()),
));
}
try {
$editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(array(
'phid' => $project->getPHID(),
'name' => $project->getName(),
));
}
if ($is_new) {
$redirect_uri = $view_uri;
} else {
$redirect_uri = $edit_uri;
}
return id(new AphrontRedirectResponse())->setURI($redirect_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
@@ -131,8 +170,13 @@ final class PhabricatorProjectEditDetailsController
}
}
$header_name = pht('Edit Project');
$title = pht('Edit Project');
if ($is_new) {
$header_name = pht('Create a New Project');
$title = pht('Create Project');
} else {
$header_name = pht('Edit Project');
$title = pht('Edit Project');
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
@@ -140,8 +184,7 @@ final class PhabricatorProjectEditDetailsController
->execute();
$v_slugs = implode(', ', $v_slugs);
$form = new AphrontFormView();
$form
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
@@ -153,7 +196,11 @@ final class PhabricatorProjectEditDetailsController
$shades = PhabricatorProjectIcon::getColorMap();
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
if ($is_new) {
$icon_uri = $this->getApplicationURI('icon/');
} else {
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
}
$icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon);
list($can_lock, $lock_message) = $this->explainApplicationCapability(
ProjectCanLockProjectsCapability::CAPABILITY,
@@ -221,21 +268,43 @@ final class PhabricatorProjectEditDetailsController
1,
pht('Prevent members from leaving this project.'),
$v_locked)
->setCaption($lock_message))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($edit_uri)
->setValue(pht('Save')));
->setCaption($lock_message));
if ($request->isAjax()) {
$errors = array();
if ($validation_exception) {
$errors = mpull($ex->getErrors(), 'getMessage');
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle($header_name)
->setErrors($errors)
->appendForm($form)
->addSubmitButton($title)
->addCancelButton('/project/');
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$form->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($edit_uri)
->setValue(pht('Save')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setValidationException($validation_exception)
->setForm($form);
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView())
->addTextCrumb($project->getName(), $view_uri)
->addTextCrumb(pht('Edit'), $edit_uri)
->addTextCrumb(pht('Details'));
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
if ($is_new) {
$crumbs->addTextCrumb($title);
} else {
$crumbs
->addTextCrumb($project->getName(), $view_uri)
->addTextCrumb(pht('Edit'), $edit_uri)
->addTextCrumb(pht('Details'));
}
return $this->buildApplicationPage(
array(