Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92629056
RevisionReviewerPolicyRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 05:05
Size
2 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 05:05 (1 d, 17 h)
Engine
blob
Format
Raw Data
Handle
22465274
Attached To
rPH Phabricator
RevisionReviewerPolicyRule.php
View Options
<?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
Log In to Comment