From da4676a27e2c15389162eddbb47deeb94f2c4c68 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 8 Dec 2008 02:30:56 +0000 Subject: [PATCH] course settings: MDL-17501 check for moodle/course:visibility in the course settings form. 1. If a user does not have that capability, don't let them change whether the course is visible. 2. Give teachers that capability by default. 3. To avoid regressions, on upgrade, give moodle/course:visibility to any role that has moodle/course:update. --- course/edit_form.php | 4 ++++ lib/db/access.php | 1 + lib/db/upgrade.php | 19 +++++++++++++++++++ version.php | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/course/edit_form.php b/course/edit_form.php index b86531c2d34..34f852c0d30 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -302,6 +302,10 @@ class course_edit_form extends moodleform { $mform->addElement('select', 'visible', get_string('availability'), $choices); $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true); $mform->setDefault('visible', 1); + if ($course and !has_capability('moodle/course:visibility', $coursecontext)) { + $mform->hardFreeze('visible'); + $mform->setConstant('visible', $course->visible); + } $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"'); $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true); diff --git a/lib/db/access.php b/lib/db/access.php index f2ba4f5a59b..b9e32629398 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -541,6 +541,7 @@ $moodle_capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'legacy' => array( + 'editingteacher' => CAP_ALLOW, 'admin' => CAP_ALLOW ) ), diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index a75afa671bc..10258b19373 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3073,6 +3073,25 @@ function xmldb_main_upgrade($oldversion=0) { } } + /// For MDL-17501. Ensure that any role that has moodle/course:update also + /// has moodle/course:visibility. + if ($result && $oldversion < 2007101532.10) { + /// Get the roles with 'moodle/course:update'. + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext); + + /// Give those roles 'moodle/course:visibility'. + foreach ($roles as $role) { + assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id); + } + + /// Force all sessions to refresh access data. + mark_context_dirty($systemcontext->path); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2007101532.10); + } + return $result; } diff --git a/version.php b/version.php index b44fa78d13d..6daf5aba3b0 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007101532.09; // YYYYMMDD = date of the 1.9 branch (don't change) + $version = 2007101532.10; // YYYYMMDD = date of the 1.9 branch (don't change) // X = release number 1.9.[0,1,2,3...] // Y.YY = micro-increments between releases