2012-01-25 11:51:20 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorProjectUpdateController
|
2012-01-25 11:51:20 -08:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2015-08-08 10:34:55 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
$action = $request->getURIData('action');
|
2012-01-25 11:51:20 -08:00
|
|
|
|
2012-08-15 10:44:58 -07:00
|
|
|
$capabilities = array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
2012-01-25 11:51:20 -08:00
|
|
|
|
2015-08-08 10:34:55 -07:00
|
|
|
switch ($action) {
|
2012-01-25 11:51:20 -08:00
|
|
|
case 'join':
|
2012-08-15 10:44:58 -07:00
|
|
|
$capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
|
2012-01-25 11:51:20 -08:00
|
|
|
break;
|
|
|
|
case 'leave':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-08-15 10:44:58 -07:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
2015-08-08 10:34:55 -07:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2012-08-15 10:44:58 -07:00
|
|
|
->needMembers(true)
|
|
|
|
->requireCapabilities($capabilities)
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-06-01 12:33:26 -07:00
|
|
|
$done_uri = "/project/members/{$id}/";
|
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
if (!$project->supportsEditMembers()) {
|
2016-06-01 12:33:26 -07:00
|
|
|
$copy = pht('Parent projects and milestones do not support adding '.
|
|
|
|
'members. You can add members directly to any non-parent subproject.');
|
2012-01-25 11:51:20 -08:00
|
|
|
|
2016-06-01 12:33:26 -07:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Unsupported Project'))
|
|
|
|
->appendParagraph($copy)
|
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
2014-02-10 14:30:00 -08:00
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
if ($request->isFormPost()) {
|
2014-02-10 14:30:00 -08:00
|
|
|
$edge_action = null;
|
2015-08-08 10:34:55 -07:00
|
|
|
switch ($action) {
|
2012-01-25 11:51:20 -08:00
|
|
|
case 'join':
|
2014-02-10 14:30:00 -08:00
|
|
|
$edge_action = '+';
|
2012-01-25 11:51:20 -08:00
|
|
|
break;
|
|
|
|
case 'leave':
|
2014-02-10 14:30:00 -08:00
|
|
|
$edge_action = '-';
|
2012-01-25 11:51:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 14:30:00 -08:00
|
|
|
|
2015-01-02 10:10:58 +11:00
|
|
|
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
|
2016-01-19 16:27:36 -08:00
|
|
|
|
2014-02-10 14:30:00 -08:00
|
|
|
$member_spec = array(
|
2015-08-08 10:34:55 -07:00
|
|
|
$edge_action => array($viewer->getPHID() => $viewer->getPHID()),
|
2014-02-10 14:30:00 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $type_member)
|
|
|
|
->setNewValue($member_spec);
|
|
|
|
|
2017-02-17 10:10:15 +00:00
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
2015-08-08 10:34:55 -07:00
|
|
|
->setActor($viewer)
|
2014-02-10 14:30:00 -08:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->applyTransactions($project, $xactions);
|
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($done_uri);
|
2012-01-25 11:51:20 -08:00
|
|
|
}
|
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
$is_locked = $project->getIsMembershipLocked();
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
$can_leave = ($can_edit || !$is_locked);
|
|
|
|
|
|
|
|
$button = null;
|
|
|
|
if ($action == 'leave') {
|
|
|
|
if ($can_leave) {
|
|
|
|
$title = pht('Leave Project');
|
|
|
|
$body = pht(
|
|
|
|
'Your tremendous contributions to this project will be sorely '.
|
|
|
|
'missed. Are you sure you want to leave?');
|
|
|
|
$button = pht('Leave Project');
|
|
|
|
} else {
|
|
|
|
$title = pht('Membership Locked');
|
|
|
|
$body = pht(
|
|
|
|
'Membership for this project is locked. You can not leave.');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$title = pht('Join Project');
|
|
|
|
$body = pht(
|
|
|
|
'Join this project? You will become a member and enjoy whatever '.
|
|
|
|
'benefits membership may confer.');
|
|
|
|
$button = pht('Join Project');
|
2012-01-25 11:51:20 -08:00
|
|
|
}
|
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
$dialog = $this->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->appendParagraph($body)
|
|
|
|
->addCancelButton($done_uri);
|
2012-01-25 11:51:20 -08:00
|
|
|
|
2016-01-19 16:27:36 -08:00
|
|
|
if ($button) {
|
|
|
|
$dialog->addSubmitButton($button);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dialog;
|
2014-09-18 11:00:50 -07:00
|
|
|
}
|
2016-01-19 16:27:36 -08:00
|
|
|
|
2012-01-25 11:51:20 -08:00
|
|
|
}
|