2013-05-04 00:47:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ManiphestSubscribeController extends ManiphestController {
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$task = id(new ManiphestTask())->load($this->id);
|
|
|
|
if (!$task) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-09-24 15:27:07 +02:00
|
|
|
$ccs = $task->getCCPHIDs();
|
2013-05-04 00:47:39 +02:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'add':
|
2013-09-24 15:27:07 +02:00
|
|
|
$ccs[] = $user->getPHID();
|
2013-05-04 00:47:39 +02:00
|
|
|
break;
|
|
|
|
case 'rem':
|
2013-09-24 15:27:07 +02:00
|
|
|
$ccs = array_diff($ccs, array($user->getPHID()));
|
2013-05-04 00:47:39 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2013-09-24 15:27:07 +02:00
|
|
|
$xaction = id(new ManiphestTransactionPro())
|
|
|
|
->setTransactionType(ManiphestTransactionPro::TYPE_CCS)
|
|
|
|
->setNewValue($ccs);
|
|
|
|
|
|
|
|
$editor = id(new ManiphestTransactionEditorPro())
|
|
|
|
->setActor($user)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->applyTransactions($task, array($xaction));
|
|
|
|
|
2013-05-04 00:47:39 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI('/T'.$task->getID());
|
|
|
|
}
|
|
|
|
}
|