]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13179 - avoid calling get_admin() when unecessary.
authorpoltawski <poltawski>
Sat, 26 Jan 2008 17:00:03 +0000 (17:00 +0000)
committerpoltawski <poltawski>
Sat, 26 Jan 2008 17:00:03 +0000 (17:00 +0000)
It uses a relatively complex query and its not needed except
for a minority of users so we may as well avoid it..
merged from MOODLE_19_STABLE

admin/user.php
lib/moodlelib.php
user/edit.php
user/editadvanced.php
user/tabs.php

index 0b975f030d2e68d4b73d87078281cedcfa224aac..9ae92ee2bfe5bd7049d95b813d6dbb7136bc7a67 100644 (file)
@@ -63,8 +63,7 @@
             error("No such user!", '', true);
         }
 
-        $primaryadmin = get_admin();
-        if ($user->id == $primaryadmin->id) {
+        if (is_primary_admin($user->id)) {
             error("You are not allowed to delete the primary admin user!", '', true);
         }
 
index ae2ca823b7716700c763a35fa842df57669972d4..6415a36f7b760088c967c9f9dea10b5b37e5be92 100644 (file)
@@ -7865,5 +7865,21 @@ function get_plugin_name($plugin, $type='mod') {
     return $plugin_name;
 }
 
+/**
+ * Is a userid the primary administrator?
+ *
+ * @param $userid int id of user to check
+ * @return boolean 
+ */
+function is_primary_admin($userid){
+    $primaryadmin =  get_admin();
+
+    if($userid == $primaryadmin->id){
+        return true;
+    }else{
+        return false;
+    }
+}
+
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>
index c79175ed05305a534579127f90d48b2e11d0e0dc..a411236dc295e097f29897fc39a7235cc7a577a9 100644 (file)
@@ -73,8 +73,7 @@
             print_error('guestnoeditprofileother');
         }
         // no editing of primary admin!
-        $mainadmin = get_admin();
-        if ($user->id == $mainadmin->id) {
+        if (is_primary_admin($user->id)) {
             print_error('adminprimarynoedit');
         }
     }
index 98812c0d55cba4e1a6022dd52a211ef6b7906d02..3cdb707dd0a11b538228a7c710598ddbe2b8606e 100644 (file)
@@ -44,8 +44,7 @@
         redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}");
     }
 
-    $mainadmin = get_admin();
-    if ($user->id != $USER->id and $user->id == $mainadmin->id) {  // Can't edit primary admin
+    if ($user->id != $USER->id and is_primary_admin($user->id)) {  // Can't edit primary admin
         print_error('adminprimarynoedit');
     }
 
index 1822b19e3cfd608e6479a1e25d3cb6941b4acdb8..7aad08a1624382a2ff6e1ab1f1330f02127214c1 100644 (file)
@@ -95,9 +95,8 @@
         $coursecontext   = get_context_instance(CONTEXT_COURSE, $course->id);
         $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
 
-    /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
 
-        $mainadmin = get_admin();
+    /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
 
         if(empty($CFG->loginhttps)) {
             $wwwroot = $CFG->wwwroot;
                 $edittype = 'normal';
             }
 
-        } else if ($user->id != $mainadmin->id) {
-            //no editing of primary admin!
-            if (has_capability('moodle/user:update', $systemcontext)) {
+        } else {
+            if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)){
                 $edittype = 'advanced';
-            } else if (has_capability('moodle/user:editprofile', $personalcontext){
+            } else if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)){
                 //teachers, parents, etc.
                 $edittype = 'normal';
             }