2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorProjectProfileEditController
|
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,
|
|
|
|
))
|
2013-10-07 02:07:20 +02:00
|
|
|
->needProfiles(true)
|
2012-08-15 19:44:58 +02:00
|
|
|
->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
|
|
|
|
2013-10-07 02:07:20 +02:00
|
|
|
$profile = $project->getProfile();
|
2011-06-18 10:13:56 +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().'/');
|
|
|
|
|
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();
|
|
|
|
$v_desc = $profile->getBlurb();
|
|
|
|
|
|
|
|
$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_desc = $request->getStr('blurb');
|
|
|
|
$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-10 23:31:34 +01:00
|
|
|
// TODO: Move this into a custom field.
|
|
|
|
$profile->setBlurb($request->getStr('blurb'));
|
|
|
|
if (!$profile->getProjectPHID()) {
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
}
|
2011-02-21 03:41:23 +01:00
|
|
|
$profile->save();
|
2014-02-10 23:31:34 +01:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
|
|
|
} 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-06-26 17:37:47 +02:00
|
|
|
$action = '/project/edit/'.$project->getID().'/';
|
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
|
2011-07-16 07:30:55 +02:00
|
|
|
->setID('project-edit-form')
|
2014-02-10 23:31:34 +01:00
|
|
|
->setUser($viewer)
|
2011-02-21 03:41:23 +01:00
|
|
|
->setAction($action)
|
|
|
|
->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)
|
2011-02-21 03:41:23 +01:00
|
|
|
->setError($e_name))
|
|
|
|
->appendChild(
|
2013-10-21 20:34:45 +02:00
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setLabel(pht('Description'))
|
2011-02-21 03:41:23 +01:00
|
|
|
->setName('blurb')
|
2014-02-10 23:31:34 +01:00
|
|
|
->setValue($v_desc));
|
|
|
|
|
|
|
|
$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')
|
2013-02-13 18:22:14 +01:00
|
|
|
->setCaption(pht('Members can always view 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_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-10 23:31:34 +01:00
|
|
|
->addCancelButton($view_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)
|
2013-12-19 02:47:34 +01:00
|
|
|
->addTextCrumb(pht('Edit Project'), $this->getApplicationURI());
|
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
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|