mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-20 03:31:10 +01:00
Validate configuration of maniphest.priorities
Summary: Fixes T6132. We currently allow invalid configuration here; validate it. Test Plan: Tried to save invalid config (negative priorities, string priorities, etc). Reviewers: chad Reviewed By: chad Maniphest Tasks: T6132 Differential Revision: https://secure.phabricator.com/D14689
This commit is contained in:
parent
ec71dcd8e9
commit
20e6a4200d
4 changed files with 46 additions and 2 deletions
|
@ -1277,6 +1277,7 @@ phutil_register_library_map(array(
|
|||
'ManiphestInfoConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestInfoConduitAPIMethod.php',
|
||||
'ManiphestNameIndex' => 'applications/maniphest/storage/ManiphestNameIndex.php',
|
||||
'ManiphestNameIndexEventListener' => 'applications/maniphest/event/ManiphestNameIndexEventListener.php',
|
||||
'ManiphestPriorityConfigOptionType' => 'applications/maniphest/config/ManiphestPriorityConfigOptionType.php',
|
||||
'ManiphestPriorityEmailCommand' => 'applications/maniphest/command/ManiphestPriorityEmailCommand.php',
|
||||
'ManiphestQueryConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestQueryConduitAPIMethod.php',
|
||||
'ManiphestQueryStatusesConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestQueryStatusesConduitAPIMethod.php',
|
||||
|
@ -5258,6 +5259,7 @@ phutil_register_library_map(array(
|
|||
'ManiphestInfoConduitAPIMethod' => 'ManiphestConduitAPIMethod',
|
||||
'ManiphestNameIndex' => 'ManiphestDAO',
|
||||
'ManiphestNameIndexEventListener' => 'PhabricatorEventListener',
|
||||
'ManiphestPriorityConfigOptionType' => 'PhabricatorConfigJSONOptionType',
|
||||
'ManiphestPriorityEmailCommand' => 'ManiphestEmailCommand',
|
||||
'ManiphestQueryConduitAPIMethod' => 'ManiphestConduitAPIMethod',
|
||||
'ManiphestQueryStatusesConduitAPIMethod' => 'ManiphestConduitAPIMethod',
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestPriorityConfigOptionType
|
||||
extends PhabricatorConfigJSONOptionType {
|
||||
|
||||
public function validateOption(PhabricatorConfigOption $option, $value) {
|
||||
ManiphestTaskPriority::validateConfiguration($value);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ final class PhabricatorManiphestConfigOptions
|
|||
}
|
||||
|
||||
public function getOptions() {
|
||||
|
||||
$priority_type = 'custom:ManiphestPriorityConfigOptionType';
|
||||
$priority_defaults = array(
|
||||
100 => array(
|
||||
'name' => pht('Unbreak Now!'),
|
||||
|
@ -267,7 +267,10 @@ EOTEXT
|
|||
$this->newOption('maniphest.fields', $custom_field_type, $default_fields)
|
||||
->setCustomData(id(new ManiphestTask())->getCustomFieldBaseClass())
|
||||
->setDescription(pht('Select and reorder task fields.')),
|
||||
$this->newOption('maniphest.priorities', 'wild', $priority_defaults)
|
||||
$this->newOption(
|
||||
'maniphest.priorities',
|
||||
$priority_type,
|
||||
$priority_defaults)
|
||||
->setSummary(pht('Configure Maniphest priority names.'))
|
||||
->setDescription(
|
||||
pht(
|
||||
|
|
|
@ -116,4 +116,33 @@ final class ManiphestTaskPriority extends ManiphestConstants {
|
|||
return $config;
|
||||
}
|
||||
|
||||
public static function validateConfiguration(array $config) {
|
||||
foreach ($config as $key => $value) {
|
||||
if (!ctype_digit((string)$key)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Key "%s" is not a valid priority constant. Priority constants '.
|
||||
'must be nonnegative integers.',
|
||||
$key));
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Value for key "%s" should be a dictionary.',
|
||||
$key));
|
||||
}
|
||||
|
||||
PhutilTypeSpec::checkMap(
|
||||
$value,
|
||||
array(
|
||||
'name' => 'string',
|
||||
'short' => 'optional string',
|
||||
'color' => 'optional string',
|
||||
'keywords' => 'optional list<string>',
|
||||
'disabled' => 'optional bool',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue