Skip to content

Commit

Permalink
MDL-74565 gradereport_grader: define capability required for editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jun 12, 2022
1 parent ca583bd commit f70fc89
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
23 changes: 6 additions & 17 deletions grade/report/grader/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,18 @@
}
$USER->grade_last_report[$course->id] = 'grader';

// Build editing on/off buttons
// Build editing on/off buttons.
$buttons = '';
if (has_capability('moodle/grade:edit', $context)) {

if (($edit != - 1) and $PAGE->user_allowed_editing()) {
$PAGE->set_other_editing_capability('moodle/grade:edit');
if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
if ($edit != - 1) {
$USER->editing = $edit;
}

// page params for the turn editting on
// Page params for the turn editing on button.
$options = $gpr->get_options();
$options['sesskey'] = sesskey();

if (isset($USER->editing) && $USER->editing) {
$options['edit'] = 0;
$string = get_string('turneditingoff');
} else {
$options['edit'] = 1;
$string = get_string('turneditingon');
}

if (!$PAGE->theme->haseditswitch) {
$buttons = new single_button(new moodle_url('index.php', $options), $string, 'get');
}
$buttons = $OUTPUT->edit_button(new moodle_url($PAGE->url, $options), 'get');
}

$gradeserror = array();
Expand Down
5 changes: 3 additions & 2 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2819,9 +2819,10 @@ public function update_module_button() {
* Returns HTML to display a "Turn editing on/off" button in a form.
*
* @param moodle_url $url The URL + params to send through when clicking the button
* @param string $method
* @return string HTML the button
*/
public function edit_button(moodle_url $url) {
public function edit_button(moodle_url $url, string $method = 'post') {

if ($this->page->theme->haseditswitch == true) {
return;
Expand All @@ -2835,7 +2836,7 @@ public function edit_button(moodle_url $url) {
$editstring = get_string('turneditingon');
}

return $this->single_button($url, $editstring);
return $this->single_button($url, $editstring, $method);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ information provided here is intended especially for developers.
an event exists with the given criteria (see MDL-72723 for details).
- Breaking: 3rd party log readers implementing interface sql_reader will need to implement get_events_select_exists()
* Added $strictness parameter to persistent `get_record` method, optionally allowing caller to ensure record exists
* The core renderer `edit_button` method now accepts an optional `$method` argument (get/post) for the button
* For plugins that override secondary navigation, the namespace for the custom secondary navigation class has
changed. It was (for example) mod_mymodule\local\views\secondary but is now
mod_mymodule\navigation\views\secondary. The old location will continue to work, but is deprecated.
Expand Down
11 changes: 9 additions & 2 deletions theme/boost/classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
*/
class core_renderer extends \core_renderer {

public function edit_button(moodle_url $url) {
/**
* Returns HTML to display a "Turn editing on/off" button in a form.
*
* @param moodle_url $url The URL + params to send through when clicking the button
* @param string $method
* @return string HTML the button
*/
public function edit_button(moodle_url $url, string $method = 'post') {
if ($this->page->theme->haseditswitch) {
return;
}
Expand All @@ -43,7 +50,7 @@ public function edit_button(moodle_url $url) {
$url->param('edit', 'on');
$editstring = get_string('turneditingon');
}
$button = new \single_button($url, $editstring, 'post', ['class' => 'btn btn-primary']);
$button = new \single_button($url, $editstring, $method, ['class' => 'btn btn-primary']);
return $this->render_single_button($button);
}

Expand Down

0 comments on commit f70fc89

Please sign in to comment.