Allow projects to be "watched", sort of a super-subscribe
Summary:
Ref T4967. Adds a "Watch" relationship to projects, which is stronger than member/subscribed.
Specifically, when a task is tagged with a project, we'll include all project watchers in the email/notifications. Normally we don't include projects unless they're explicitly CC'd, or have some other active role in the object (like being a reviewer or auditor).
This allows you to closely follow a project without needing to write a Herald rule for every project you care about.
Test Plan:
- Watched/unwatched a project.
- Tested the watch/subscribe/member relationships:
- Watching implies subscribe.
- Joining implies subscribe.
- Leaving implies unsubscribe + unwatch.
- You can't unsubscribe until you unwatch (slightly better would be unsubscribe implies unwatch, but this is a bit tricky).
- Watched a project, then recevied email about a tagged task without otherwise being involved.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T4967
Differential Revision: https://secure.phabricator.com/D9185
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorProjectWatchController
|
||||
extends PhabricatorProjectController {
|
||||
|
||||
private $id;
|
||||
private $action;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
$this->action = $data['action'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$project = id(new PhabricatorProjectQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($this->id))
|
||||
->needMembers(true)
|
||||
->needWatchers(true)
|
||||
->executeOne();
|
||||
if (!$project) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$project_uri = '/project/view/'.$project->getID().'/';
|
||||
|
||||
// You must be a member of a project to
|
||||
if (!$project->isUserMember($viewer->getPHID())) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
if ($request->isDialogFormPost()) {
|
||||
$edge_action = null;
|
||||
switch ($this->action) {
|
||||
case 'watch':
|
||||
$edge_action = '+';
|
||||
$force_subscribe = true;
|
||||
break;
|
||||
case 'unwatch':
|
||||
$edge_action = '-';
|
||||
$force_subscribe = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$type_member = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_WATCHER;
|
||||
$member_spec = array(
|
||||
$edge_action => array($viewer->getPHID() => $viewer->getPHID()),
|
||||
);
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhabricatorProjectTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
||||
->setMetadataValue('edge:type', $type_member)
|
||||
->setNewValue($member_spec);
|
||||
|
||||
$editor = id(new PhabricatorProjectTransactionEditor($project))
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
->applyTransactions($project, $xactions);
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($project_uri);
|
||||
}
|
||||
|
||||
$dialog = null;
|
||||
switch ($this->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)
|
||||
->appendParagraph($body)
|
||||
->addCancelButton($project_uri)
|
||||
->addSubmitButton($submit);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user