Differential D15063 Diff 36373 src/applications/project/controller/PhabricatorProjectWatchController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectWatchController.php
Show All 12 Lines | $project = id(new PhabricatorProjectQuery()) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->needMembers(true) | ->needMembers(true) | ||||
->needWatchers(true) | ->needWatchers(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$project) { | if (!$project) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$via = $request->getStr('via'); | |||||
if ($via == 'profile') { | |||||
$done_uri = $project->getURI(); | |||||
} else { | |||||
$done_uri = "/project/members/{$id}/"; | $done_uri = "/project/members/{$id}/"; | ||||
// You must be a member of a project to watch it. | |||||
if (!$project->isUserMember($viewer->getPHID())) { | |||||
return new Aphront400Response(); | |||||
} | } | ||||
if ($request->isDialogFormPost()) { | if ($request->isDialogFormPost()) { | ||||
$edge_action = null; | $edge_action = null; | ||||
switch ($action) { | switch ($action) { | ||||
case 'watch': | case 'watch': | ||||
$edge_action = '+'; | $edge_action = '+'; | ||||
$force_subscribe = true; | $force_subscribe = true; | ||||
break; | break; | ||||
case 'unwatch': | case 'unwatch': | ||||
$edge_action = '-'; | $edge_action = '-'; | ||||
$force_subscribe = false; | $force_subscribe = false; | ||||
break; | break; | ||||
} | } | ||||
$type_member = PhabricatorObjectHasWatcherEdgeType::EDGECONST; | $type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST; | ||||
$member_spec = array( | $member_spec = array( | ||||
$edge_action => array($viewer->getPHID() => $viewer->getPHID()), | $edge_action => array($viewer->getPHID() => $viewer->getPHID()), | ||||
); | ); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorProjectTransaction()) | $xactions[] = id(new PhabricatorProjectTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ||||
->setMetadataValue('edge:type', $type_member) | ->setMetadataValue('edge:type', $type_watcher) | ||||
->setNewValue($member_spec); | ->setNewValue($member_spec); | ||||
$editor = id(new PhabricatorProjectTransactionEditor($project)) | $editor = id(new PhabricatorProjectTransactionEditor($project)) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->applyTransactions($project, $xactions); | ->applyTransactions($project, $xactions); | ||||
Show All 19 Lines | switch ($action) { | ||||
$submit = pht('Unwatch Project'); | $submit = pht('Unwatch Project'); | ||||
break; | break; | ||||
default: | default: | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->addHiddenInput('via', $via) | |||||
->appendParagraph($body) | ->appendParagraph($body) | ||||
->addCancelButton($done_uri) | ->addCancelButton($done_uri) | ||||
->addSubmitButton($submit); | ->addSubmitButton($submit); | ||||
} | } | ||||
} | } |