1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Propagate "unexpandable" PHIDs to feed notification recipient expansion

Summary:
See PHI466. Ref T13108. Somewhat recently, new rules were added so that "Resigning" from a revision takes you off the default recipient list, even if you're still a member of a project or package that is still a reviewer or subscriber.

However, these rules don't currently apply to the similar expansion which occurs in notifications. If you resign from a revision you may still get some notifications (just not email) if a package or project you're a member of is a reviewer or subscriber.

(Possibly these should eventually share more code, but just get things working for now.)

Test Plan:
  - Created a revision as A.
  - Added B as a reviewer.
  - Added a package B is an owner for as a reviewer.
  - As B, resigned. (Make sure B is also not an explicit subscriber.)
  - Commented on the revision as A.
    - Before: B is included in the expanded notification recipient list.
    - After: B is no longer included in the expanded notification recipient list.

Maniphest Tasks: T13108

Differential Revision: https://secure.phabricator.com/D19244
This commit is contained in:
epriestley 2018-03-21 11:11:43 -07:00
parent 73b68bc2a6
commit 6ed123e080
2 changed files with 43 additions and 1 deletions

View file

@ -12,6 +12,7 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
private $mailRecipientPHIDs = array(); private $mailRecipientPHIDs = array();
private $notifyAuthor; private $notifyAuthor;
private $mailTags = array(); private $mailTags = array();
private $unexpandablePHIDs = array();
public function setMailTags(array $mail_tags) { public function setMailTags(array $mail_tags) {
$this->mailTags = $mail_tags; $this->mailTags = $mail_tags;
@ -46,6 +47,15 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
return $this; return $this;
} }
public function setUnexpandablePHIDs(array $unexpandable_phids) {
$this->unexpandablePHIDs = $unexpandable_phids;
return $this;
}
public function getUnexpandablePHIDs() {
return $this->unexpandablePHIDs;
}
public function setStoryType($story_type) { public function setStoryType($story_type) {
$this->storyType = $story_type; $this->storyType = $story_type;
return $this; return $this;
@ -254,10 +264,36 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
} }
private function expandRecipients(array $phids) { private function expandRecipients(array $phids) {
return id(new PhabricatorMetaMTAMemberQuery()) $expanded_phids = id(new PhabricatorMetaMTAMemberQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($phids) ->withPHIDs($phids)
->executeExpansion(); ->executeExpansion();
// Filter out unexpandable PHIDs from the results. The typical case for
// this is that resigned reviewers should not be notified just because
// they are a member of some project or package reviewer.
$original_map = array_fuse($phids);
$unexpandable_map = array_fuse($this->unexpandablePHIDs);
foreach ($expanded_phids as $key => $phid) {
// We can keep this expanded PHID if it was present originally.
if (isset($original_map[$phid])) {
continue;
}
// We can also keep it if it isn't marked as unexpandable.
if (!isset($unexpandable_map[$phid])) {
continue;
}
// If it's unexpandable and we produced it by expanding recipients,
// throw it away.
unset($expanded_phids[$key]);
}
$expanded_phids = array_values($expanded_phids);
return $expanded_phids;
} }
/** /**

View file

@ -3199,6 +3199,11 @@ abstract class PhabricatorApplicationTransactionEditor
$story_type = $this->getFeedStoryType(); $story_type = $this->getFeedStoryType();
$story_data = $this->getFeedStoryData($object, $xactions); $story_data = $this->getFeedStoryData($object, $xactions);
$unexpandable_phids = $this->mailUnexpandablePHIDs;
if (!is_array($unexpandable_phids)) {
$unexpandable_phids = array();
}
id(new PhabricatorFeedStoryPublisher()) id(new PhabricatorFeedStoryPublisher())
->setStoryType($story_type) ->setStoryType($story_type)
->setStoryData($story_data) ->setStoryData($story_data)
@ -3207,6 +3212,7 @@ abstract class PhabricatorApplicationTransactionEditor
->setRelatedPHIDs($related_phids) ->setRelatedPHIDs($related_phids)
->setPrimaryObjectPHID($object->getPHID()) ->setPrimaryObjectPHID($object->getPHID())
->setSubscribedPHIDs($subscribed_phids) ->setSubscribedPHIDs($subscribed_phids)
->setUnexpandablePHIDs($unexpandable_phids)
->setMailRecipientPHIDs($mailed_phids) ->setMailRecipientPHIDs($mailed_phids)
->setMailTags($this->getMailTags($object, $xactions)) ->setMailTags($this->getMailTags($object, $xactions))
->publish(); ->publish();