diff --git a/mod/data/classes/output/presets.php b/mod/data/classes/output/presets.php index b9ce09f25f7..29cb8edf2cc 100644 --- a/mod/data/classes/output/presets.php +++ b/mod/data/classes/output/presets.php @@ -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', diff --git a/mod/data/preset.php b/mod/data/preset.php index 879310dc773..2cc88ebfd3e 100644 --- a/mod/data/preset.php +++ b/mod/data/preset.php @@ -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"); diff --git a/mod/data/tests/behat/data_presets.feature b/mod/data/tests/behat/data_presets.feature index d0a24caf039..e18f24b64cb 100644 --- a/mod/data/tests/behat/data_presets.feature +++ b/mod/data/tests/behat/data_presets.feature @@ -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