--- context.core.inc.orig	2009-08-25 21:38:14.000000000 -0700
+++ context.core.inc	2009-11-08 20:33:22.000000000 -0800
@@ -358,7 +358,17 @@
 
     // This query is identical to the one in block_list(), but status = 1 is excluded to
     // retain blocks that may be enabled via context.
-    $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));
+    // $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));
+    // grab all the block role restrictions
+    $roleblocks = array();
+    if ($result = db_query('SELECT module, delta, rid FROM {blocks_roles} ORDER BY module, delta, rid')) {
+      while ($row = db_fetch_object($result)) {
+        $bid = "{$row->module}-{$row->delta}";
+        if (in_array($row->rid, $rids)) $roleblocks[$bid] = TRUE;
+        elseif (!isset($roleblocks[$bid])) $roleblocks[$bid] = FALSE;
+      }
+    }
+    $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b WHERE b.theme = '%s' ORDER BY b.region, b.weight, b.module", 'b', 'bid'), $theme_key);
 
     while ($block = db_fetch_object($result)) {
       $bid = "{$block->module}-{$block->delta}";
@@ -414,6 +424,11 @@
         $page_match = TRUE;
       }
 
+      // match block role restrictions, if any
+      if ($enabled && isset($roleblocks[$bid]) and !$roleblocks[$bid]) {
+        $enabled = FALSE;
+      }
+
       $block->enabled = $enabled;
       $block->page_match = $page_match;
       $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
