]> git.mjollnir.org Git - moodle.git/commitdiff
course settings: MDL-17501 check for moodle/course:visibility in the course settings...
authortjhunt <tjhunt>
Mon, 8 Dec 2008 02:31:05 +0000 (02:31 +0000)
committertjhunt <tjhunt>
Mon, 8 Dec 2008 02:31:05 +0000 (02:31 +0000)
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
lib/db/access.php
lib/db/upgrade.php
version.php

index f79a878795ed70e25cbea0868b98860194c9135d..89497a299511c3e86074cf08b722862bd2f959bf 100644 (file)
@@ -315,6 +315,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', $courseconfig->visible);
+        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);
index fafd9632e00164ec0164037dca522def58f4e81d..de14be2cc46976028082f1f76663830daf12c957 100644 (file)
@@ -498,6 +498,7 @@ $moodle_capabilities = array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
+            'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
index 1463351fbfcabdbc5d3e509e82f32cbbb007fed9..2d953634977f4f2b5ffb53a8226e0b4700e656f4 100644 (file)
@@ -1123,7 +1123,25 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2008120700);
     }
 
-    
+    /// For MDL-17501. Ensure that any role that has moodle/course:update also
+    /// has moodle/course:visibility.
+    if ($result && $oldversion < 2008120800) {
+    /// 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, 2008120800);
+    }
+
     return $result;
 }
 
index 34ba7fb2bed4780fb66f156e6c7fadfdf4d50c08..aad31f858ef43f3276184bb51adfa6a5a323f5d3 100644 (file)
@@ -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 = 2008120700;  // YYYYMMDD   = date of the last version bump
+    $version = 2008120800;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20081208)';  // Human-friendly version name