MDL-39111 check repository instance context instead of repository usage context ...
authorMarina Glancy <marina@moodle.com>
Tue, 16 Apr 2013 02:45:06 +0000 (12:45 +1000)
committerMarina Glancy <marina@moodle.com>
Tue, 16 Apr 2013 03:28:42 +0000 (13:28 +1000)
repository/lib.php
repository/upgrade.txt

index 731ac6c..f3cc50f 100644 (file)
@@ -1123,7 +1123,7 @@ abstract class repository implements cacheable_object {
      * Do not use this function to access repository contents, because it
      * does not set the current context
      *
-     * @see rpository::get_repository_by_id()
+     * @see repository::get_repository_by_id()
      *
      * @static
      * @param integer $id repository instance id
@@ -1877,7 +1877,7 @@ abstract class repository implements cacheable_object {
 
         if ($type->get_visible()) {
             //if the instance is unique so it's visible, otherwise check if the instance has a enabled context
-            if (empty($instanceoptions) || $type->get_contextvisibility($this->context)) {
+            if (empty($instanceoptions) || $type->get_contextvisibility(context::instance_by_id($this->instance->contextid))) {
                 return true;
             }
         }
index dee842e..739fa81 100644 (file)
@@ -16,6 +16,16 @@ http://docs.moodle.org/dev/Repository_API
 * can_be_edited_by_user() encapsulates all the tests to make sure that the current user
   has the rights to edit the instance of this repository.
 
+* repository::get_instances() (used by filepicker and texteditor to populate the
+  list of available repositories) now calls repository constructor specifying the
+  context where repository will be used.
+  When checking permissions inside repository class use:
+  $this->instance->contextid - to find the context where repository was created;
+  $this->context - to find the current context where repository is used.
+  This also means that the same repository instance may now have different names when
+  called from different contexts.
+  Avoid calling repository::get_instance(), use repository::get_repository_by_id() instead.
+
 === 2.4 ===
 
 * copy_to_area() can receive a new parameter called $areamaxbytes which controls the maximum