MDL-21097 Correctly check capabilities for course settings items
- Make sure that items in course settings (and frontpage settings) are shown depending on user capabilities - Make sure user is able to turn editing on on the page even if he has only limited number of seciton/modules managing capabilities
This commit is contained in:
+10
-5
@@ -72,11 +72,11 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$this->page->course->id == SITEID ||
|
||||
!$this->page->user_is_editing() ||
|
||||
!($context = context_course::instance($this->page->course->id)) ||
|
||||
!has_capability('moodle/course:update', $context) ||
|
||||
!has_capability('moodle/course:manageactivities', $context) ||
|
||||
!course_ajax_enabled($this->page->course) ||
|
||||
!($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) ||
|
||||
!$coursenode->get('editsettings')) {
|
||||
// too late or we are on site page or we could not find the course settings node
|
||||
!($turneditingnode = $coursenode->get('turneditingonoff'))) {
|
||||
// too late or we are on site page or we could not find the adjacent nodes in course settings menu
|
||||
// or we are not allowed to edit
|
||||
return;
|
||||
}
|
||||
@@ -97,8 +97,13 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$modchoosertogglestring = get_string('modchooserenable', 'moodle');
|
||||
$modchoosertoggleurl->param('modchooser', 'on');
|
||||
}
|
||||
$modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING);
|
||||
$coursenode->add_node($modchoosertoggle, 'editsettings');
|
||||
$modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING, null, 'modchoosertoggle');
|
||||
|
||||
// Insert the modchoosertoggle after the settings node 'turneditingonoff' (navigation_node only has function to insert before, so we insert before and then swap).
|
||||
$coursenode->add_node($modchoosertoggle, 'turneditingonoff');
|
||||
$turneditingnode->remove();
|
||||
$coursenode->add_node($turneditingnode, 'modchoosertoggle');
|
||||
|
||||
$modchoosertoggle->add_class('modchoosertoggle');
|
||||
$modchoosertoggle->add_class('visibleifjs');
|
||||
user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL);
|
||||
|
||||
@@ -123,6 +123,11 @@
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_pagetype('course-view-' . $course->format);
|
||||
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
||||
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
|
||||
if (course_format_uses_sections($course->format)) {
|
||||
$PAGE->set_other_editing_capability('moodle/course:sectionvisibility');
|
||||
$PAGE->set_other_editing_capability('moodle/course:movesections');
|
||||
}
|
||||
|
||||
// Preload course format renderer before output starts.
|
||||
// This is a little hacky but necessary since
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
|
||||
$PAGE->set_pagetype('site-index');
|
||||
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
||||
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
|
||||
$PAGE->set_docs_path('');
|
||||
$PAGE->set_pagelayout('frontpage');
|
||||
$editing = $PAGE->user_is_editing();
|
||||
|
||||
@@ -3489,7 +3489,7 @@ class settings_navigation extends navigation_node {
|
||||
$coursenode->force_open();
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
if ($this->page->user_allowed_editing()) {
|
||||
// Add the turn on/off settings
|
||||
|
||||
if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
|
||||
@@ -3509,8 +3509,10 @@ class settings_navigation extends navigation_node {
|
||||
$editurl->param('edit', 'on');
|
||||
$editstring = get_string('turneditingon');
|
||||
}
|
||||
$coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
|
||||
$coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, 'turneditingonoff', new pix_icon('i/edit', ''));
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
// Add the course settings link
|
||||
$url = new moodle_url('/course/edit.php', array('id'=>$course->id));
|
||||
$coursenode->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, 'editsettings', new pix_icon('i/settings', ''));
|
||||
@@ -4244,7 +4246,7 @@ class settings_navigation extends navigation_node {
|
||||
}
|
||||
$frontpage->id = 'frontpagesettings';
|
||||
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
if ($this->page->user_allowed_editing()) {
|
||||
|
||||
// Add the turn on/off settings
|
||||
$url = new moodle_url('/course/view.php', array('id'=>$course->id, 'sesskey'=>sesskey()));
|
||||
@@ -4256,7 +4258,9 @@ class settings_navigation extends navigation_node {
|
||||
$editstring = get_string('turneditingon');
|
||||
}
|
||||
$frontpage->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
// Add the course settings link
|
||||
$url = new moodle_url('/admin/settings.php', array('section'=>'frontpagesettings'));
|
||||
$frontpage->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
|
||||
|
||||
Reference in New Issue
Block a user