Skip to content
Browse files

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.
  • Loading branch information...
1 parent cb8e878 commit f455e4e9bdcd102f0d19547993be42e1317107e1 @timhunt timhunt committed Dec 15, 2011
Showing with 19 additions and 8 deletions.
  1. +19 −8 lib/questionlib.php
View
27 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 @@ public function having_cap($cap) {
}
return $contextswithcap;
}
+
/**
* @param array $caps capabilities
* @return array parent contexts having at least one of $caps, zero based index
@@ -1558,13 +1566,15 @@ public function having_one_cap($caps) {
}
return $contextswithacap;
}
+
/**
* @param string $tabname edit tab name
* @return array parent contexts having at least one of $caps, zero based index
*/
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 @@ public function require_one_edit_tab_cap($tabname) {
}
}
+
/**
* Helps call file_rewrite_pluginfile_urls with the right parameters.
*

0 comments on commit f455e4e

Please sign in to comment.
Something went wrong with that request. Please try again.