2011-02-20 18:41:23 -08:00
|
|
|
<?php
|
|
|
|
|
|
2014-02-16 20:17:52 -08:00
|
|
|
final class PhabricatorProjectEditDetailsController
|
2011-02-20 18:41:23 -08:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
2012-10-04 14:33:50 -07:00
|
|
|
private $id;
|
|
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
public function willProcessRequest(array $data) {
|
2014-10-10 16:57:05 -07:00
|
|
|
$this->id = idx($data, 'id');
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
$request = $this->getRequest();
|
2014-02-10 14:31:34 -08:00
|
|
|
$viewer = $request->getUser();
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
if ($this->id) {
|
2015-01-12 10:04:01 -08:00
|
|
|
$id = $request->getURIData('id');
|
|
|
|
|
$is_new = false;
|
2014-10-10 16:57:05 -07:00
|
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
|
->needSlugs(true)
|
2015-01-12 10:04:01 -08:00
|
|
|
->needImages(true)
|
2014-10-10 16:57:05 -07:00
|
|
|
->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);
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
2012-08-15 10:44:58 -07:00
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
|
$project,
|
|
|
|
|
PhabricatorCustomField::ROLE_EDIT);
|
|
|
|
|
$field_list
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->readFieldsFromStorage($project);
|
|
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
$e_name = true;
|
2014-05-22 11:19:03 -07:00
|
|
|
$e_slugs = false;
|
2014-02-10 14:31:34 -08:00
|
|
|
$e_edit = null;
|
|
|
|
|
|
|
|
|
|
$v_name = $project->getName();
|
2014-05-22 11:19:03 -07:00
|
|
|
$project_slugs = $project->getSlugs();
|
|
|
|
|
$project_slugs = mpull($project_slugs, 'getSlug', 'getSlug');
|
|
|
|
|
$v_primary_slug = $project->getPrimarySlug();
|
|
|
|
|
unset($project_slugs[$v_primary_slug]);
|
|
|
|
|
$v_slugs = $project_slugs;
|
2014-06-26 08:50:01 -07:00
|
|
|
$v_color = $project->getColor();
|
2014-06-26 09:41:07 -07:00
|
|
|
$v_icon = $project->getIcon();
|
2014-09-18 11:00:50 -07:00
|
|
|
$v_locked = $project->getIsMembershipLocked();
|
2014-02-10 14:31:34 -08:00
|
|
|
|
|
|
|
|
$validation_exception = null;
|
2012-03-14 12:41:33 -07:00
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
if ($request->isFormPost()) {
|
2014-02-10 14:31:34 -08:00
|
|
|
$e_name = null;
|
2014-05-22 11:19:03 -07:00
|
|
|
$e_slugs = null;
|
2014-02-10 14:31:34 -08:00
|
|
|
|
|
|
|
|
$v_name = $request->getStr('name');
|
2014-05-22 11:19:03 -07:00
|
|
|
$v_slugs = $request->getStrList('slugs');
|
2014-02-10 14:31:34 -08:00
|
|
|
$v_view = $request->getStr('can_view');
|
|
|
|
|
$v_edit = $request->getStr('can_edit');
|
|
|
|
|
$v_join = $request->getStr('can_join');
|
2014-06-26 08:50:01 -07:00
|
|
|
$v_color = $request->getStr('color');
|
2014-06-26 09:41:07 -07:00
|
|
|
$v_icon = $request->getStr('icon');
|
2014-09-18 11:00:50 -07:00
|
|
|
$v_locked = $request->getInt('is_membership_locked', 0);
|
2014-02-10 14:31:34 -08:00
|
|
|
|
|
|
|
|
$xactions = $field_list->buildFieldTransactionsFromRequest(
|
|
|
|
|
new PhabricatorProjectTransaction(),
|
|
|
|
|
$request);
|
|
|
|
|
|
|
|
|
|
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
|
2014-05-22 11:19:03 -07:00
|
|
|
$type_slugs = PhabricatorProjectTransaction::TYPE_SLUGS;
|
2014-02-10 14:31:34 -08:00
|
|
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
2014-06-26 09:41:07 -07:00
|
|
|
$type_icon = PhabricatorProjectTransaction::TYPE_ICON;
|
2014-06-26 08:50:01 -07:00
|
|
|
$type_color = PhabricatorProjectTransaction::TYPE_COLOR;
|
2014-09-18 11:00:50 -07:00
|
|
|
$type_locked = PhabricatorProjectTransaction::TYPE_LOCKED;
|
2014-02-10 14:30:17 -08:00
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setTransactionType($type_name)
|
2014-05-22 11:19:03 -07:00
|
|
|
->setNewValue($v_name);
|
|
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType($type_slugs)
|
|
|
|
|
->setNewValue($v_slugs);
|
2014-02-10 14:30:17 -08:00
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
2014-02-10 14:31:34 -08:00
|
|
|
->setNewValue($v_view);
|
2014-02-10 14:30:17 -08:00
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setTransactionType($type_edit)
|
|
|
|
|
->setNewValue($v_edit);
|
2014-02-10 14:30:17 -08:00
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)
|
2014-02-10 14:31:34 -08:00
|
|
|
->setNewValue($v_join);
|
2014-02-10 14:30:17 -08:00
|
|
|
|
2014-06-26 09:41:07 -07:00
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType($type_icon)
|
|
|
|
|
->setNewValue($v_icon);
|
|
|
|
|
|
2014-06-26 08:50:01 -07:00
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType($type_color)
|
|
|
|
|
->setNewValue($v_color);
|
|
|
|
|
|
2014-09-18 11:00:50 -07:00
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType($type_locked)
|
|
|
|
|
->setNewValue($v_locked);
|
|
|
|
|
|
2014-02-10 14:30:17 -08:00
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setActor($viewer)
|
2014-02-10 14:30:17 -08:00
|
|
|
->setContentSourceFromRequest($request)
|
2014-02-10 14:31:34 -08:00
|
|
|
->setContinueOnNoEffect(true);
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 11:58:55 -08:00
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
if ($is_new) {
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
|
->setMetadataValue(
|
|
|
|
|
'edge:type',
|
2015-01-02 10:10:58 +11:00
|
|
|
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
|
2014-10-10 16:57:05 -07:00
|
|
|
->setNewValue(
|
|
|
|
|
array(
|
|
|
|
|
'+' => array($viewer->getPHID() => $viewer->getPHID()),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
try {
|
2014-10-10 16:57:05 -07:00
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
$editor->applyTransactions($project, $xactions);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
|
->setContent(array(
|
|
|
|
|
'phid' => $project->getPHID(),
|
|
|
|
|
'name' => $project->getName(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($is_new) {
|
2014-10-14 09:55:52 -07:00
|
|
|
$redirect_uri =
|
2015-01-12 10:04:01 -08:00
|
|
|
$this->getApplicationURI('profile/'.$project->getID().'/');
|
2014-10-10 16:57:05 -07:00
|
|
|
} else {
|
2014-10-14 09:55:52 -07:00
|
|
|
$redirect_uri =
|
|
|
|
|
$this->getApplicationURI('edit/'.$project->getID().'/');
|
2014-10-10 16:57:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($redirect_uri);
|
2014-02-10 14:31:34 -08:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
|
$validation_exception = $ex;
|
|
|
|
|
|
|
|
|
|
$e_name = $ex->getShortMessage($type_name);
|
2014-05-22 11:19:03 -07:00
|
|
|
$e_slugs = $ex->getShortMessage($type_slugs);
|
2014-02-10 14:31:34 -08:00
|
|
|
$e_edit = $ex->getShortMessage($type_edit);
|
|
|
|
|
|
|
|
|
|
$project->setViewPolicy($v_view);
|
|
|
|
|
$project->setEditPolicy($v_edit);
|
|
|
|
|
$project->setJoinPolicy($v_join);
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
if ($is_new) {
|
|
|
|
|
$header_name = pht('Create a New Project');
|
|
|
|
|
$title = pht('Create Project');
|
|
|
|
|
} else {
|
|
|
|
|
$header_name = pht('Edit Project');
|
|
|
|
|
$title = pht('Edit Project');
|
|
|
|
|
}
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2012-09-13 10:15:08 -07:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setViewer($viewer)
|
2012-09-13 10:15:08 -07:00
|
|
|
->setObject($project)
|
|
|
|
|
->execute();
|
2014-05-22 11:19:03 -07:00
|
|
|
$v_slugs = implode(', ', $v_slugs);
|
2012-09-13 10:15:08 -07:00
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
$form = id(new AphrontFormView())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setUser($viewer)
|
2011-02-20 18:41:23 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
2013-02-13 09:22:14 -08:00
|
|
|
->setLabel(pht('Name'))
|
2011-02-20 18:41:23 -08:00
|
|
|
->setName('name')
|
2014-02-10 14:31:34 -08:00
|
|
|
->setValue($v_name)
|
2014-02-10 14:31:57 -08:00
|
|
|
->setError($e_name));
|
2014-02-10 14:31:34 -08:00
|
|
|
$field_list->appendFieldsToForm($form);
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
$shades = PhabricatorProjectIcon::getColorMap();
|
2014-06-26 08:50:01 -07:00
|
|
|
|
2014-10-10 16:57:05 -07:00
|
|
|
if ($is_new) {
|
|
|
|
|
$icon_uri = $this->getApplicationURI('icon/');
|
|
|
|
|
} else {
|
|
|
|
|
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
|
|
|
|
|
}
|
2014-06-26 09:41:07 -07:00
|
|
|
$icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon);
|
2014-09-18 11:00:50 -07:00
|
|
|
list($can_lock, $lock_message) = $this->explainApplicationCapability(
|
|
|
|
|
ProjectCanLockProjectsCapability::CAPABILITY,
|
|
|
|
|
pht('You can update the Lock Project setting.'),
|
|
|
|
|
pht('You can not update the Lock Project setting.'));
|
2014-06-26 09:41:07 -07:00
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
$form
|
2014-06-26 09:41:07 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormChooseButtonControl())
|
|
|
|
|
->setLabel(pht('Icon'))
|
|
|
|
|
->setName('icon')
|
|
|
|
|
->setDisplayValue($icon_display)
|
|
|
|
|
->setButtonText(pht('Choose Icon...'))
|
|
|
|
|
->setChooseURI($icon_uri)
|
|
|
|
|
->setValue($v_icon))
|
2014-06-26 08:50:01 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
|
->setLabel(pht('Color'))
|
|
|
|
|
->setName('color')
|
|
|
|
|
->setValue($v_color)
|
2014-12-10 15:32:54 -08:00
|
|
|
->setOptions($shades));
|
|
|
|
|
|
|
|
|
|
if (!$is_new) {
|
|
|
|
|
$form->appendChild(
|
2014-05-22 11:19:03 -07:00
|
|
|
id(new AphrontFormStaticControl())
|
|
|
|
|
->setLabel(pht('Primary Hashtag'))
|
|
|
|
|
->setCaption(pht('The primary hashtag is derived from the name.'))
|
2014-12-10 15:32:54 -08:00
|
|
|
->setValue($v_primary_slug));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form
|
2014-05-22 11:19:03 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
|
->setLabel(pht('Additional Hashtags'))
|
|
|
|
|
->setCaption(pht(
|
|
|
|
|
'Specify a comma-separated list of additional hashtags.'))
|
|
|
|
|
->setName('slugs')
|
|
|
|
|
->setValue($v_slugs)
|
|
|
|
|
->setError($e_slugs))
|
2012-08-15 10:44:58 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setUser($viewer)
|
2012-08-15 10:44:58 -07:00
|
|
|
->setName('can_view')
|
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 10:15:08 -07:00
|
|
|
->setPolicies($policies)
|
2012-08-15 10:44:58 -07:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setUser($viewer)
|
2012-08-15 10:44:58 -07:00
|
|
|
->setName('can_edit')
|
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 10:15:08 -07:00
|
|
|
->setPolicies($policies)
|
2014-02-10 14:31:34 -08:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
|
|
|
|
->setError($e_edit))
|
2012-08-15 10:44:58 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 14:31:34 -08:00
|
|
|
->setUser($viewer)
|
2012-08-15 10:44:58 -07:00
|
|
|
->setName('can_join')
|
|
|
|
|
->setCaption(
|
2013-02-13 09:22:14 -08:00
|
|
|
pht('Users who can edit a project can always join a project.'))
|
2012-08-15 10:44:58 -07:00
|
|
|
->setPolicyObject($project)
|
2012-09-13 10:15:08 -07:00
|
|
|
->setPolicies($policies)
|
2012-08-15 10:44:58 -07:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_JOIN))
|
2014-09-18 11:00:50 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
|
->setLabel(pht('Lock Project'))
|
|
|
|
|
->setDisabled(!$can_lock)
|
|
|
|
|
->addCheckbox(
|
|
|
|
|
'is_membership_locked',
|
|
|
|
|
1,
|
|
|
|
|
pht('Prevent members from leaving this project.'),
|
|
|
|
|
$v_locked)
|
2014-10-10 16:57:05 -07:00
|
|
|
->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())
|
2014-10-14 09:55:52 -07:00
|
|
|
->addCancelButton($this->getApplicationURI())
|
2014-10-10 16:57:05 -07:00
|
|
|
->setValue(pht('Save')));
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-09-25 11:23:29 -07:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 11:53:11 -07:00
|
|
|
->setHeaderText($title)
|
2014-02-10 14:31:34 -08:00
|
|
|
->setValidationException($validation_exception)
|
2013-08-26 11:53:11 -07:00
|
|
|
->setForm($form);
|
2012-08-07 11:57:38 -07:00
|
|
|
|
2015-01-12 10:04:01 -08:00
|
|
|
if (!$is_new) {
|
|
|
|
|
$nav = $this->buildIconNavView($project);
|
|
|
|
|
$nav->selectFilter("edit/{$id}/");
|
|
|
|
|
$nav->appendChild($form_box);
|
2014-10-10 16:57:05 -07:00
|
|
|
} else {
|
2015-01-12 10:04:01 -08:00
|
|
|
$nav = array($form_box);
|
2014-10-10 16:57:05 -07:00
|
|
|
}
|
2013-02-13 09:22:14 -08:00
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
2013-07-22 09:01:22 -07:00
|
|
|
array(
|
2015-01-12 10:04:01 -08:00
|
|
|
$nav,
|
2013-07-22 09:01:22 -07:00
|
|
|
),
|
2011-02-20 18:41:23 -08:00
|
|
|
array(
|
|
|
|
|
'title' => $title,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|