Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80790903
PolicyLockOptionType.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
Mon, Sep 2, 14:56
Size
2 KB
Mime Type
text/x-php
Expires
Wed, Sep 4, 14:56 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20400737
Attached To
rPH Phabricator
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
));
}
}
}
}
}
Event Timeline
Log In to Comment