diff --git a/src/applications/feed/story/PhabricatorFeedStory.php b/src/applications/feed/story/PhabricatorFeedStory.php index a115985704..0c989d4948 100644 --- a/src/applications/feed/story/PhabricatorFeedStory.php +++ b/src/applications/feed/story/PhabricatorFeedStory.php @@ -453,15 +453,9 @@ abstract class PhabricatorFeedStory * @task policy */ public function getPolicy($capability) { - // If this story's primary object is a policy-aware object, use its policy - // to control story visiblity. - - $primary_phid = $this->getPrimaryObjectPHID(); - if (isset($this->objects[$primary_phid])) { - $object = $this->objects[$primary_phid]; - if ($object instanceof PhabricatorPolicyInterface) { - return $object->getPolicy($capability); - } + $policy_object = $this->getPrimaryPolicyObject(); + if ($policy_object) { + return $policy_object->getPolicy($capability); } // TODO: Remove this once all objects are policy-aware. For now, keep @@ -476,6 +470,11 @@ abstract class PhabricatorFeedStory * @task policy */ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + $policy_object = $this->getPrimaryPolicyObject(); + if ($policy_object) { + return $policy_object->hasAutomaticCapability($capability, $viewer); + } + return false; } @@ -484,6 +483,26 @@ abstract class PhabricatorFeedStory } + /** + * Get the policy object this story is about, if such a policy object + * exists. + * + * @return PhabricatorPolicyInterface|null Policy object, if available. + * @task policy + */ + private function getPrimaryPolicyObject() { + $primary_phid = $this->getPrimaryObjectPHID(); + if (empty($this->objects[$primary_phid])) { + $object = $this->objects[$primary_phid]; + if ($object instanceof PhabricatorPolicyInterface) { + return $object; + } + } + + return null; + } + + /* -( PhabricatorMarkupInterface Implementation )--------------------------- */