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();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->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
|
|
|
$options = PhabricatorProjectStatus::getStatusMap();
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$e_name = true;
|
2012-03-14 20:41:33 +01:00
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
2014-02-10 23:30:17 +01:00
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME)
|
|
|
|
->setNewValue($request->getStr('name'));
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorProjectTransaction::TYPE_STATUS)
|
|
|
|
->setNewValue($request->getStr('status'));
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
|
|
|
->setNewValue($request->getStr('can_view'));
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
|
|
|
->setNewValue($request->getStr('can_edit'));
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)
|
|
|
|
->setNewValue($request->getStr('can_join'));
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
|
|
|
->setActor($user)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->applyTransactions($project, $xactions);
|
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
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$profile->setBlurb($request->getStr('blurb'));
|
|
|
|
|
|
|
|
if (!strlen($project->getName())) {
|
2013-02-13 18:22:14 +01:00
|
|
|
$e_name = pht('Required');
|
|
|
|
$errors[] = pht('Project name is required.');
|
2011-02-21 03:41:23 +01:00
|
|
|
} else {
|
|
|
|
$e_name = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$project->save();
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
$profile->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
->setViewer($user)
|
|
|
|
->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')
|
2011-02-21 03:41:23 +01:00
|
|
|
->setUser($user)
|
|
|
|
->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')
|
|
|
|
->setValue($project->getName())
|
|
|
|
->setError($e_name))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
2013-02-13 18:22:14 +01:00
|
|
|
->setLabel(pht('Project Status'))
|
2011-06-18 10:13:56 +02:00
|
|
|
->setName('status')
|
|
|
|
->setOptions($options)
|
|
|
|
->setValue($project->getStatus()))
|
2011-02-21 03:41:23 +01:00
|
|
|
->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')
|
|
|
|
->setValue($profile->getBlurb()))
|
2012-08-15 19:44:58 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->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())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('can_edit')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->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())
|
2011-06-18 10:13:56 +02:00
|
|
|
->addCancelButton('/project/view/'.$project->getID().'/')
|
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-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
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())
|
|
|
|
->addTextCrumb(
|
|
|
|
$project->getName(),
|
|
|
|
'/project/view/'.$project->getID().'/')
|
|
|
|
->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
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|