2013-03-15 12:28:43 +01:00
|
|
|
<?php
|
|
|
|
|
2013-07-21 17:42:10 +02:00
|
|
|
final class ReleephRequestActionController extends ReleephProjectController {
|
2013-03-15 12:28:43 +01:00
|
|
|
|
|
|
|
private $action;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
parent::willProcessRequest($data);
|
|
|
|
$this->action = $data['action'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2013-04-08 17:34:21 +02:00
|
|
|
$releeph_project = $this->getReleephProject();
|
2013-03-15 12:28:43 +01:00
|
|
|
$releeph_branch = $this->getReleephBranch();
|
|
|
|
$releeph_request = $this->getReleephRequest();
|
|
|
|
|
|
|
|
$releeph_branch->populateReleephRequestHandles(
|
|
|
|
$request->getUser(), array($releeph_request));
|
|
|
|
|
|
|
|
$action = $this->action;
|
|
|
|
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$origin_uri = $releeph_request->loadReleephBranch()->getURI();
|
|
|
|
|
2013-04-08 17:34:21 +02:00
|
|
|
$editor = id(new ReleephRequestTransactionalEditor())
|
|
|
|
->setActor($user)
|
|
|
|
->setContinueOnNoEffect(true)
|
2013-05-24 19:48:34 +02:00
|
|
|
->setContentSourceFromRequest($request);
|
2013-04-08 17:34:21 +02:00
|
|
|
|
|
|
|
$xactions = array();
|
2013-03-15 12:28:43 +01:00
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'want':
|
|
|
|
case 'pass':
|
|
|
|
static $action_map = array(
|
|
|
|
'want' => ReleephRequest::INTENT_WANT,
|
|
|
|
'pass' => ReleephRequest::INTENT_PASS);
|
|
|
|
$intent = $action_map[$action];
|
2013-04-08 17:34:21 +02:00
|
|
|
$xactions[] = id(new ReleephRequestTransaction())
|
|
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
|
|
|
|
->setMetadataValue(
|
|
|
|
'isAuthoritative',
|
|
|
|
$releeph_project->isAuthoritative($user))
|
|
|
|
->setNewValue($intent);
|
2013-03-15 12:28:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mark-manually-picked':
|
|
|
|
case 'mark-manually-reverted':
|
2013-05-28 17:21:26 +02:00
|
|
|
if (
|
|
|
|
$releeph_request->getRequestUserPHID() === $user->getPHID() ||
|
|
|
|
$releeph_project->isAuthoritative($user)) {
|
|
|
|
|
|
|
|
// We're all good!
|
|
|
|
} else {
|
2013-04-08 17:34:21 +02:00
|
|
|
throw new Exception(
|
2013-05-28 17:21:26 +02:00
|
|
|
"Bug! Only pushers or the requestor can manually change a ".
|
|
|
|
"request's in-branch status!");
|
2013-04-08 17:34:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($action === 'mark-manually-picked') {
|
|
|
|
$in_branch = 1;
|
|
|
|
$intent = ReleephRequest::INTENT_WANT;
|
|
|
|
} else {
|
|
|
|
$in_branch = 0;
|
|
|
|
$intent = ReleephRequest::INTENT_PASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions[] = id(new ReleephRequestTransaction())
|
|
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
|
|
|
|
->setMetadataValue('isManual', true)
|
|
|
|
->setMetadataValue('isAuthoritative', true)
|
|
|
|
->setNewValue($intent);
|
|
|
|
|
|
|
|
$xactions[] = id(new ReleephRequestTransaction())
|
|
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH)
|
|
|
|
->setNewValue($in_branch);
|
|
|
|
|
2013-03-15 12:28:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Exception("unknown or unimplemented action {$action}");
|
|
|
|
}
|
|
|
|
|
2013-04-08 17:34:21 +02:00
|
|
|
$editor->applyTransactions($releeph_request, $xactions);
|
|
|
|
|
2013-03-15 12:28:43 +01:00
|
|
|
// If we're adding a new user to userIntents, we'll have to re-populate
|
|
|
|
// request handles to load that user's data.
|
|
|
|
//
|
|
|
|
// This is cheap enough to do every time.
|
|
|
|
$this->getReleephBranch()->populateReleephRequestHandles(
|
|
|
|
$user, array($releeph_request));
|
|
|
|
|
|
|
|
$list = id(new ReleephRequestHeaderListView())
|
|
|
|
->setReleephProject($this->getReleephProject())
|
|
|
|
->setReleephBranch($this->getReleephBranch())
|
|
|
|
->setReleephRequests(array($releeph_request))
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->setAphrontRequest($this->getRequest())
|
|
|
|
->setOriginType('request');
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(array(
|
|
|
|
'markup' => head($list->renderInner())
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|