Page MenuHomec4science

RevisionAuthorPolicyRule.php
No OneTemporary

File Metadata

Created
Sat, Nov 23, 13:36

RevisionAuthorPolicyRule.php

<?php
final class RevisionAuthorPolicyRule
extends PhabricatorPolicyRule {
public function getObjectPolicyKey() {
return 'revision.author';
}
public function getObjectPolicyName() {
return pht('Revision Author');
}
public function getPolicyExplanation() {
return pht('The author of this revision can take this action.');
}
public function getRuleDescription() {
return pht('revision author');
}
public function canApplyToObject(PhabricatorPolicyInterface $object) {
return ($object instanceof DifferentialRevision);
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
return false;
}
// Get the revision author
$rev = id(new DifferentialRevisionQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($object->getPHID()))
->executeOne();
// Allow the author
if($rev && $rev->getAuthorPHID() === $viewer->getPHID()){
return true;
}
return false;
}
public function getValueControlType() {
return self::CONTROL_TYPE_NONE;
}
}

Event Timeline