Make subproject/milestone watch rules work better

Summary:
Ref T10349. These got sort of half-weirded-up before I separated subscriptions and watching fully. New rules are:

  - You can watch whatever you want.
  - Watching a parent watches everything inside it.
  - If you're watching "Stonework" and go to "Stonework > Masonry", you'll see a "Watching Ancestor" hint to let you know you're already watching a parent or ancestor.

Test Plan:
  - Watched and unwatched "Stonework".
  - Watched and unwatched "Stonework > Iteration IV".
  - While watching "Stonework", visited "Iteration IV" and saw "Watching Ancestor" hint.
  - Created a task tagged "Stonework > Iteration IV". Got notified about it because I watch "Stonework".

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10349

Differential Revision: https://secure.phabricator.com/D15280
This commit is contained in:
epriestley
2016-02-16 10:11:12 -08:00
parent 0e5cd478c4
commit 376c85a828
6 changed files with 111 additions and 37 deletions

View File

@@ -162,19 +162,32 @@ final class PhabricatorProjectProfileController
private function renderWatchAction(PhabricatorProject $project) {
$viewer = $this->getViewer();
$viewer_phid = $viewer->getPHID();
$id = $project->getID();
$is_watcher = ($viewer_phid && $project->isUserWatcher($viewer_phid));
if (!$viewer->isLoggedIn()) {
$is_watcher = false;
$is_ancestor = false;
} else {
$viewer_phid = $viewer->getPHID();
$is_watcher = $project->isUserWatcher($viewer_phid);
$is_ancestor = $project->isUserAncestorWatcher($viewer_phid);
}
if (!$is_watcher) {
if ($is_ancestor && !$is_watcher) {
$watch_icon = 'fa-eye';
$watch_text = pht('Watching Ancestor');
$watch_href = "/project/watch/{$id}/?via=profile";
$watch_disabled = true;
} else if (!$is_watcher) {
$watch_icon = 'fa-eye';
$watch_text = pht('Watch Project');
$watch_href = "/project/watch/{$id}/?via=profile";
$watch_disabled = false;
} else {
$watch_icon = 'fa-eye-slash';
$watch_text = pht('Unwatch Project');
$watch_href = "/project/unwatch/{$id}/?via=profile";
$watch_disabled = false;
}
$watch_icon = id(new PHUIIconView())
@@ -185,7 +198,8 @@ final class PhabricatorProjectProfileController
->setWorkflow(true)
->setIcon($watch_icon)
->setText($watch_text)
->setHref($watch_href);
->setHref($watch_href)
->setDisabled($watch_disabled);
}
private function buildMilestoneList(PhabricatorProject $project) {

View File

@@ -25,6 +25,23 @@ final class PhabricatorProjectWatchController
$done_uri = "/project/members/{$id}/";
}
$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);
}
if ($request->isDialogFormPost()) {
$edge_action = null;
switch ($action) {
@@ -61,10 +78,14 @@ final class PhabricatorProjectWatchController
switch ($action) {
case 'watch':
$title = pht('Watch Project?');
$body = pht(
$body = array();
$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.');
'tagged with projects you watch.');
$body[] = pht(
'Watching a project also watches all subprojects and milestones of '.
'that project.');
$submit = pht('Watch Project');
break;
case 'unwatch':
@@ -78,12 +99,17 @@ final class PhabricatorProjectWatchController
return new Aphront404Response();
}
return $this->newDialog()
$dialog = $this->newDialog()
->setTitle($title)
->addHiddenInput('via', $via)
->appendParagraph($body)
->addCancelButton($done_uri)
->addSubmitButton($submit);
foreach ((array)$body as $paragraph) {
$dialog->appendParagraph($paragraph);
}
return $dialog;
}
}