2014-05-19 21:40:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectWatchController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2015-08-08 19:34:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
$action = $request->getURIData('action');
|
2014-05-19 21:40:57 +02:00
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
2015-08-08 19:34:55 +02:00
|
|
|
->withIDs(array($id))
|
2014-05-19 21:40:57 +02:00
|
|
|
->needMembers(true)
|
|
|
|
->needWatchers(true)
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:14 +01:00
|
|
|
$via = $request->getStr('via');
|
|
|
|
if ($via == 'profile') {
|
2016-01-23 02:26:46 +01:00
|
|
|
$done_uri = "/project/profile/{$id}/";
|
2016-01-20 02:43:14 +01:00
|
|
|
} else {
|
|
|
|
$done_uri = "/project/members/{$id}/";
|
2014-05-19 21:40:57 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 19:11:12 +01:00
|
|
|
$is_watcher = $project->isUserWatcher($viewer->getPHID());
|
|
|
|
$is_ancestor = $project->isUserAncestorWatcher($viewer->getPHID());
|
|
|
|
if ($is_ancestor && !$is_watcher) {
|
|
|
|
$ancestor_phid = $project->getWatchedAncestorPHID($viewer->getPHID());
|
|
|
|
$handles = $viewer->loadHandles(array($ancestor_phid));
|
|
|
|
$ancestor_handle = $handles[$ancestor_phid];
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Watching Ancestor'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'You are already watching %s, an ancestor of this project, and '.
|
|
|
|
'are thus watching all of its subprojects.',
|
|
|
|
$ancestor_handle->renderTag()->render()))
|
|
|
|
->addCancelbutton($done_uri);
|
|
|
|
}
|
|
|
|
|
2014-05-19 21:40:57 +02:00
|
|
|
if ($request->isDialogFormPost()) {
|
|
|
|
$edge_action = null;
|
2015-08-08 19:34:55 +02:00
|
|
|
switch ($action) {
|
2014-05-19 21:40:57 +02:00
|
|
|
case 'watch':
|
|
|
|
$edge_action = '+';
|
|
|
|
break;
|
|
|
|
case 'unwatch':
|
|
|
|
$edge_action = '-';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:14 +01:00
|
|
|
$type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
2014-05-19 21:40:57 +02:00
|
|
|
$member_spec = array(
|
|
|
|
$edge_action => array($viewer->getPHID() => $viewer->getPHID()),
|
|
|
|
);
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
2016-01-20 02:43:14 +01:00
|
|
|
->setMetadataValue('edge:type', $type_watcher)
|
2014-05-19 21:40:57 +02:00
|
|
|
->setNewValue($member_spec);
|
|
|
|
|
2017-02-17 11:10:15 +01:00
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
2014-05-19 21:40:57 +02:00
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->applyTransactions($project, $xactions);
|
|
|
|
|
2016-01-20 01:27:36 +01:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($done_uri);
|
2014-05-19 21:40:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = null;
|
2015-08-08 19:34:55 +02:00
|
|
|
switch ($action) {
|
2014-05-19 21:40:57 +02:00
|
|
|
case 'watch':
|
|
|
|
$title = pht('Watch Project?');
|
2016-02-16 19:11:12 +01:00
|
|
|
$body = array();
|
|
|
|
$body[] = pht(
|
2014-05-19 21:40:57 +02:00
|
|
|
'Watching a project will let you monitor it closely. You will '.
|
|
|
|
'receive email and notifications about changes to every object '.
|
2016-02-16 19:11:12 +01:00
|
|
|
'tagged with projects you watch.');
|
|
|
|
$body[] = pht(
|
|
|
|
'Watching a project also watches all subprojects and milestones of '.
|
|
|
|
'that project.');
|
2014-05-19 21:40:57 +02:00
|
|
|
$submit = pht('Watch Project');
|
|
|
|
break;
|
|
|
|
case 'unwatch':
|
|
|
|
$title = pht('Unwatch Project?');
|
|
|
|
$body = pht(
|
|
|
|
'You will no longer receive email or notifications about every '.
|
|
|
|
'object associated with this project.');
|
|
|
|
$submit = pht('Unwatch Project');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-02-16 19:11:12 +01:00
|
|
|
$dialog = $this->newDialog()
|
2014-05-19 21:40:57 +02:00
|
|
|
->setTitle($title)
|
2016-01-20 02:43:14 +01:00
|
|
|
->addHiddenInput('via', $via)
|
2016-01-20 01:27:36 +01:00
|
|
|
->addCancelButton($done_uri)
|
2014-05-19 21:40:57 +02:00
|
|
|
->addSubmitButton($submit);
|
2016-02-16 19:11:12 +01:00
|
|
|
|
|
|
|
foreach ((array)$body as $paragraph) {
|
|
|
|
$dialog->appendParagraph($paragraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dialog;
|
2014-05-19 21:40:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|