Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2892266
PolicyLockOptionType.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
PolicyLockOptionType.php
View Options
<?php
final
class
PolicyLockOptionType
extends
PhabricatorConfigJSONOptionType
{
public
function
validateOption
(
PhabricatorConfigOption
$option
,
$value
)
{
$capabilities
=
id
(
new
PhutilClassMapQuery
(
)
)
->
setAncestorClass
(
'PhabricatorPolicyCapability'
)
->
setUniqueMethod
(
'getCapabilityKey'
)
->
execute
(
)
;
$policy_phids
=
array
(
)
;
foreach
(
$value
as
$capability_key
=>
$policy
)
{
$capability
=
idx
(
$capabilities
,
$capability_key
)
;
if
(
!
$capability
)
{
throw
new
Exception
(
pht
(
'Capability "%s" does not exist.'
,
$capability_key
)
)
;
}
if
(
phid_get_type
(
$policy
)
!=
PhabricatorPHIDConstants
::
PHID_TYPE_UNKNOWN
)
{
$policy_phids
[
$policy
]
=
$policy
;
}
else
{
try
{
$policy_object
=
PhabricatorPolicyQuery
::
getGlobalPolicy
(
$policy
)
;
// this exception is not helpful here as its about global policy;
// throw a better exception
}
catch
(
Exception
$ex
)
{
throw
new
Exception
(
pht
(
'Capability "%s" has invalid policy "%s".'
,
$capability_key
,
$policy
)
)
;
}
}
if
(
$policy
==
PhabricatorPolicies
::
POLICY_PUBLIC
)
{
if
(
!
$capability
->
shouldAllowPublicPolicySetting
(
)
)
{
throw
new
Exception
(
pht
(
'Capability "%s" does not support public policy.'
,
$capability_key
)
)
;
}
}
}
if
(
$policy_phids
)
{
$handles
=
id
(
new
PhabricatorHandleQuery
(
)
)
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
(
)
)
->
withPhids
(
$policy_phids
)
->
execute
(
)
;
$handles
=
mpull
(
$handles
,
null
,
'getPHID'
)
;
foreach
(
$value
as
$capability_key
=>
$policy
)
{
$handle
=
$handles
[
$policy
]
;
if
(
!
$handle
->
isComplete
(
)
)
{
throw
new
Exception
(
pht
(
'Capability "%s" has invalid policy "%s"; "%s" does not exist.'
,
$capability_key
,
$policy
,
$policy
)
)
;
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 16:31 (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1126503
Default Alt Text
PolicyLockOptionType.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment