From 623aaf488dc38689d95ca33269d5069d68a65f78 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 8 Jun 2015 10:18:01 -0700 Subject: [PATCH] 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 --- .../editor/DifferentialTransactionEditor.php | 4 --- .../herald/adapter/HeraldAdapter.php | 14 +++++++++++ .../HeraldDifferentialRevisionAdapter.php | 25 ------------------- .../adapter/HeraldManiphestTaskAdapter.php | 3 --- .../adapter/HeraldPholioMockAdapter.php | 3 --- .../herald/PhrictionDocumentHeraldAdapter.php | 3 --- 6 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php index ffd1d647e4..af9000fd80 100644 --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -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); diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index f494ad95fc..702c477300 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -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 diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index e7ba56cf06..76fffac1b4 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -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()), diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index cb4c7988c0..4f7510199c 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -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(), diff --git a/src/applications/herald/adapter/HeraldPholioMockAdapter.php b/src/applications/herald/adapter/HeraldPholioMockAdapter.php index 0b73b6cfc2..1b156c1751 100644 --- a/src/applications/herald/adapter/HeraldPholioMockAdapter.php +++ b/src/applications/herald/adapter/HeraldPholioMockAdapter.php @@ -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(), diff --git a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php index 8b6d36edf6..3e4fcaaed6 100644 --- a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php +++ b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php @@ -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(); }