From 0229dc83eadba042bcdc62f2be9313fc34d702fe Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 8 Jan 2008 15:04:04 +0000 Subject: [PATCH] Put back DEBUG_DEVELOPER sanity check in has_capability, that makes sure the capabiltiy you are asking about actually exists. I know it takes an extra DB query, but it is DEBUG_DEVELOPER only, and it is worth its weight in gold, because otherwise you get really subtle bugs that take forever to diagnose. I know, I have just been banging my head against the wall for an hour. --- lib/accesslib.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/accesslib.php b/lib/accesslib.php index 117593dfd09..5ac60619d88 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -327,6 +327,16 @@ function has_capability($capability, $context, $userid=NULL, $doanything=true) { return false; } +/// Some sanity checks + if (debugging('',DEBUG_DEVELOPER)) { + if (!record_exists('capabilities', 'name', $capability)) { + debugging('Capability "'.$capability.'" was not found! This should be fixed in code.'); + } + if ($doanything != true and $doanything != false) { + debugging('Capability parameter "doanything" is wierd ("'.$doanything.'"). This should be fixed in code.'); + } + } + if (empty($userid)) { // we must accept null, 0, '0', '' etc. in $userid $userid = $USER->id; }