1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Consolidate "Subscribers" Herald field value logic

Summary:
Ref T8455. The Herald code in general isn't nearly as modular as it should be, and the subscriber code particularly has some legacy cruft. This is making it fragile and causing the issue described in T8455.

Currently, each Herald adapter has essentially identical code which it uses to determine which users are subscribed to an object. Instead, share code between object types.

I removed "explicitCCs":

  - The value was always identical to doing the query in the common/standard way.
  - They were only used to print a diagnostic message on transcripts, which I think is no longer relevant.
    - I believe it predates transactions, so when it was added you couldn't figure out the old object state by looking at the transaction history. Now, CC changes are recorded there, so there's no need to restate the CC state on the transcript.
    - Even if we do want to restore this (or something similar), we can do it directly from Herald now.

Test Plan:
  - Created rules that use the "CCs" field in Herald, Pholio, Maniphest and Differential.
  - Updated objects in each application.
  - Observed valid field reads in the tranascript.
  - Grepped for `FIELD_CC`.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8455

Differential Revision: https://secure.phabricator.com/D13177
This commit is contained in:
epriestley 2015-06-08 10:18:01 -07:00
parent 2e0f189950
commit 623aaf488d
6 changed files with 14 additions and 38 deletions

View file

@ -1558,9 +1558,6 @@ final class DifferentialTransactionEditor
$object->getPHID(),
PhabricatorObjectHasUnsubscriberEdgeType::EDGECONST);
$subscribed_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$object->getPHID());
$revision = id(new DifferentialRevisionQuery())
->setViewer($this->getActor())
->withPHIDs(array($object->getPHID()))
@ -1579,7 +1576,6 @@ final class DifferentialTransactionEditor
$reviewers = $revision->getReviewerStatus();
$reviewer_phids = mpull($reviewers, 'getReviewerPHID');
$adapter->setExplicitCCs($subscribed_phids);
$adapter->setExplicitReviewers($reviewer_phids);
$adapter->setForbiddenCCs($unsubscribed_phids);

View file

@ -196,6 +196,20 @@ abstract class HeraldAdapter {
return true;
case self::FIELD_IS_NEW_OBJECT:
return $this->getIsNewObject();
case self::FIELD_CC:
$object = $this->getObject();
if (!($object instanceof PhabricatorSubscribableInterface)) {
throw new Exception(
pht(
'Adapter object (of class "%s") does not implement interface '.
'"%s", so the subscribers field value can not be determined.',
get_class($object),
'PhabricatorSubscribableInterface'));
}
$phid = $object->getPHID();
return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid);
case self::FIELD_APPLICATION_EMAIL:
$value = array();
// while there is only one match by implementation, we do set

View file

@ -5,7 +5,6 @@ final class HeraldDifferentialRevisionAdapter
protected $revision;
protected $explicitCCs;
protected $explicitReviewers;
protected $forbiddenCCs;
@ -110,11 +109,6 @@ final class HeraldDifferentialRevisionAdapter
return $object;
}
public function setExplicitCCs($explicit_ccs) {
$this->explicitCCs = $explicit_ccs;
return $this;
}
public function setExplicitReviewers($explicit_reviewers) {
$this->explicitReviewers = $explicit_reviewers;
return $this;
@ -221,12 +215,6 @@ final class HeraldDifferentialRevisionAdapter
return mpull($projects, 'getPHID');
case self::FIELD_DIFF_FILE:
return $this->loadAffectedPaths();
case self::FIELD_CC:
if (isset($this->explicitCCs)) {
return array_keys($this->explicitCCs);
} else {
return $this->revision->getCCPHIDs();
}
case self::FIELD_REVIEWERS:
if (isset($this->explicitReviewers)) {
return array_keys($this->explicitReviewers);
@ -297,19 +285,6 @@ final class HeraldDifferentialRevisionAdapter
assert_instances_of($effects, 'HeraldEffect');
$result = array();
if ($this->explicitCCs) {
$effect = new HeraldEffect();
$effect->setAction(self::ACTION_ADD_CC);
$effect->setTarget(array_keys($this->explicitCCs));
$effect->setReason(
pht(
'CCs provided explicitly by revision author or carried over '.
'from a previous version of the revision.'));
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added addresses to CC list.'));
}
$forbidden_ccs = array_fill_keys(
nonempty($this->forbiddenCCs, array()),

View file

@ -128,9 +128,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
return $this->getTask()->getAuthorPHID();
case self::FIELD_ASSIGNEE:
return $this->getTask()->getOwnerPHID();
case self::FIELD_CC:
return PhabricatorSubscribersQuery::loadSubscribersForPHID(
$this->getTask()->getPHID());
case self::FIELD_PROJECTS:
return PhabricatorEdgeQuery::loadDestinationPHIDs(
$this->getTask()->getPHID(),

View file

@ -101,9 +101,6 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
return $this->getMock()->getDescription();
case self::FIELD_AUTHOR:
return $this->getMock()->getAuthorPHID();
case self::FIELD_CC:
return PhabricatorSubscribersQuery::loadSubscribersForPHID(
$this->getMock()->getPHID());
case self::FIELD_PROJECTS:
return PhabricatorEdgeQuery::loadDestinationPHIDs(
$this->getMock()->getPHID(),

View file

@ -104,9 +104,6 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
return $this->getDocument()->getContent()->getContent();
case self::FIELD_AUTHOR:
return $this->getDocument()->getContent()->getAuthorPHID();
case self::FIELD_CC:
return PhabricatorSubscribersQuery::loadSubscribersForPHID(
$this->getDocument()->getPHID());
case self::FIELD_PATH:
return $this->getDocument()->getContent()->getSlug();
}