MDL-72978 reportbuilder: Report name can't have only blank spaces

- Don't allow to set a report name containing only blank spaces when
creating a new report or editing an existing report name.
- Removed TODO from code related to MDL-71086
This commit is contained in:
David Matamoros
2021-11-02 16:27:20 +01:00
parent 8af7bec81e
commit 741f47ea7a
4 changed files with 28 additions and 7 deletions
+17
View File
@@ -147,4 +147,21 @@ class report extends dynamic_form {
public function get_page_url_for_dynamic_submission(): moodle_url {
return new moodle_url('/reportbuilder/index.php');
}
/**
* Perform some extra moodle validation
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files): array {
$errors = [];
if (trim($data['name']) === '') {
$errors['name'] = get_string('required');
}
return $errors;
}
}
@@ -45,10 +45,8 @@ class report {
* @return report_model
*/
public static function create_report(stdClass $data, bool $default = true): report_model {
// TODO move this properties_definition validation into the persistents, or resolve MDL-71086.
$data = (object) array_merge(array_intersect_key((array) $data, report_model::properties_definition()), [
'type' => datasource::TYPE_CUSTOM_REPORT,
]);
$data->name = trim($data->name);
$data->type = datasource::TYPE_CUSTOM_REPORT;
$reportpersistent = manager::create_report_persistent($data);
@@ -77,7 +75,7 @@ class report {
throw new invalid_parameter_exception('Invalid report');
}
$report->set('name', $data->name)
$report->set('name', trim($data->name))
->update();
return $report;
@@ -70,7 +70,7 @@ class report_name_editable extends inplace_editable {
core_external::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = clean_param($value, PARAM_TEXT);
$value = trim(clean_param($value, PARAM_TEXT));
if ($value !== '') {
$report
->set('name', $value)
@@ -41,9 +41,13 @@ Feature: Manage custom reports
When I navigate to "Reports > Report builder > Custom reports" in site administration
And I click on "New report" "button"
And I set the following fields in the "New report" "dialogue" to these values:
| Name | My report |
| Report source | Users |
| Include default setup | 0 |
# Try to set the report name to some blank spaces.
And I set the field "Name" in the "New report" "dialogue" to " "
And I click on "Save" "button" in the "New report" "dialogue"
And I should see "Required"
And I set the field "Name" in the "New report" "dialogue" to "My report"
And I click on "Save" "button" in the "New report" "dialogue"
Then I should see "My report"
And I should see "Nothing to display"
@@ -58,6 +62,8 @@ Feature: Manage custom reports
| My report | core_user\reportbuilder\datasource\users |
And I log in as "admin"
When I navigate to "Reports > Report builder > Custom reports" in site administration
# Try to set the report name to some blank spaces. It should simply ignore the change.
And I set the field "Edit report name" in the "My report" "table_row" to " "
And I set the field "Edit report name" in the "My report" "table_row" to "My renamed report"
And I reload the page
Then the following should exist in the "reportbuilder-table" table: