From 6f4c71f5feef3eb88cfef0a0510d9d7ade9f7d60 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 15 Dec 2011 11:54:50 +0000 Subject: [PATCH] MDL-30744 question editing permissions. Update to new accessslib.php code. I don't believe this will actually fix the reported problem, which I cannot reproduce, but it should give us much better error messages, at which point we can fix it. --- lib/questionlib.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index 06be371ac03..f9d82a14ce7 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1481,6 +1481,14 @@ function question_get_all_capabilities() { return $caps; } + +/** + * Tracks all the contexts related to the one where we are currently editing + * questions, and provides helper methods to check permissions. + * + * @copyright 2007 Jamie Pratt me@jamiep.org + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class question_edit_contexts { public static $caps = array( @@ -1507,28 +1515,27 @@ class question_edit_contexts { protected $allcontexts; /** - * @param current context + * Constructor + * @param context the current context. */ - public function __construct($thiscontext) { - $pcontextids = get_parent_contexts($thiscontext); - $contexts = array($thiscontext); - foreach ($pcontextids as $pcontextid) { - $contexts[] = get_context_instance_by_id($pcontextid); - } - $this->allcontexts = $contexts; + public function __construct(context $thiscontext) { + $this->allcontexts = array_values($thiscontext->get_parent_contexts(true)); } + /** * @return array all parent contexts */ public function all() { return $this->allcontexts; } + /** * @return object lowest context which must be either the module or course context */ public function lowest() { return $this->allcontexts[0]; } + /** * @param string $cap capability * @return array parent contexts having capability, zero based index @@ -1542,6 +1549,7 @@ class question_edit_contexts { } return $contextswithcap; } + /** * @param array $caps capabilities * @return array parent contexts having at least one of $caps, zero based index @@ -1558,6 +1566,7 @@ class question_edit_contexts { } return $contextswithacap; } + /** * @param string $tabname edit tab name * @return array parent contexts having at least one of $caps, zero based index @@ -1565,6 +1574,7 @@ class question_edit_contexts { public function having_one_edit_tab_cap($tabname) { return $this->having_one_cap(self::$caps[$tabname]); } + /** * Has at least one parent context got the cap $cap? * @@ -1635,6 +1645,7 @@ class question_edit_contexts { } } + /** * Helps call file_rewrite_pluginfile_urls with the right parameters. *