diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-05-15 04:16:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-15 04:16:29 +0300 |
commit | cecec674a65e4dc2a1aa7c33722a5380be2fd719 (patch) | |
tree | e2958f4ba1bb4a6c3c520c88ca40ec60859484b1 /plugins | |
parent | 045b3c6d936b39ca25623ca40b8ba6b4143f14ba (diff) |
Allow throwing exceptions for HTTP error codes to better check query param input. (#14023)
* Allow throwing exceptions for HTTP error codes to better check query param input.
* Add multiple period checks to visualizations.
* Forgot to add files.
* apply review comments
* Make sure code is set when using HttpCodeException.
Diffstat (limited to 'plugins')
8 files changed, 55 insertions, 1 deletions
diff --git a/plugins/CoreVisualizations/Visualizations/Cloud.php b/plugins/CoreVisualizations/Visualizations/Cloud.php index 1a199b327a..f5c5543116 100644 --- a/plugins/CoreVisualizations/Visualizations/Cloud.php +++ b/plugins/CoreVisualizations/Visualizations/Cloud.php @@ -47,6 +47,11 @@ class Cloud extends Visualization $this->config->show_limit_control = false; } + public function beforeLoadDataTable() + { + $this->checkRequestIsNotForMultiplePeriods(); + } + public function afterAllFiltersAreApplied() { if ($this->dataTable->getRowsCount() == 0) { diff --git a/plugins/CoreVisualizations/Visualizations/HtmlTable.php b/plugins/CoreVisualizations/Visualizations/HtmlTable.php index 522eed6ae5..2fa6e6674b 100644 --- a/plugins/CoreVisualizations/Visualizations/HtmlTable.php +++ b/plugins/CoreVisualizations/Visualizations/HtmlTable.php @@ -37,6 +37,11 @@ class HtmlTable extends Visualization return new HtmlTable\RequestConfig(); } + public function beforeLoadDataTable() + { + $this->checkRequestIsNotForMultiplePeriods(); + } + public function beforeRender() { if ($this->requestConfig->idSubtable diff --git a/plugins/CoreVisualizations/Visualizations/HtmlTable/AllColumns.php b/plugins/CoreVisualizations/Visualizations/HtmlTable/AllColumns.php index 536477abb3..9f754eccc4 100644 --- a/plugins/CoreVisualizations/Visualizations/HtmlTable/AllColumns.php +++ b/plugins/CoreVisualizations/Visualizations/HtmlTable/AllColumns.php @@ -67,6 +67,8 @@ class AllColumns extends HtmlTable public function beforeLoadDataTable() { + parent::beforeLoadDataTable(); + unset($this->requestConfig->request_parameters_to_modify['pivotBy']); unset($this->requestConfig->request_parameters_to_modify['pivotByColumn']); } diff --git a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Bar.php b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Bar.php index 1204ae8a09..122920da2d 100644 --- a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Bar.php +++ b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Bar.php @@ -25,6 +25,8 @@ class Bar extends JqplotGraph { parent::beforeLoadDataTable(); + $this->checkRequestIsNotForMultiplePeriods(); + $this->config->datatable_js_type = 'JqplotBarGraphDataTable'; } diff --git a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php index ae8e260bc1..ec6d4924cf 100644 --- a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php +++ b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Evolution.php @@ -35,6 +35,8 @@ class Evolution extends JqplotGraph { parent::beforeRender(); + $this->checkRequestIsOnlyForMultiplePeriods(); + $this->config->show_flatten_table = false; $this->config->datatable_js_type = 'JqplotEvolutionGraphDataTable'; } diff --git a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Pie.php b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Pie.php index 42ba69ef3f..32a2f2dfed 100644 --- a/plugins/CoreVisualizations/Visualizations/JqplotGraph/Pie.php +++ b/plugins/CoreVisualizations/Visualizations/JqplotGraph/Pie.php @@ -34,6 +34,8 @@ class Pie extends JqplotGraph { parent::beforeRender(); + $this->checkRequestIsNotForMultiplePeriods(); + $this->config->show_all_ticks = true; $this->config->datatable_js_type = 'JqplotPieGraphDataTable'; } diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index ab82b56b7e..7cdb0505a7 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -21,6 +21,7 @@ use Piwik\Filesystem; use Piwik\Http; use Piwik\Log; use Piwik\NoAccessException; +use Piwik\Period; use Piwik\Piwik; use Piwik\Plugins\ImageGraph\ImageGraph; use Piwik\Plugins\LanguagesManager\LanguagesManager; @@ -309,7 +310,7 @@ class API extends \Piwik\Plugin\API * @param string $date YYYY-MM-DD * @param bool|false|string $language If not passed, will use default language. * @param bool|false|int $outputType 1 = download report, 3 = output report in browser, 4 = return report content to caller, defaults to download - * @param bool|false|string $period Defaults to 'day'. If not specified, will default to the report's period set when creating the report + * @param bool|false|string $period If not specified, will default to the report's period set when creating the report * @param bool|false|string $reportFormat 'pdf', 'html' or any other format provided via the ScheduledReports.getReportFormats hook * @param bool|false|array $parameters array of parameters * @return array|void @@ -345,6 +346,8 @@ class API extends \Piwik\Plugin\API $period = $report['period_param']; } + $this->checkSinglePeriod($period, $date); + // override report format if (!empty($reportFormat)) { self::validateReportFormat($reportType, $reportFormat); @@ -1032,4 +1035,11 @@ class API extends \Piwik\Plugin\API throw new NoAccessException(Piwik::translate('General_ExceptionPrivilege', array("'view'"))); } } + + private function checkSinglePeriod($period, $date) + { + if (Period::isMultiplePeriod($date, $period)) { + throw new Http\BadRequestException("This API method does not support multiple periods."); + } + } } diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php index 247b2136da..e445d99270 100644 --- a/plugins/ScheduledReports/tests/Integration/ApiTest.php +++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php @@ -12,6 +12,7 @@ use Piwik\API\Proxy; use Piwik\Container\StaticContainer; use Piwik\DataTable; use Piwik\Date; +use Piwik\Http\BadRequestException; use Piwik\Plugins\MobileMessaging\API as APIMobileMessaging; use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; @@ -490,6 +491,31 @@ class ApiTest extends IntegrationTestCase } /** + * @expectedException \Piwik\Http\BadRequestException + * @expectedExceptionMessage This API method does not support multiple periods. + */ + public function test_generateReport_throwsIfMultiplePeriodsRequested() + { + $idReport = APIScheduledReports::getInstance()->addReport( + 1, + '', + Schedule::PERIOD_DAY, + 0, + ScheduledReports::EMAIL_TYPE, + ReportRenderer::HTML_FORMAT, + array( + 'VisitsSummary_get', + 'UserCountry_getCountry', + 'Referrers_getWebsites', + ), + array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY) + ); + + APIScheduledReports::getInstance()->generateReport($idReport, '2012-03-03,2012-03-23', + $language = false, $outputType = APIScheduledReports::OUTPUT_RETURN); + } + + /** * @expectedException \Exception * @expectedExceptionMessage Invalid evolutionPeriodFor value */ |