MDL-35429 roles: teachers and managers can restore automated backups
authorJake Dallimore <jake@moodle.com>
Thu, 21 Sep 2017 03:36:23 +0000 (11:36 +0800)
committerJake Dallimore <jake@moodle.com>
Mon, 9 Oct 2017 02:29:07 +0000 (10:29 +0800)
Changes the default for the 'moodle/restore:viewautomatedfilearea'
cap from 'Not set' to 'Allow' for the teacher and manager role
archetypes.

lib/db/access.php
lib/filebrowser/tests/file_browser_test.php

index 7b3a37a..68704f4 100644 (file)
@@ -305,6 +305,10 @@ $capabilities = array(
 
         'captype' => 'write',
         'contextlevel' => CONTEXT_COURSE,
+        'archetypes' => array(
+            'editingteacher' => CAP_ALLOW,
+            'manager' => CAP_ALLOW
+        ),
     ),
 
     'moodle/restore:restoretargethub' => array(
index 3ce0570..25835de 100644 (file)
@@ -78,6 +78,10 @@ class file_browser_testcase extends advanced_testcase {
 
         $this->teacher = $this->getDataGenerator()->create_user();
         $this->teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
+
+        // Make sure we're testing what should be the default capabilities.
+        assign_capability('moodle/restore:viewautomatedfilearea', CAP_ALLOW, $this->teacherrole->id, $coursecontext1);
+
         $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course1->id, $this->teacherrole->id);
         $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course2->id, $this->teacherrole->id);
 
@@ -175,9 +179,9 @@ class file_browser_testcase extends advanced_testcase {
         // Filearea "Course summary" has a child that is the actual image file.
         $this->assertEquals($this->course1filerecord, $child->get_children()[0]->get_params());
 
-        // There are six course-level file areas and no modules in this course.
+        // There are seven course-level file areas available to teachers with default caps and no modules in this course.
         $allchildren = $fileinfo->get_children();
-        $this->assertEquals(6, count($allchildren));
+        $this->assertEquals(7, count($allchildren));
         $modulechildren = array_filter($allchildren, function($a) {
             return $a instanceof file_info_context_module;
         });