Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F471827
PhabricatorProjectsPolicyRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhabricatorProjectsPolicyRule.php
View Options
<?php
final
class
PhabricatorProjectsPolicyRule
extends
PhabricatorPolicyRule
{
private
$memberships
=
array
();
public
function
getRuleDescription
()
{
return
pht
(
'members of projects'
);
}
public
function
willApplyRules
(
PhabricatorUser
$viewer
,
array
$values
)
{
$values
=
array_unique
(
array_filter
(
array_mergev
(
$values
)));
if
(!
$values
)
{
return
;
}
$projects
=
id
(
new
PhabricatorProjectQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withMemberPHIDs
(
array
(
$viewer
->
getPHID
()))
->
withPHIDs
(
$values
)
->
execute
();
foreach
(
$projects
as
$project
)
{
$this
->
memberships
[
$viewer
->
getPHID
()][
$project
->
getPHID
()]
=
true
;
}
}
public
function
applyRule
(
PhabricatorUser
$viewer
,
$value
)
{
foreach
(
$value
as
$project_phid
)
{
if
(
isset
(
$this
->
memberships
[
$viewer
->
getPHID
()][
$project_phid
]))
{
return
true
;
}
}
return
false
;
}
public
function
getValueControlType
()
{
return
self
::
CONTROL_TYPE_TOKENIZER
;
}
public
function
getValueControlTemplate
()
{
$projects_source
=
new
PhabricatorProjectDatasource
();
return
array
(
'markup'
=>
new
AphrontTokenizerTemplateView
(),
'uri'
=>
$projects_source
->
getDatasourceURI
(),
'placeholder'
=>
$projects_source
->
getPlaceholderText
(),
);
}
public
function
getRuleOrder
()
{
return
200
;
}
public
function
getValueForStorage
(
$value
)
{
PhutilTypeSpec
::
newFromString
(
'list<string>'
)->
check
(
$value
);
return
array_values
(
$value
);
}
public
function
getValueForDisplay
(
PhabricatorUser
$viewer
,
$value
)
{
$handles
=
id
(
new
PhabricatorHandleQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
$value
)
->
execute
();
return
mpull
(
$handles
,
'getFullName'
,
'getPHID'
);
}
public
function
ruleHasEffect
(
$value
)
{
return
(
bool
)
$value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 6, 3:48 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
83181
Default Alt Text
PhabricatorProjectsPolicyRule.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment