2011-02-19 23:36:13 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DifferentialSubscribeController extends DifferentialController {
|
2011-02-19 23:36:13 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2013-07-16 01:01:31 +02:00
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->needRelationships(true)
|
|
|
|
->needReviewerStatus(true)
|
|
|
|
->executeOne();
|
2011-02-19 23:36:13 +01:00
|
|
|
if (!$revision) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$request->isFormPost()) {
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
|
|
|
|
switch ($this->action) {
|
|
|
|
case 'add':
|
2013-01-24 19:46:47 +01:00
|
|
|
$button = pht('Subscribe');
|
|
|
|
$title = pht('Subscribe to Revision');
|
|
|
|
$prompt = pht('Really subscribe to this revision?');
|
2011-02-19 23:36:13 +01:00
|
|
|
break;
|
|
|
|
case 'rem':
|
2013-01-24 19:46:47 +01:00
|
|
|
$button = pht('Unsubscribe');
|
|
|
|
$title = pht('Unsubscribe from Revision');
|
|
|
|
$prompt = pht('Really unsubscribe from this revision? Herald will '.
|
2012-03-26 18:55:38 +02:00
|
|
|
'not resubscribe you to a revision you unsubscribe '.
|
2013-01-24 19:46:47 +01:00
|
|
|
'from.');
|
2011-02-19 23:36:13 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle($title)
|
2013-02-13 23:50:15 +01:00
|
|
|
->appendChild(phutil_tag('p', array(), $prompt))
|
2011-02-19 23:36:13 +01:00
|
|
|
->setSubmitURI($request->getRequestURI())
|
|
|
|
->addSubmitButton($button)
|
|
|
|
->addCancelButton('/D'.$revision->getID());
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
$phid = $user->getPHID();
|
|
|
|
|
|
|
|
switch ($this->action) {
|
|
|
|
case 'add':
|
2011-05-31 23:53:03 +02:00
|
|
|
DifferentialRevisionEditor::addCCAndUpdateRevision(
|
2011-02-19 23:36:13 +01:00
|
|
|
$revision,
|
|
|
|
$phid,
|
2013-02-08 03:13:38 +01:00
|
|
|
$user);
|
2011-02-19 23:36:13 +01:00
|
|
|
break;
|
|
|
|
case 'rem':
|
2011-05-31 23:53:03 +02:00
|
|
|
DifferentialRevisionEditor::removeCCAndUpdateRevision(
|
2011-02-19 23:36:13 +01:00
|
|
|
$revision,
|
2011-05-31 23:53:03 +02:00
|
|
|
$phid,
|
2013-02-08 03:13:38 +01:00
|
|
|
$user);
|
2011-02-19 23:36:13 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/D'.$revision->getID());
|
|
|
|
}
|
|
|
|
}
|