mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-75771 core_courseformat: Fix capability for edit controls
course_format\base:show_editor now by default uses 'moodle/course:manageactivities', but also accepts other capabilities as param
This commit is contained in:
parent
fa7a55aa5d
commit
4294acc5ab
@ -1340,13 +1340,18 @@ abstract class base {
|
||||
/**
|
||||
* return true if the course editor must be displayed.
|
||||
*
|
||||
* @param array|null $capabilities array of capabilities a user needs to have to see edit controls in general.
|
||||
* If null or not specified, the user needs to have 'moodle/course:manageactivities'.
|
||||
* @return bool true if edit controls must be displayed
|
||||
*/
|
||||
public function show_editor(): bool {
|
||||
public function show_editor(?array $capabilities = ['moodle/course:manageactivities']): bool {
|
||||
global $PAGE;
|
||||
$course = $this->get_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
return $PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext);
|
||||
if ($capabilities === null) {
|
||||
$capabilities = ['moodle/course:manageactivities'];
|
||||
}
|
||||
return $PAGE->user_is_editing() && has_all_capabilities($capabilities, $coursecontext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class addsection implements named_templatable, renderable {
|
||||
public function export_for_template(\renderer_base $output): stdClass {
|
||||
|
||||
// If no editor must be displayed, just return an empty structure.
|
||||
if (!$this->format->show_editor()) {
|
||||
if (!$this->format->show_editor(['moodle/course:update'])) {
|
||||
return new stdClass();
|
||||
}
|
||||
|
||||
|
@ -90,10 +90,7 @@ class title extends inplace_editable implements named_templatable, renderable {
|
||||
$this->displayoptions = $this->load_display_options($displayoptions);
|
||||
|
||||
if ($editable === null) {
|
||||
$editable = $format->show_editor() && has_capability(
|
||||
'moodle/course:manageactivities',
|
||||
$mod->context
|
||||
);
|
||||
$editable = $format->show_editor();
|
||||
}
|
||||
$this->editable = $editable;
|
||||
|
||||
|
@ -79,8 +79,6 @@ class frontpagesection implements named_templatable, renderable {
|
||||
global $USER;
|
||||
|
||||
$format = $this->format;
|
||||
$course = $format->get_course();
|
||||
$context = context_course::instance($course->id);
|
||||
$section = $this->section;
|
||||
|
||||
$sectionoutput = new $this->sectionclass($format, $section);
|
||||
@ -94,7 +92,7 @@ class frontpagesection implements named_templatable, renderable {
|
||||
'sections' => [$sectionoutput->export_for_template($output)],
|
||||
];
|
||||
|
||||
if ($format->show_editor() && has_capability('moodle/course:update', $context)) {
|
||||
if ($format->show_editor(['moodle/course:update'])) {
|
||||
$data->showsettings = true;
|
||||
$data->settingsurl = new moodle_url('/course/editsection.php', ['id' => $section->id]);
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
|
||||
the deprecated methods add_section_delete() and add_cm_delete().
|
||||
* The 4th param of the core_courseformat\output\local\content\cm\cmname construct is now deprecated.
|
||||
The page edition is now detected using the course_format\base:show_editor method as the rest of the
|
||||
core_courseformat outputs.
|
||||
core_courseformat outputs. It defaults to checking the capability 'moodle/course:manageactivities'. If different
|
||||
capabilities are needed to check, an array of capabilities can be passed as an optional parameter to the function.
|
||||
|
||||
=== 4.0 ===
|
||||
* New core_courseformat\base::uses_course_index() to define whether the course format uses course index or not.
|
||||
|
Loading…
x
Reference in New Issue
Block a user