Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93136272
PhabricatorPolicyRuleProjects.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
Tue, Nov 26, 11:48
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Nov 28, 11:48 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22579166
Attached To
rPH Phabricator
PhabricatorPolicyRuleProjects.php
View Options
<?php
final
class
PhabricatorPolicyRuleProjects
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
(
$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
()
{
return
array
(
'markup'
=>
new
AphrontTokenizerTemplateView
(),
'uri'
=>
'/typeahead/common/projects/'
,
'placeholder'
=>
pht
(
'Type a project name...'
),
);
}
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
;
}
}
Event Timeline
Log In to Comment