]> git.mjollnir.org Git - moodle.git/commitdiff
course/view: roleswitch checks moved to the course page
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:06:44 +0000 (07:06 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:06:44 +0000 (07:06 +0000)
Implemented all the relevant checks for role_switch().

accesslib's role_switch() doesn't do any UI-related checks any more,
being a backend lib call. These belong here.

course/view.php

index 2bd82540619d87b58d696bee2e42823ae695b6f1..6fa94bc1a7d8219c6dd1a99fd4ec885e1b43a748 100644 (file)
         print_error('nocontext');
     }
 
-    if ($switchrole == 0) {  // Remove any switched roles before checking login
+    // Remove any switched roles before checking login
+    if ($switchrole == 0 && confirm_sesskey()) {
         role_switch($switchrole, $context);
     }
 
     require_login($course->id);
 
-    if ($switchrole > 0) {
-        role_switch($switchrole, $context);
-        require_login($course->id);   // Double check that this role is allowed here
+    // Switchrole - sanity check in cost-order...
+    if ($switchrole > 0 && confirm_sesskey() &&
+        has_capability('moodle/role:switchroles', $context)) {
+        // is this role assignable in this context?
+        // inquiring minds want to know...
+        $aroles = get_assignable_roles($context);
+        if (is_array($aroles) && isset($aroles[$switchrole])) {
+            role_switch($switchrole, $context);
+            // Double check that this role is allowed here
+            require_login($course->id);
+        }
     }
 
     //If course is hosted on an external server, redirect to corresponding