Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64737347
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
Wed, May 29, 02:16
Size
1 KB
Mime Type
text/x-php
Expires
Fri, May 31, 02:16 (2 d)
Engine
blob
Format
Raw Data
Handle
17951869
Attached To
rPHINFRA c4science
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
);
}
public
function
applyRule
(
PhabricatorUser
$viewer
,
$value
,
PhabricatorPolicyInterface
$object
)
{
$viewer_phid
=
$viewer
->
getPHID
();
if
(!
$viewer_phid
)
{
return
false
;
}
// If the repository doesn't exist, we allow the user to create it
$repo_phid
=
$object
->
getPHID
();
if
(!
$repo_phid
){
return
true
;
}
// Get all repositories the user has created
$repo_transaction
=
id
(
new
PhabricatorRepositoryTransactionQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withAuthorPHIDs
(
array
(
$viewer_phid
))
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_CREATE
))
->
execute
();
// Check if the current repository has been created by the user
if
(!
empty
(
$repo_transaction
))
{
$repo_phids
=
mpull
(
$repo_transaction
,
'getObjectPHID'
);
if
(
in_array
(
$repo_phid
,
$repo_phids
,
true
)
==
true
){
return
true
;
}
}
return
false
;
}
public
function
getValueControlType
()
{
return
self
::
CONTROL_TYPE_NONE
;
}
}
Event Timeline
Log In to Comment