Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config - add an option to lock policy settings
Summary: Fixes T6947 Test Plan: locked people.create.user and noted the UI only showed a link to the existing policy with no way to edit it. tried to set the config to all the various bad things and saw helpful error messages telling me what I did wrong. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6947 Differential Revision: https://secure.phabricator.com/D11358
- Loading branch information
Showing
4 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
final class PolicyLockOptionType | ||
extends PhabricatorConfigJSONOptionType { | ||
|
||
public function validateOption(PhabricatorConfigOption $option, $value) { | ||
$capabilities = id(new PhutilSymbolLoader()) | ||
->setAncestorClass('PhabricatorPolicyCapability') | ||
->loadObjects(); | ||
$capabilities = mpull($capabilities, null, 'getCapabilityKey'); | ||
|
||
$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)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |