Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93680573
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
Sat, Nov 30, 16:21
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Dec 2, 16:21 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22687932
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