mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-31 18:01:00 +01:00
Detect and prevent invalid configuation of "ui.footer-items"
Summary: Fixes T12775. Currently, we do not validate this option and it's possible to configure it in an invalid way. Test Plan: Tried to misconfigure things, was helpfully pointed toward errors. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12775 Differential Revision: https://secure.phabricator.com/D18041
This commit is contained in:
parent
e5b3d03319
commit
c4e45c6c8c
3 changed files with 45 additions and 1 deletions
|
@ -2522,6 +2522,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCustomFieldStorageQuery' => 'infrastructure/customfield/query/PhabricatorCustomFieldStorageQuery.php',
|
||||
'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php',
|
||||
'PhabricatorCustomLogoConfigType' => 'applications/config/custom/PhabricatorCustomLogoConfigType.php',
|
||||
'PhabricatorCustomUIFooterConfigType' => 'applications/config/custom/PhabricatorCustomUIFooterConfigType.php',
|
||||
'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php',
|
||||
'PhabricatorDaemonBulkJobController' => 'applications/daemon/controller/PhabricatorDaemonBulkJobController.php',
|
||||
'PhabricatorDaemonBulkJobListController' => 'applications/daemon/controller/PhabricatorDaemonBulkJobListController.php',
|
||||
|
@ -7779,6 +7780,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCustomFieldStorageQuery' => 'Phobject',
|
||||
'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
|
||||
'PhabricatorCustomLogoConfigType' => 'PhabricatorConfigOptionType',
|
||||
'PhabricatorCustomUIFooterConfigType' => 'PhabricatorConfigJSONOptionType',
|
||||
'PhabricatorDaemon' => 'PhutilDaemon',
|
||||
'PhabricatorDaemonBulkJobController' => 'PhabricatorDaemonController',
|
||||
'PhabricatorDaemonBulkJobListController' => 'PhabricatorDaemonBulkJobController',
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCustomUIFooterConfigType
|
||||
extends PhabricatorConfigJSONOptionType {
|
||||
|
||||
public function validateOption(PhabricatorConfigOption $option, $value) {
|
||||
if (!is_array($value)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Footer configuration is not valid: value must be a list of '.
|
||||
'items.'));
|
||||
}
|
||||
|
||||
foreach ($value as $idx => $item) {
|
||||
if (!is_array($item)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Footer item with index "%s" is invalid: each item must be a '.
|
||||
'dictionary describing a footer item.',
|
||||
$idx));
|
||||
}
|
||||
|
||||
try {
|
||||
PhutilTypeSpec::checkMap(
|
||||
$item,
|
||||
array(
|
||||
'name' => 'string',
|
||||
'href' => 'optional string',
|
||||
));
|
||||
} catch (Exception $ex) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Footer item with index "%s" is invalid: %s',
|
||||
$idx,
|
||||
$ex->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -46,6 +46,7 @@ final class PhabricatorUIConfigOptions
|
|||
EOJSON;
|
||||
|
||||
$logo_type = 'custom:PhabricatorCustomLogoConfigType';
|
||||
$footer_type = 'custom:PhabricatorCustomUIFooterConfigType';
|
||||
|
||||
return array(
|
||||
$this->newOption('ui.header-color', 'enum', 'blindigo')
|
||||
|
@ -63,7 +64,7 @@ EOJSON;
|
|||
"Phabricator logo in the site header.\n\n".
|
||||
" - **Wordmark**: Choose new text to display next to the logo. ".
|
||||
"By default, the header displays //Phabricator//.\n\n")),
|
||||
$this->newOption('ui.footer-items', 'list<wild>', array())
|
||||
$this->newOption('ui.footer-items', $footer_type, array())
|
||||
->setSummary(
|
||||
pht(
|
||||
'Allows you to add footer links on most pages.'))
|
||||
|
|
Loading…
Reference in a new issue