Merge branch 'MDL-75186-master' of https://github.com/sarjona/moodle

This commit is contained in:
Jun Pataleta 2022-09-19 12:01:53 +08:00
commit 359e7c7ca4
3 changed files with 38 additions and 4 deletions

View File

@ -142,8 +142,9 @@ class presets implements templatable, renderable {
$actionmenu->set_action_label(get_string('actions'));
$actionmenu->attributes['class'] .= ' presets-actions';
// Only users with mod/data:manageuserpresets capability have options to edit the preset.
if ($preset->can_manage()) {
$canmanage = $preset->can_manage();
// Edit.
if ($canmanage) {
$params = [
'd' => $this->id,
'action' => 'edit',
@ -162,7 +163,23 @@ class presets implements templatable, renderable {
$attributes
));
// Delete.
}
// Export.
$params = [
'd' => $this->id,
'presetname' => $preset->name,
'action' => 'export',
];
$exporturl = new moodle_url('/mod/data/preset.php', $params);
$actionmenu->add(new action_menu_link_secondary(
$exporturl,
null,
get_string('export', 'mod_data'),
));
// Delete.
if ($canmanage) {
$params = [
'd' => $this->id,
'action' => 'delete',

View File

@ -88,7 +88,10 @@ if ($action === 'export') {
throw new \moodle_exception('headersent');
}
$preset = preset::create_from_instance($manager, $data->name);
// Check if we should export a given preset or the current one.
$presetname = optional_param('presetname', $data->name, PARAM_FILE);
$preset = preset::create_from_instance($manager, $presetname);
$exportfile = $preset->export();
$exportfilename = basename($exportfile);
header("Content-Type: application/download\n");

View File

@ -287,3 +287,17 @@ Feature: Users can view and manage data presets
And I should see "Test field name"
And I should see "This is a short text"
Then "Use preset" "button" should exist
@javascript
Scenario: Teachers can export any saved preset
Given I am on the "Mountain landscapes" "data activity" page logged in as teacher1
When I follow "Presets"
# Plugin presets can't be exported.
And I should not see "Actions" in the "Image gallery" "table_row"
# The teacher should be able to export any saved preset.
And I open the action menu in "Saved preset by teacher1" "table_row"
Then I should see "Export"
And following "Export" "link" in the "Saved preset by teacher1" "table_row" should download between "1" and "5000" bytes
And I open the action menu in "Saved preset 1" "table_row"
And I should see "Export"
And following "Export" "link" in the "Saved preset 1" "table_row" should download between "1" and "5000" bytes