Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96122729
RepositoryAuthorPolicyRule.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
Sun, Dec 22, 21:31
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Dec 24, 21:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23127795
Attached To
rPH Phabricator
RepositoryAuthorPolicyRule.php
View Options
<?php
final
class
RepositoryAuthorPolicyRule
extends
PhabricatorPolicyRule
{
public
function
getObjectPolicyKey
()
{
return
'repository.author'
;
}
public
function
getObjectPolicyName
()
{
return
pht
(
'Repository Author'
);
}
public
function
getPolicyExplanation
()
{
return
pht
(
'The author of this repository can take this action.'
);
}
public
function
getRuleDescription
()
{
return
pht
(
'repository author'
);
}
public
function
canApplyToObject
(
PhabricatorPolicyInterface
$object
)
{
//phlog($object);
return
(
$object
instanceof
PhabricatorRepository
||
$object
instanceof
PhabricatorRepositoryCommit
||
$object
instanceof
PhabricatorRepositoryPullEvent
||
$object
instanceof
PhabricatorRepositoryPushEvent
||
$object
instanceof
PhabricatorRepositoryPushLog
||
$object
instanceof
PhabricatorRepositoryRefCursor
||
$object
instanceof
HarbormasterBuildable
||
$object
instanceof
HarbormasterBuild
);
}
public
function
applyRule
(
PhabricatorUser
$viewer
,
$value
,
PhabricatorPolicyInterface
$object
)
{
$viewer_phid
=
$viewer
->
getPHID
();
if
(!
$viewer_phid
)
{
return
false
;
}
// Get repo phid when accessing a commit
if
(
$object
instanceof
PhabricatorRepository
){
$repo_phid
=
$object
->
getPHID
();
}
else
if
(
$object
instanceof
HarbormasterBuildable
)
{
$repo_phid
=
$object
->
getHarbormasterContainerPHID
();
}
else
if
(
$object
instanceof
HarbormasterBuild
)
{
$repo_phid
=
$object
->
getBuildable
()->
getHarbormasterContainerPHID
();
}
else
{
$repo_phid
=
$object
->
getRepository
()->
getPHID
();
}
// If the repository doesn't exist, we allow the user to create it
if
(!
$repo_phid
){
return
true
;
}
// Get all repositories the user has created
$repo_transaction
=
id
(
new
PhabricatorRepositoryTransactionQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withAuthorPHIDs
(
array
(
$viewer_phid
))
->
withObjectPHIDs
(
array
(
$repo_phid
))
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_CREATE
))
->
executeOne
();
if
(!
empty
(
$repo_transaction
))
{
return
true
;
}
return
false
;
}
public
function
getValueControlType
()
{
return
self
::
CONTROL_TYPE_NONE
;
}
}
Event Timeline
Log In to Comment