Use extended policies in Differential diffs
Summary: Fixes T9648. Diffs currently use `return $this->getRevision()->getViewPolicy();` to inherit their revision's view policy. After the introduction of object policies, this is wrong for policies like "Subscribers", because it means "Subscribers to this object, the diff". Since Diffs have no subscribers, this always fails. Instead, use extended policies so that the object policy evaluates in the context of the correct object (the revision). Test Plan: - Create a revision. - Subscribe `alice` to it. - Set view policy to "Subscribers". - View revision as `alice`. - Before patch: nonsense fatal about missing diff because of policy error. - After patch: `alice` can see the revision. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9648 Differential Revision: https://secure.phabricator.com/D17123
This commit is contained in:
@@ -5058,6 +5058,7 @@ phutil_register_library_map(array(
|
|||||||
'DifferentialDiff' => array(
|
'DifferentialDiff' => array(
|
||||||
'DifferentialDAO',
|
'DifferentialDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
'PhabricatorExtendedPolicyInterface',
|
||||||
'HarbormasterBuildableInterface',
|
'HarbormasterBuildableInterface',
|
||||||
'HarbormasterCircleCIBuildableInterface',
|
'HarbormasterCircleCIBuildableInterface',
|
||||||
'PhabricatorApplicationTransactionInterface',
|
'PhabricatorApplicationTransactionInterface',
|
||||||
|
|||||||
@@ -16,18 +16,17 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||||||
|
|
||||||
$revision = id(new DifferentialRevisionQuery())
|
$revision = id(new DifferentialRevisionQuery())
|
||||||
->withIDs(array($this->revisionID))
|
->withIDs(array($this->revisionID))
|
||||||
->setViewer($request->getUser())
|
->setViewer($viewer)
|
||||||
->needRelationships(true)
|
->needRelationships(true)
|
||||||
->needReviewerStatus(true)
|
->needReviewerStatus(true)
|
||||||
->needReviewerAuthority(true)
|
->needReviewerAuthority(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$revision) {
|
if (!$revision) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$diffs = id(new DifferentialDiffQuery())
|
$diffs = id(new DifferentialDiffQuery())
|
||||||
->setViewer($request->getUser())
|
->setViewer($viewer)
|
||||||
->withRevisionIDs(array($this->revisionID))
|
->withRevisionIDs(array($this->revisionID))
|
||||||
->execute();
|
->execute();
|
||||||
$diffs = array_reverse($diffs, $preserve_keys = true);
|
$diffs = array_reverse($diffs, $preserve_keys = true);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ final class DifferentialDiff
|
|||||||
extends DifferentialDAO
|
extends DifferentialDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorPolicyInterface,
|
PhabricatorPolicyInterface,
|
||||||
|
PhabricatorExtendedPolicyInterface,
|
||||||
HarbormasterBuildableInterface,
|
HarbormasterBuildableInterface,
|
||||||
HarbormasterCircleCIBuildableInterface,
|
HarbormasterCircleCIBuildableInterface,
|
||||||
PhabricatorApplicationTransactionInterface,
|
PhabricatorApplicationTransactionInterface,
|
||||||
@@ -429,7 +430,7 @@ final class DifferentialDiff
|
|||||||
|
|
||||||
public function getPolicy($capability) {
|
public function getPolicy($capability) {
|
||||||
if ($this->hasRevision()) {
|
if ($this->hasRevision()) {
|
||||||
return $this->getRevision()->getPolicy($capability);
|
return PhabricatorPolicies::getMostOpenPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->viewPolicy;
|
return $this->viewPolicy;
|
||||||
@@ -440,7 +441,7 @@ final class DifferentialDiff
|
|||||||
return $this->getRevision()->hasAutomaticCapability($capability, $viewer);
|
return $this->getRevision()->hasAutomaticCapability($capability, $viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($this->getAuthorPHID() == $viewer->getPhid());
|
return ($this->getAuthorPHID() == $viewer->getPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function describeAutomaticCapability($capability) {
|
public function describeAutomaticCapability($capability) {
|
||||||
@@ -448,10 +449,31 @@ final class DifferentialDiff
|
|||||||
return pht(
|
return pht(
|
||||||
'This diff is attached to a revision, and inherits its policies.');
|
'This diff is attached to a revision, and inherits its policies.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return pht('The author of a diff can see it.');
|
return pht('The author of a diff can see it.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
|
||||||
|
$extended = array();
|
||||||
|
|
||||||
|
switch ($capability) {
|
||||||
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
if ($this->hasRevision()) {
|
||||||
|
$extended[] = array(
|
||||||
|
$this->getRevision(),
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $extended;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( HarbormasterBuildableInterface )------------------------------------- */
|
/* -( HarbormasterBuildableInterface )------------------------------------- */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user