Page MenuHomec4science

RevisionReviewerPolicyRule.php
No OneTemporary

File Metadata

Created
Wed, Nov 27, 18:45

RevisionReviewerPolicyRule.php

<?php
final class RevisionReviewerPolicyRule
extends PhabricatorPolicyRule {
public function getObjectPolicyKey() {
return 'revision.reviewer';
}
public function getObjectPolicyName() {
return pht('Revision Reviewer');
}
public function getPolicyExplanation() {
return pht('The reviewer of this revision can take this action.');
}
public function getRuleDescription() {
return pht('revision reviewer');
}
public function canApplyToObject(PhabricatorPolicyInterface $object) {
return (
$object instanceof DifferentialRevision
|| $object instanceof DifferentialDiff
);
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
return false;
}
// Get revision phid
if($object instanceof DifferentialRevision){
$rev_phid = $object->getPHID();
} else if($object instanceof DifferentialDiff) {
$diff_phid = $object->getPHID();
$diff = id(new DifferentialDiffQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($diff_phid))
->executeOne();
if($diff && $diff->hasRevision()){
$rev_phid = $diff->getRevision()->getPHID();
} else {
return false;
}
}
// Get the revision reviewer
$rev = id(new DifferentialRevisionQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($rev_phid))
->needReviewers(true)
->executeOne();
// Allow the reviewers
if($rev){
$reviewers = $rev->getReviewers();
if(in_array($viewer_phid, $reviewers)){
return true;
} else {
// Check group reviewer
$projects = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withMemberPHIDs(array($viewer_phid))
->execute();
if($projects) {
$proj_phids = mpull($projects, 'getPHID');
foreach($reviewers as $rev){
if(in_array($rev, $proj_phids)){
return true;
}
}
}
}
}
return false;
}
public function getValueControlType() {
return self::CONTROL_TYPE_NONE;
}
}

Event Timeline