2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-17 05:17:52 +01:00
|
|
|
final class PhabricatorProjectEditDetailsController
|
2011-02-21 03:41:23 +01:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2012-10-04 23:33:50 +02:00
|
|
|
private $id;
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-26 17:37:47 +02:00
|
|
|
$this->id = $data['id'];
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
2014-02-10 23:31:34 +01:00
|
|
|
$viewer = $request->getUser();
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setViewer($viewer)
|
2012-08-15 19:44:58 +02:00
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2011-06-26 17:37:47 +02:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
2012-08-15 19:44:58 +02:00
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$project,
|
|
|
|
PhabricatorCustomField::ROLE_EDIT);
|
|
|
|
$field_list
|
|
|
|
->setViewer($viewer)
|
|
|
|
->readFieldsFromStorage($project);
|
|
|
|
|
|
|
|
$view_uri = $this->getApplicationURI('view/'.$project->getID().'/');
|
2014-02-17 05:17:52 +01:00
|
|
|
$edit_uri = $this->getApplicationURI('edit/'.$project->getID().'/');
|
2014-02-10 23:31:34 +01:00
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$e_name = true;
|
2014-02-10 23:31:34 +01:00
|
|
|
$e_edit = null;
|
|
|
|
|
|
|
|
$v_name = $project->getName();
|
|
|
|
|
|
|
|
$validation_exception = null;
|
2012-03-14 20:41:33 +01:00
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
if ($request->isFormPost()) {
|
2014-02-10 23:31:34 +01:00
|
|
|
$e_name = null;
|
|
|
|
|
|
|
|
$v_name = $request->getStr('name');
|
|
|
|
$v_view = $request->getStr('can_view');
|
|
|
|
$v_edit = $request->getStr('can_edit');
|
|
|
|
$v_join = $request->getStr('can_join');
|
|
|
|
|
|
|
|
$xactions = $field_list->buildFieldTransactionsFromRequest(
|
|
|
|
new PhabricatorProjectTransaction(),
|
|
|
|
$request);
|
|
|
|
|
|
|
|
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
|
|
|
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
2014-02-10 23:30:17 +01:00
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setTransactionType($type_name)
|
2014-02-10 23:30:17 +01:00
|
|
|
->setNewValue($request->getStr('name'));
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
2014-02-10 23:31:34 +01:00
|
|
|
->setNewValue($v_view);
|
2014-02-10 23:30:17 +01:00
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setTransactionType($type_edit)
|
|
|
|
->setNewValue($v_edit);
|
2014-02-10 23:30:17 +01:00
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)
|
2014-02-10 23:31:34 +01:00
|
|
|
->setNewValue($v_join);
|
2014-02-10 23:30:17 +01:00
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setActor($viewer)
|
2014-02-10 23:30:17 +01:00
|
|
|
->setContentSourceFromRequest($request)
|
2014-02-10 23:31:34 +01: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 20:58:55 +01:00
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
try {
|
|
|
|
$editor->applyTransactions($project, $xactions);
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2014-02-17 05:17:52 +01:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($edit_uri);
|
2014-02-10 23:31:34 +01:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
|
|
|
|
$e_name = $ex->getShortMessage($type_name);
|
|
|
|
$e_edit = $ex->getShortMessage($type_edit);
|
|
|
|
|
|
|
|
$project->setViewPolicy($v_view);
|
|
|
|
$project->setEditPolicy($v_edit);
|
|
|
|
$project->setJoinPolicy($v_join);
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
$header_name = pht('Edit Project');
|
|
|
|
$title = pht('Edit Project');
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2012-09-13 19:15:08 +02:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setViewer($viewer)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setObject($project)
|
|
|
|
->execute();
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
2014-02-10 23:31:34 +01:00
|
|
|
->setUser($viewer)
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-02-13 18:22:14 +01:00
|
|
|
->setLabel(pht('Name'))
|
2011-02-21 03:41:23 +01:00
|
|
|
->setName('name')
|
2014-02-10 23:31:34 +01:00
|
|
|
->setValue($v_name)
|
2014-02-10 23:31:57 +01:00
|
|
|
->setError($e_name));
|
2014-02-10 23:31:34 +01:00
|
|
|
|
|
|
|
$field_list->appendFieldsToForm($form);
|
|
|
|
|
|
|
|
$form
|
2012-08-15 19:44:58 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setUser($viewer)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setName('can_view')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setUser($viewer)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setName('can_edit')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2014-02-10 23:31:34 +01:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
|
|
|
->setError($e_edit))
|
2012-08-15 19:44:58 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
2014-02-10 23:31:34 +01:00
|
|
|
->setUser($viewer)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setName('can_join')
|
|
|
|
->setCaption(
|
2013-02-13 18:22:14 +01:00
|
|
|
pht('Users who can edit a project can always join a project.'))
|
2012-08-15 19:44:58 +02:00
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_JOIN))
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2014-02-17 05:17:52 +01:00
|
|
|
->addCancelButton($edit_uri)
|
2013-02-13 18:22:14 +01:00
|
|
|
->setValue(pht('Save')));
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText($title)
|
2014-02-10 23:31:34 +01:00
|
|
|
->setValidationException($validation_exception)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
2012-08-07 20:57:38 +02:00
|
|
|
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView())
|
2014-02-10 23:31:34 +01:00
|
|
|
->addTextCrumb($project->getName(), $view_uri)
|
2014-02-17 05:17:52 +01:00
|
|
|
->addTextCrumb(pht('Edit'), $edit_uri)
|
|
|
|
->addTextCrumb(pht('Details'));
|
2013-02-13 18:22:14 +01:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
2013-07-22 18:01:22 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2013-07-22 18:01:22 +02:00
|
|
|
),
|
2011-02-21 03:41:23 +01:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
2013-02-13 18:22:14 +01:00
|
|
|
'device' => true,
|
2011-02-21 03:41:23 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|