1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-26 13:39:08 +01:00
phorge-phorge/src/applications/project/controller/PhabricatorProjectWatchController.php
epriestley 8463ad2659 Replace subscribe/unsubscribe for projects with explicit mail setting
Summary:
Ref T10054. Ref T6113. Users can currently subscribe to projects, which causes them to receive:

  # mail about project membership changes, description changes, etc; and
  # mail to the project, e.g. when the project is added as a subscriber on a task, or a reviewer on a revision.

Almost no one cares about (1), and after D15061 you can use Herald to get this stuff if you really want it. (It will get progressively more annoying in the future with external membership sources causing automated project membership updates.)

A lot of users are confused about (2) and how it relates to membership, watching, etc, and most users who want (2) don't want (1).

Instead, add an explicit option for this and explain what it does.

This is fairly verbose but I've hidden it on the member/watch screen, which is now the "explain how projects work" screen, I guess.

Test Plan:
{F1064929}

{F1064930}

{F1064931}

  - Disabled/enabled mail for a project.
  - Sent mail to a project with mail disabled, verified I didn't get a copy.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T6113, T10054

Differential Revision: https://secure.phabricator.com/D15065
2016-01-19 19:39:02 -08:00

89 lines
2.6 KiB
PHP

<?php
final class PhabricatorProjectWatchController
extends PhabricatorProjectController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$action = $request->getURIData('action');
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($id))
->needMembers(true)
->needWatchers(true)
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$via = $request->getStr('via');
if ($via == 'profile') {
$done_uri = $project->getURI();
} else {
$done_uri = "/project/members/{$id}/";
}
if ($request->isDialogFormPost()) {
$edge_action = null;
switch ($action) {
case 'watch':
$edge_action = '+';
break;
case 'unwatch':
$edge_action = '-';
break;
}
$type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
$member_spec = array(
$edge_action => array($viewer->getPHID() => $viewer->getPHID()),
);
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $type_watcher)
->setNewValue($member_spec);
$editor = id(new PhabricatorProjectTransactionEditor($project))
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($done_uri);
}
$dialog = null;
switch ($action) {
case 'watch':
$title = pht('Watch Project?');
$body = pht(
'Watching a project will let you monitor it closely. You will '.
'receive email and notifications about changes to every object '.
'associated with projects you watch.');
$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();
}
return $this->newDialog()
->setTitle($title)
->addHiddenInput('via', $via)
->appendParagraph($body)
->addCancelButton($done_uri)
->addSubmitButton($submit);
}
}