2012-01-25 20:51:20 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorProjectUpdateController
|
2012-01-25 20:51:20 +01:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
private $action;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
$this->action = $data['action'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$capabilities = array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
2012-01-25 20:51:20 +01:00
|
|
|
|
|
|
|
$process_action = false;
|
|
|
|
switch ($this->action) {
|
|
|
|
case 'join':
|
2012-08-15 19:44:58 +02:00
|
|
|
$capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
|
2012-01-25 20:51:20 +01:00
|
|
|
$process_action = $request->isFormPost();
|
|
|
|
break;
|
|
|
|
case 'leave':
|
|
|
|
$process_action = $request->isDialogFormPost();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->needMembers(true)
|
|
|
|
->requireCapabilities($capabilities)
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-01-25 20:51:20 +01:00
|
|
|
$project_uri = '/project/view/'.$project->getID().'/';
|
|
|
|
|
|
|
|
if ($process_action) {
|
2014-02-10 23:30:00 +01:00
|
|
|
|
|
|
|
$edge_action = null;
|
2012-01-25 20:51:20 +01:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'join':
|
2014-02-10 23:30:00 +01:00
|
|
|
$edge_action = '+';
|
2012-01-25 20:51:20 +01:00
|
|
|
break;
|
|
|
|
case 'leave':
|
2014-02-10 23:30:00 +01:00
|
|
|
$edge_action = '-';
|
2012-01-25 20:51:20 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 23:30:00 +01:00
|
|
|
|
|
|
|
$type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
|
|
|
|
$member_spec = array(
|
|
|
|
$edge_action => array($user->getPHID() => $user->getPHID()),
|
|
|
|
);
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $type_member)
|
|
|
|
->setNewValue($member_spec);
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor($project))
|
|
|
|
->setActor($user)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->applyTransactions($project, $xactions);
|
|
|
|
|
2012-01-25 20:51:20 +01:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($project_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = null;
|
|
|
|
switch ($this->action) {
|
|
|
|
case 'leave':
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setUser($user);
|
2013-02-13 18:22:14 +01:00
|
|
|
$dialog->setTitle(pht('Really leave project?'));
|
2013-02-13 23:50:15 +01:00
|
|
|
$dialog->appendChild(phutil_tag('p', array(), pht(
|
|
|
|
'Your tremendous contributions to this project will be sorely '.
|
|
|
|
'missed. Are you sure you want to leave?')));
|
2012-01-25 20:51:20 +01:00
|
|
|
$dialog->addCancelButton($project_uri);
|
2013-02-13 18:22:14 +01:00
|
|
|
$dialog->addSubmitButton(pht('Leave Project'));
|
2012-01-25 20:51:20 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|