1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02: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:
epriestley 2015-12-05 16:35:36 -08:00
parent ec71dcd8e9
commit 20e6a4200d
4 changed files with 46 additions and 2 deletions

View file

@ -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',

View file

@ -0,0 +1,10 @@
<?php
final class ManiphestPriorityConfigOptionType
extends PhabricatorConfigJSONOptionType {
public function validateOption(PhabricatorConfigOption $option, $value) {
ManiphestTaskPriority::validateConfiguration($value);
}
}

View file

@ -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(

View file

@ -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',
));
}
}
}