]> git.mjollnir.org Git - moodle.git/commitdiff
accesslib: revert changes to get_users_by_capability() - MDL-12452 MDL-12451
authormartinlanghoff <martinlanghoff>
Sun, 6 Jan 2008 23:22:08 +0000 (23:22 +0000)
committermartinlanghoff <martinlanghoff>
Sun, 6 Jan 2008 23:22:08 +0000 (23:22 +0000)
The changes made by Yu and Tim are superceded by the patches that
follow -- and would not apply cleanly without this revert.

lib/accesslib.php

index 2069fe501dae8d052c983bd0c5948d3141976f2c..27542134141b8dc1e56ef36375c6eb86dae3c5e2 100755 (executable)
@@ -4165,17 +4165,11 @@ function get_default_course_role($course) {
 
 
 /**
- * This function is supposed to return a list of all the users who have a particular capability in
- * a particular context.
- *
- * However, at the moment it is buggy. For example it does not resolve conflicting capabilities
- * properly - that is if a person has 2 roles, one with allow and one with prevent, they
- * will incorrectly be included. In pracitce, this very rarely occurrs, so using this function is
- * still the best things you can do, and hopefully one day it will be fixed.
- *
- * Pleaes note if you do not pass in $fields, then this function attempts to get u.*
- * which can be rather large.
- *
+ * who has this capability in this context
+ * does not handling user level resolving!!!
+ * (!)pleaes note if $fields is empty this function attempts to get u.*
+ * which can get rather large.
+ * i.e 1 person has 2 roles 1 allow, 1 prevent, this will not work properly
  * @param $context - object
  * @param $capability - string capability
  * @param $fields - fields to be pulled
@@ -4200,25 +4194,13 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
         $view=false, $useviewallgroups=false) {
     global $CFG;
 
-/// Sorting out exceptions
-    $exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
-
 /// check for front page course, and see if default front page role has the required capability
-/// if it does, we can just return all users, and we do not need to check further, just return all users
+    
     $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
     if (!empty($CFG->defaultfrontpageroleid) && ($context->id == $frontpagectx->id || strstr($context->path, '/'.$frontpagectx->id.'/'))) {
-        
         $roles = get_roles_with_capability($capability, CAP_ALLOW, $context);
-        // if this condition is satisfied, then everyone is selected, no need to check further
         if (in_array($CFG->defaultfrontpageroleid, array_keys($roles))) {
-            if (empty($fields)) {
-                $fields = 'u.*';
-            }
-        
-            if (empty($sort)) {
-                $sort = 'u.lastaccess';
-            }
-            return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u $exceptionsql ORDER BY $sort", $limitfrom, $limitnum); 
+            return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u ORDER BY $sort", $limitfrom, $limitnum); 
         }
     }
 
@@ -4244,6 +4226,9 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
         $groupsql = '';
     }
 
+/// Sorting out exceptions
+    $exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
+
 /// Set up default fields
     if (empty($fields)) {
         $fields = 'u.*, ul.timeaccess as lastaccess, ra.hidden';