Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/constants/ManiphestTaskPriority.php
<?php | <?php | ||||
final class ManiphestTaskPriority extends ManiphestConstants { | final class ManiphestTaskPriority extends ManiphestConstants { | ||||
const UNKNOWN_PRIORITY_KEYWORD = '!!unknown!!'; | |||||
/** | /** | ||||
* Get the priorities and their full descriptions. | * Get the priorities and their full descriptions. | ||||
* | * | ||||
* @return map Priorities to descriptions. | * @return map Priorities to descriptions. | ||||
*/ | */ | ||||
public static function getTaskPriorityMap() { | public static function getTaskPriorityMap() { | ||||
$map = self::getConfig(); | $map = self::getConfig(); | ||||
foreach ($map as $key => $spec) { | foreach ($map as $key => $spec) { | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | final class ManiphestTaskPriority extends ManiphestConstants { | ||||
public static function getTaskPriorityColor($priority) { | public static function getTaskPriorityColor($priority) { | ||||
return idx(self::getColorMap(), $priority, 'black'); | return idx(self::getColorMap(), $priority, 'black'); | ||||
} | } | ||||
public static function getTaskPriorityIcon($priority) { | public static function getTaskPriorityIcon($priority) { | ||||
return 'fa-arrow-right'; | return 'fa-arrow-right'; | ||||
} | } | ||||
public static function getTaskPriorityFromKeyword($keyword) { | |||||
$map = self::getTaskPriorityKeywordsMap(); | |||||
foreach ($map as $priority => $keywords) { | |||||
if (in_array($keyword, $keywords)) { | |||||
return $priority; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
public static function isDisabledPriority($priority) { | public static function isDisabledPriority($priority) { | ||||
$config = idx(self::getConfig(), $priority, array()); | $config = idx(self::getConfig(), $priority, array()); | ||||
return idx($config, 'disabled', false); | return idx($config, 'disabled', false); | ||||
} | } | ||||
public static function getConfig() { | public static function getConfig() { | ||||
$config = PhabricatorEnv::getEnvConfig('maniphest.priorities'); | $config = PhabricatorEnv::getEnvConfig('maniphest.priorities'); | ||||
krsort($config); | krsort($config); | ||||
return $config; | return $config; | ||||
} | } | ||||
private static function isValidPriorityKeyword($keyword) { | |||||
if (!strlen($keyword) || strlen($keyword) > 64) { | |||||
return false; | |||||
} | |||||
// Alphanumeric, but not exclusively numeric | |||||
if (!preg_match('/^(?![0-9]*$)[a-zA-Z0-9]+$/', $keyword)) { | |||||
return false; | |||||
} | |||||
epriestley: Perhaps this is too strict? I don't think there's any reason that a Chinese-language install… | |||||
Not Done Inline ActionsShould I change ManiphestTaskStatus->isValidStatusConstant() similarly? That's where I pulled this code from. amckinley: Should I change `ManiphestTaskStatus->isValidStatusConstant()` similarly? That's where I pulled… | |||||
return true; | |||||
} | |||||
public static function validateConfiguration($config) { | public static function validateConfiguration($config) { | ||||
if (!is_array($config)) { | if (!is_array($config)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Configuration is not valid. Maniphest priority configurations '. | 'Configuration is not valid. Maniphest priority configurations '. | ||||
'must be dictionaries.', | 'must be dictionaries.', | ||||
$config)); | $config)); | ||||
} | } | ||||
Show All 15 Lines | foreach ($config as $key => $value) { | ||||
} | } | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$value, | $value, | ||||
array( | array( | ||||
'name' => 'string', | 'name' => 'string', | ||||
'short' => 'optional string', | 'short' => 'optional string', | ||||
'color' => 'optional string', | 'color' => 'optional string', | ||||
'keywords' => 'optional list<string>', | 'keywords' => 'list<string>', | ||||
'disabled' => 'optional bool', | 'disabled' => 'optional bool', | ||||
)); | )); | ||||
$keywords = $value['keywords']; | |||||
foreach ($keywords as $keyword) { | |||||
if (!self::isValidPriorityKeyword($keyword)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Key "%s" is not a valid priority keyword. Priority keywords '. | |||||
'must be 1-64 alphanumeric characters and cannot be '. | |||||
'exclusively digits. For example, "%s" or "%s" are '. | |||||
'reasonable choices.', | |||||
$keyword, | |||||
'low', | |||||
'critical')); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
Perhaps this is too strict? I don't think there's any reason that a Chinese-language install can't use "keywords": ["important", "重要"] (which is what Google says is Chinese for "important"), or an install can't use a 13-letter keyword.
This also allows 0-length keywords, which probably are invalid.
Maybe something like: minimum of 1 byte, maximum of 64 bytes, no spaces, not entirely digits (in case we want to interpret priority numbers as magic later)?