Merge branch 'MDL-61751-master' of git://github.com/andrewnicols/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Apr 2018 22:23:44 +0000 (00:23 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Apr 2018 22:23:44 +0000 (00:23 +0200)
59 files changed:
.travis.yml
analytics/tests/course_test.php
auth/email/auth.php
course/classes/search/section.php [new file with mode: 0644]
course/tests/behat/course_controls.feature
course/tests/behat/paged_course_navigation.feature
course/tests/search_test.php
files/renderer.php
install.php
lang/en/search.php
lib/moodlelib.php
lib/testing/generator/data_generator.php
lib/tests/moodlelib_test.php
lib/xmldb/xmldb_structure.php
media/player/videojs/styles.css
message/output/airnotifier/classes/privacy/provider.php [new file with mode: 0644]
message/output/airnotifier/lang/en/message_airnotifier.php
message/output/airnotifier/tests/privacy_test.php [new file with mode: 0644]
mod/book/edit.php
mod/folder/download_folder.php
mod/lti/service/memberships/classes/local/resources/contextmemberships.php [moved from mod/lti/service/memberships/classes/local/resource/contextmemberships.php with 99% similarity]
mod/lti/service/memberships/classes/local/resources/linkmemberships.php [moved from mod/lti/service/memberships/classes/local/resource/linkmemberships.php with 98% similarity]
mod/lti/service/memberships/classes/local/service/memberships.php
mod/lti/service/memberships/db/renamedclasses.php [new file with mode: 0644]
mod/lti/service/profile/classes/local/resources/profile.php [moved from mod/lti/service/profile/classes/local/resource/profile.php with 98% similarity]
mod/lti/service/profile/classes/local/service/profile.php
mod/lti/service/profile/db/renamedclasses.php [new file with mode: 0644]
mod/lti/service/toolproxy/classes/local/resources/toolproxy.php [moved from mod/lti/service/toolproxy/classes/local/resource/toolproxy.php with 98% similarity]
mod/lti/service/toolproxy/classes/local/service/toolproxy.php
mod/lti/service/toolproxy/db/renamedclasses.php [new file with mode: 0644]
mod/lti/service/toolsettings/classes/local/resources/contextsettings.php [moved from mod/lti/service/toolsettings/classes/local/resource/contextsettings.php with 97% similarity]
mod/lti/service/toolsettings/classes/local/resources/linksettings.php [moved from mod/lti/service/toolsettings/classes/local/resource/linksettings.php with 96% similarity]
mod/lti/service/toolsettings/classes/local/resources/systemsettings.php [moved from mod/lti/service/toolsettings/classes/local/resource/systemsettings.php with 99% similarity]
mod/lti/service/toolsettings/classes/local/service/toolsettings.php
mod/lti/service/toolsettings/db/renamedclasses.php [new file with mode: 0644]
phpunit.xml.dist
privacy/classes/local/metadata/types/plugintype_link.php
privacy/classes/local/metadata/types/subsystem_link.php
privacy/classes/manager.php
privacy/classes/tests/request/content_writer.php
privacy/tests/manager_test.php
question/behaviour/manualgraded/behaviour.php
question/type/essay/backup/moodle2/backup_qtype_essay_plugin.class.php
question/type/essay/db/install.xml
question/type/essay/db/upgrade.php
question/type/essay/edit_essay_form.php
question/type/essay/lang/en/qtype_essay.php
question/type/essay/question.php
question/type/essay/questiontype.php
question/type/essay/renderer.php
question/type/essay/tests/behat/file_type_restriction.feature [new file with mode: 0644]
question/type/essay/tests/fixtures/testquestion.moodle.xml
question/type/essay/tests/helper.php
question/type/essay/tests/walkthrough_test.php
question/type/essay/version.php
question/type/questionbase.php
question/type/upgrade.txt
repository/filepicker.js
theme/boost/templates/core/filemanager_modal_generallayout.mustache

index 9e436f5..a1217e8 100644 (file)
@@ -248,7 +248,7 @@ script:
     - >
       if [ "$TASK" = 'PHPUNIT' ];
       then
-        vendor/bin/phpunit;
+        vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
       fi
 
     - >
index 0383c08..00cfea3 100644 (file)
@@ -36,7 +36,7 @@ class core_analytics_course_testcase extends advanced_testcase {
     public function setUp() {
         global $DB;
 
-        $this->course = $this->getDataGenerator()->create_course();
+        $this->course = $this->getDataGenerator()->create_course(['startdate' => 0]);
         $this->stu1 = $this->getDataGenerator()->create_user();
         $this->stu2 = $this->getDataGenerator()->create_user();
         $this->both = $this->getDataGenerator()->create_user();
index f1cbc11..f207f03 100644 (file)
@@ -113,7 +113,7 @@ class auth_plugin_email extends auth_plugin_base {
      * @since Moodle 3.2
      */
     public function user_signup_with_confirmation($user, $notify=true, $confirmationurl = null) {
-        global $CFG, $DB;
+        global $CFG, $DB, $SESSION;
         require_once($CFG->dirroot.'/user/profile/lib.php');
         require_once($CFG->dirroot.'/user/lib.php');
 
@@ -130,6 +130,11 @@ class auth_plugin_email extends auth_plugin_base {
         // Save any custom profile field information.
         profile_save_data($user);
 
+        // Save wantsurl against user's profile, so we can return them there upon confirmation.
+        if (!empty($SESSION->wantsurl)) {
+            set_user_preference('auth_email_wantsurl', $SESSION->wantsurl, $user);
+        }
+
         // Trigger event.
         \core\event\user_created::create_from_userid($user->id)->trigger();
 
@@ -166,7 +171,7 @@ class auth_plugin_email extends auth_plugin_base {
      * @param string $confirmsecret
      */
     function user_confirm($username, $confirmsecret) {
-        global $DB;
+        global $DB, $SESSION;
         $user = get_complete_user_data('username', $username);
 
         if (!empty($user)) {
@@ -178,6 +183,13 @@ class auth_plugin_email extends auth_plugin_base {
 
             } else if ($user->secret == $confirmsecret) {   // They have provided the secret key to get in
                 $DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
+
+                if ($wantsurl = get_user_preferences('auth_email_wantsurl', false, $user)) {
+                    // Ensure user gets returned to page they were trying to access before signing up.
+                    $SESSION->wantsurl = $wantsurl;
+                    unset_user_preference('auth_email_wantsurl', $user);
+                }
+
                 return AUTH_CONFIRM_OK;
             }
         } else {
diff --git a/course/classes/search/section.php b/course/classes/search/section.php
new file mode 100644 (file)
index 0000000..11f6866
--- /dev/null
@@ -0,0 +1,195 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Search area for course sections (title and summary).
+ *
+ * @package core_course
+ * @copyright 2018 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_course\search;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Search area for course sections (title and summary).
+ *
+ * Note this does not include the activities within the section, as these have their own search
+ * areas.
+ *
+ * @package core_course
+ * @copyright 2018 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class section extends \core_search\base {
+    /**
+     * Sections are indexed at course context.
+     *
+     * @var array
+     */
+    protected static $levels = [CONTEXT_COURSE];
+
+    /**
+     * Returns recordset containing required data for indexing course sections.
+     *
+     * @param int $modifiedfrom timestamp
+     * @param \context|null $context Restriction context
+     * @return \moodle_recordset|null Recordset or null if no change possible
+     */
+    public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
+        global $DB;
+
+        list ($contextjoin, $contextparams) = $this->get_course_level_context_restriction_sql($context, 'c');
+        if ($contextjoin === null) {
+            return null;
+        }
+
+        $comparetext = $DB->sql_compare_text('cs.summary', 1);
+
+        return $DB->get_recordset_sql("
+                SELECT cs.id,
+                       cs.course,
+                       cs.section,
+                       cs.name,
+                       cs.summary,
+                       cs.summaryformat,
+                       cs.timemodified
+                  FROM {course_sections} cs
+                  JOIN {course} c ON c.id = cs.course
+          $contextjoin
+                 WHERE cs.timemodified >= ?
+                   AND (cs.name != ? OR $comparetext != ?)
+              ORDER BY cs.timemodified ASC", array_merge($contextparams, [$modifiedfrom, '', '']));
+    }
+
+    /**
+     * Returns the document associated with this section.
+     *
+     * @param \stdClass $record
+     * @param array $options
+     * @return \core_search\document
+     */
+    public function get_document($record, $options = array()) {
+        // Get the context, modinfo, and section.
+        try {
+            $context = \context_course::instance($record->course);
+        } catch (\moodle_exception $ex) {
+            // Notify it as we run here as admin, we should see everything.
+            debugging('Error retrieving ' . $this->areaid . ' ' . $record->id .
+                    ' document, not all required data is available: ' . $ex->getMessage(),
+                    DEBUG_DEVELOPER);
+            return false;
+        }
+
+        // Title - use default if none given.
+        $title = get_section_name($record->course, $record->section);
+
+        // Prepare associative array with data from DB.
+        $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
+        $doc->set('title', content_to_text($title, false));
+        $doc->set('content', content_to_text($record->summary, $record->summaryformat));
+        $doc->set('contextid', $context->id);
+        $doc->set('courseid', $record->course);
+        $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
+        $doc->set('modified', $record->timemodified);
+
+        return $doc;
+    }
+
+    /**
+     * Whether the user can access the section or not.
+     *
+     * @param int $id The course section id.
+     * @return int One of the \core_search\manager:ACCESS_xx constants
+     */
+    public function check_access($id) {
+        global $DB;
+
+        // Check we can get the section and the course modinfo.
+        $sectionrec = $DB->get_record('course_sections', ['id' => $id], '*', IGNORE_MISSING);
+        if (!$sectionrec) {
+            return \core_search\manager::ACCESS_DELETED;
+        }
+        try {
+            $modinfo = get_fast_modinfo($sectionrec->course);
+        } catch (\moodle_exception $e) {
+            return \core_search\manager::ACCESS_DELETED;
+        }
+        $section = $modinfo->get_section_info($sectionrec->section, IGNORE_MISSING);
+        if (!$section) {
+            return \core_search\manager::ACCESS_DELETED;
+        }
+
+        // Check access to course and that the section is visible to current user.
+        if (can_access_course($modinfo->get_course()) && $section->uservisible) {
+            return \core_search\manager::ACCESS_GRANTED;
+        }
+
+        return \core_search\manager::ACCESS_DENIED;
+    }
+
+    /**
+     * Gets a link to the section.
+     *
+     * @param \core_search\document $doc
+     * @return \moodle_url
+     */
+    public function get_doc_url(\core_search\document $doc) {
+        global $DB;
+        $section = $DB->get_field('course_sections', 'section', ['id' => $doc->get('itemid')], MUST_EXIST);
+        $format = course_get_format($doc->get('courseid'));
+        return $format->get_view_url($section);
+    }
+
+    /**
+     * Gets a link to the section.
+     *
+     * @param \core_search\document $doc
+     * @return \moodle_url
+     */
+    public function get_context_url(\core_search\document $doc) {
+        return $this->get_doc_url($doc);
+    }
+
+    /**
+     * Returns true to include summary files in the index.
+     *
+     * @return bool True
+     */
+    public function uses_file_indexing() {
+        return true;
+    }
+
+    /**
+     * Return the file area that is used for summary files.
+     *
+     * @return array File area name
+     */
+    public function get_search_fileareas() {
+        return ['section'];
+    }
+
+    /**
+     * Returns the moodle component name, as used in the files table.
+     *
+     * @return string Component name
+     */
+    public function get_component_name() {
+        return 'course';
+    }
+}
index f28f75e..0cb64fe 100644 (file)
@@ -21,8 +21,8 @@ Feature: Course activity controls works as expected
       | username | firstname | lastname | email |
       | teacher1 | Teacher | 1 | teacher1@example.com |
     And the following "courses" exist:
-      | fullname | shortname | format | coursedisplay | numsections |
-      | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 |
+      | fullname | shortname | format | coursedisplay | numsections | startdate |
+      | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 | 0 |
     And the following "course enrolments" exist:
       | user | course | role |
       | teacher1 | C1 | editingteacher |
@@ -93,8 +93,8 @@ Feature: Course activity controls works as expected
       | username | firstname | lastname | email |
       | teacher1 | Teacher | 1 | teacher1@example.com |
     And the following "courses" exist:
-      | fullname | shortname | format | coursedisplay | numsections |
-      | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 |
+      | fullname | shortname | format | coursedisplay | numsections | startdate |
+      | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 | 0 |
     And the following "course enrolments" exist:
       | user | course | role |
       | teacher1 | C1 | editingteacher |
index 3e88929..92fd475 100644 (file)
@@ -7,8 +7,8 @@ Feature: Course paged mode
   @javascript @_cross_browser
   Scenario Outline: Weekly and topics course formats with Javascript enabled
     Given the following "courses" exist:
-      | fullname | shortname | category | format | coursedisplay | numsections |
-      | Course 1 | C1 | 0 | <courseformat> | 1 | 3 |
+      | fullname | shortname | category | format | coursedisplay | numsections | startdate |
+      | Course 1 | C1 | 0 | <courseformat> | 1 | 3 | 0 |
     And I log in as "admin"
     And I am on "Course 1" course homepage
     Then I click on <section2> "link" in the <section2> "section"
@@ -40,8 +40,8 @@ Feature: Course paged mode
 
   Scenario Outline: Weekly and topics course formats with Javascript disabled
     Given the following "courses" exist:
-      | fullname | shortname | category | format | coursedisplay | numsections |
-      | Course 1 | C1 | 0 | <courseformat> | 1 | 3 |
+      | fullname | shortname | category | format | coursedisplay | numsections | startdate |
+      | Course 1 | C1 | 0 | <courseformat> | 1 | 3 | 0 |
     And I log in as "admin"
     And I am on "Course 1" course homepage
     Then I click on <section2> "link" in the <section2> "section"
index b609280..9751f1a 100644 (file)
@@ -43,11 +43,17 @@ class course_search_testcase extends advanced_testcase {
      */
     protected $mycoursesareaid = null;
 
+    /**
+     * @var string Area id for sections
+     */
+    protected $sectionareaid = null;
+
     public function setUp() {
         $this->resetAfterTest(true);
         set_config('enableglobalsearch', true);
 
         $this->mycoursesareaid = \core_search\manager::generate_areaid('core_course', 'mycourse');
+        $this->sectionareaid = \core_search\manager::generate_areaid('core_course', 'section');
 
         // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
         $search = testable_core_search::instance();
@@ -240,4 +246,204 @@ class course_search_testcase extends advanced_testcase {
         $this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($course2->id));
         $this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($course3->id));
     }
+
+    /**
+     * Indexing section contents.
+     */
+    public function test_section_indexing() {
+        global $DB, $USER;
+
+        // Returns the instance as long as the area is supported.
+        $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+        $this->assertInstanceOf('\core_course\search\section', $searcharea);
+
+        // Create some courses in categories, and a forum.
+        $generator = $this->getDataGenerator();
+        $cat1 = $generator->create_category();
+        $cat2 = $generator->create_category(['parent' => $cat1->id]);
+        $course1 = $generator->create_course(['category' => $cat1->id]);
+        $course2 = $generator->create_course(['category' => $cat2->id]);
+        $forum = $generator->create_module('forum', ['course' => $course1->id]);
+
+        // Edit 2 sections on course 1 and one on course 2.
+        $existing = $DB->get_record('course_sections', ['course' => $course1->id, 'section' => 2]);
+        $course1section2id = $existing->id;
+        $new = clone($existing);
+        $new->name = 'Frogs';
+        course_update_section($course1->id, $existing, $new);
+
+        $existing = $DB->get_record('course_sections', ['course' => $course1->id, 'section' => 3]);
+        $course1section3id = $existing->id;
+        $new = clone($existing);
+        $new->summary = 'Frogs';
+        $new->summaryformat = FORMAT_HTML;
+        course_update_section($course1->id, $existing, $new);
+
+        $existing = $DB->get_record('course_sections', ['course' => $course2->id, 'section' => 1]);
+        $course2section1id = $existing->id;
+        $new = clone($existing);
+        $new->summary = 'Frogs';
+        $new->summaryformat = FORMAT_HTML;
+        course_update_section($course2->id, $existing, $new);
+
+        // Bodge timemodified into a particular order.
+        $DB->set_field('course_sections', 'timemodified', 1, ['id' => $course1section3id]);
+        $DB->set_field('course_sections', 'timemodified', 2, ['id' => $course1section2id]);
+        $DB->set_field('course_sections', 'timemodified', 3, ['id' => $course2section1id]);
+
+        // All records.
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(0));
+        $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+
+        // Records after time 2.
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(2));
+        $this->assertEquals([$course1section2id, $course2section1id], $results);
+
+        // Records after time 10 (there aren't any).
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(10));
+        $this->assertEquals([], $results);
+
+        // Find the first block to use for a block context.
+        $blockid = array_values($DB->get_records('block_instances', null, 'id', 'id', 0, 1))[0]->id;
+        $blockcontext = context_block::instance($blockid);
+
+        // Check with block context - should be null.
+        $this->assertNull($searcharea->get_document_recordset(0, $blockcontext));
+
+        // Check with user context - should be null.
+        $this->setAdminUser();
+        $usercontext = context_user::instance($USER->id);
+        $this->assertNull($searcharea->get_document_recordset(0, $usercontext));
+
+        // Check with module context - should be null.
+        $modcontext = context_module::instance($forum->cmid);
+        $this->assertNull($searcharea->get_document_recordset(0, $modcontext));
+
+        // Check with course context - should return specific course entries.
+        $coursecontext = context_course::instance($course1->id);
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $coursecontext));
+        $this->assertEquals([$course1section3id, $course1section2id], $results);
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(2, $coursecontext));
+        $this->assertEquals([$course1section2id], $results);
+
+        // Check with category context - should return course in categories and subcategories.
+        $catcontext = context_coursecat::instance($cat1->id);
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $catcontext));
+        $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+        $catcontext = context_coursecat::instance($cat2->id);
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $catcontext));
+        $this->assertEquals([$course2section1id], $results);
+
+        // Check with system context - should return everything (same as null, tested first).
+        $systemcontext = context_system::instance();
+        $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $systemcontext));
+        $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+    }
+
+    /**
+     * Document contents for sections.
+     */
+    public function test_section_document() {
+        global $DB;
+
+        $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+
+        // Create a course.
+        $generator = $this->getDataGenerator();
+        $course = $generator->create_course();
+
+        // Test with default title.
+        $sectionrec = (object)['id' => 123, 'course' => $course->id,
+                'section' => 3, 'timemodified' => 456,
+                'summary' => 'Kermit', 'summaryformat' => FORMAT_HTML];
+        $doc = $searcharea->get_document($sectionrec);
+        $this->assertInstanceOf('\core_search\document', $doc);
+        $this->assertEquals(123, $doc->get('itemid'));
+        $this->assertEquals($this->sectionareaid . '-123', $doc->get('id'));
+        $this->assertEquals($course->id, $doc->get('courseid'));
+        $this->assertFalse($doc->is_set('userid'));
+        $this->assertEquals(\core_search\manager::NO_OWNER_ID, $doc->get('owneruserid'));
+        $this->assertEquals('Topic 3', $doc->get('title'));
+        $this->assertEquals('Kermit', $doc->get('content'));
+
+        // Test with user-set title.
+        $DB->set_field('course_sections', 'name', 'Frogs',
+                ['course' => $course->id, 'section' => 3]);
+        rebuild_course_cache($course->id, true);
+        $doc = $searcharea->get_document($sectionrec);
+        $this->assertEquals('Frogs', $doc->get('title'));
+    }
+
+    /**
+     * Document access for sections.
+     */
+    public function test_section_access() {
+        global $DB;
+
+        $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+
+        // Create a course.
+        $generator = $this->getDataGenerator();
+        $course = $generator->create_course();
+
+        // Create 2 users - student and manager. Initially, student is not even enrolled.
+        $student = $generator->create_user();
+        $manager = $generator->create_user();
+        $generator->enrol_user($manager->id, $course->id, 'manager');
+
+        // Two sections have content - one is hidden.
+        $DB->set_field('course_sections', 'name', 'Frogs',
+                ['course' => $course->id, 'section' => 1]);
+        $DB->set_field('course_sections', 'name', 'Toads',
+                ['course' => $course->id, 'section' => 2]);
+        $DB->set_field('course_sections', 'visible', '0',
+                ['course' => $course->id, 'section' => 2]);
+
+        // Make the modified time be in order of sections.
+        $DB->execute('UPDATE {course_sections} SET timemodified = section');
+
+        // Get the two document objects.
+        $rs = $searcharea->get_document_recordset();
+        $documents = [];
+        $index = 0;
+        foreach ($rs as $rec) {
+            $documents[$index++] = $searcharea->get_document($rec);
+        }
+        $this->assertCount(2, $documents);
+
+        // Log in as admin and check access.
+        $this->setAdminUser();
+        $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+                $searcharea->check_access($documents[0]->get('itemid')));
+        $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+                $searcharea->check_access($documents[1]->get('itemid')));
+
+        // Log in as manager and check access.
+        $this->setUser($manager);
+        $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+                $searcharea->check_access($documents[0]->get('itemid')));
+        $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+                $searcharea->check_access($documents[1]->get('itemid')));
+
+        // Log in as student and check access - none yet.
+        $this->setUser($student);
+        $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+                $searcharea->check_access($documents[0]->get('itemid')));
+        $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+                $searcharea->check_access($documents[1]->get('itemid')));
+
+        // Enrol student - now they should get access but not to the hidden one.
+        $generator->enrol_user($student->id, $course->id, 'student');
+        $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+                $searcharea->check_access($documents[0]->get('itemid')));
+        $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+                $searcharea->check_access($documents[1]->get('itemid')));
+
+        // Delete the course and check it returns deleted.
+        delete_course($course, false);
+        $this->assertEquals(\core_search\manager::ACCESS_DELETED,
+                $searcharea->check_access($documents[0]->get('itemid')));
+        $this->assertEquals(\core_search\manager::ACCESS_DELETED,
+                $searcharea->check_access($documents[1]->get('itemid')));
+    }
 }
index f5f39d8..1cf7e30 100644 (file)
@@ -574,9 +574,11 @@ class core_files_renderer extends plugin_renderer_base {
         $rv = '
 <div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
     <div class="fp-repo-area">
-        <ul class="fp-list">
-            <li class="fp-repo">
-                <a href="#"><img class="fp-repo-icon" alt=" " width="16" height="16" />&nbsp;<span class="fp-repo-name"></span></a>
+        <ul class="fp-list" role="tablist">
+            <li class="fp-repo" role="tab" aria-selected="false" tabindex="-1">
+                <a href="#" tabindex="-1"><img class="fp-repo-icon" alt=" " width="16" height="16" />&nbsp;
+                    <span class="fp-repo-name"></span>
+                </a>
             </li>
         </ul>
     </div>
index 0a5501b..8868c6a 100644 (file)
@@ -166,7 +166,7 @@ $CFG->tempdir              = $CFG->dataroot.'/temp';
 $CFG->cachedir             = $CFG->dataroot.'/cache';
 $CFG->localcachedir        = $CFG->dataroot.'/localcache';
 $CFG->admin                = $config->admin;
-$CFG->docroot              = 'http://docs.moodle.org';
+$CFG->docroot              = 'https://docs.moodle.org';
 $CFG->langotherroot        = $CFG->dataroot.'/lang';
 $CFG->langlocalroot        = $CFG->dataroot.'/lang';
 $CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->directorypermissions : 00777; // let distros set dir permissions
index 2129142..6afcbd4 100644 (file)
@@ -100,6 +100,7 @@ $string['search'] = 'Search';
 $string['search:message_received'] = 'Messages - received';
 $string['search:message_sent'] = 'Messages - sent';
 $string['search:mycourse'] = 'My courses';
+$string['search:section'] = 'Course sections';
 $string['search:user'] = 'Users';
 $string['searcharea'] = 'Search area';
 $string['searching'] = 'Searching in ...';
index 978720a..c011a13 100644 (file)
@@ -442,7 +442,7 @@ define('FEATURE_USES_QUESTIONS', 'usesquestions');
 /**
  * Maximum filename char size
  */
-define('MAX_FILENAME_SIZE', 90);
+define('MAX_FILENAME_SIZE', 100);
 
 /** Unspecified module archetype */
 define('MOD_ARCHETYPE_OTHER', 0);
@@ -991,21 +991,6 @@ function clean_param($param, $type) {
             if ($param === '.' || $param === '..') {
                 $param = '';
             }
-            // Extract a part of the filename if it's char size exceeds MAX_FILENAME_SIZE.
-            // If the filename is too long, the file cannot be created on the filesystem due to exceeding max byte size.
-            // Limiting the filename to a certain size (considering multibyte characters) will prevent this.
-            if (core_text::strlen($param) > MAX_FILENAME_SIZE) {
-                // Exclude extension if present in filename.
-                $mimetypes = get_mimetypes_array();
-                $extension = pathinfo($param, PATHINFO_EXTENSION);
-                if ($extension && !empty($mimetypes[$extension])) {
-                    $basename = pathinfo($param, PATHINFO_FILENAME);
-                    $param = core_text::substr($basename, 0, MAX_FILENAME_SIZE);
-                    $param .= '.' . $extension;
-                } else {
-                    $param = core_text::substr($param, 0, MAX_FILENAME_SIZE);
-                }
-            }
             return $param;
 
         case PARAM_PATH:
@@ -6813,7 +6798,6 @@ function clean_filename($string) {
     return clean_param($string, PARAM_FILE);
 }
 
-
 // STRING TRANSLATION.
 
 /**
@@ -8258,6 +8242,32 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {
     return $truncate;
 }
 
+/**
+ * Shortens a given filename by removing characters positioned after the ideal string length.
+ * When the filename is too long, the file cannot be created on the filesystem due to exceeding max byte size.
+ * Limiting the filename to a certain size (considering multibyte characters) will prevent this.
+ *
+ * @param string $filename file name
+ * @param int $length ideal string length
+ * @return string $shortened shortened file name
+ */
+function shorten_filename($filename, $length = MAX_FILENAME_SIZE) {
+    $shortened = $filename;
+    // Extract a part of the filename if it's char size exceeds the ideal string length.
+    if (core_text::strlen($filename) > $length) {
+        // Exclude extension if present in filename.
+        $mimetypes = get_mimetypes_array();
+        $extension = pathinfo($filename, PATHINFO_EXTENSION);
+        if ($extension && !empty($mimetypes[$extension])) {
+            $basename = pathinfo($filename, PATHINFO_FILENAME);
+            $shortened = core_text::substr($basename, 0, $length);
+            $shortened .= '.' . $extension;
+        } else {
+            $shortened = core_text::substr($filename, 0, $length);
+        }
+    }
+    return $shortened;
+}
 
 /**
  * Given dates in seconds, how many weeks is the date from startdate
index b3499c7..5dc5e4c 100644 (file)
@@ -415,6 +415,10 @@ EOD;
             $record['category'] = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
         }
 
+        if (!isset($record['startdate'])) {
+            $record['startdate'] = usergetmidnight(time());
+        }
+
         if (isset($record['tags']) && !is_array($record['tags'])) {
             $record['tags'] = preg_split('/\s*,\s*/', trim($record['tags']), -1, PREG_SPLIT_NO_EMPTY);
         }
index 454d9cc..87f59e8 100644 (file)
@@ -682,13 +682,6 @@ class core_moodlelib_testcase extends advanced_testcase {
         $this->assertSame(' . .dontltrim.me', clean_param(' . .dontltrim.me', PARAM_FILE));
         $this->assertSame('here is a tab.txt', clean_param("here is a tab\t.txt", PARAM_FILE));
         $this->assertSame('here is a linebreak.txt', clean_param("here is a line\r\nbreak.txt", PARAM_FILE));
-        // Test filename that contains more than 90 characters.
-        $filename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
-        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laud',
-            clean_param($filename, PARAM_FILE));
-        // Filename contains extension.
-        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laud.zip',
-            clean_param($filename . '.zip', PARAM_FILE));
 
         // The following behaviours have been maintained although they seem a little odd.
         $this->assertSame('funnything', clean_param('funny:thing', PARAM_FILE));
@@ -1014,6 +1007,29 @@ class core_moodlelib_testcase extends advanced_testcase {
                 shorten_text($text, 1));
     }
 
+    public function test_shorten_filename() {
+        // Test filename that contains more than 100 characters.
+        $filename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium tot',
+            shorten_filename($filename));
+        // Filename contains extension.
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium tot.zip',
+            shorten_filename($filename . '.zip'));
+        // Limit filename to 50 chars.
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error si',
+            shorten_filename($filename, 50));
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error si.zip',
+            shorten_filename($filename . '.zip', 50));
+
+        // Test filename that contains less than 100 characters.
+        $filename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque';
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque',
+            shorten_filename($filename));
+        // Filename contains extension.
+        $this->assertSame('sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque.zip',
+            shorten_filename($filename . '.zip'));
+    }
+
     public function test_usergetdate() {
         global $USER, $CFG, $DB;
         $this->resetAfterTest();
index 0f500a6..ad681ef 100644 (file)
@@ -234,7 +234,14 @@ class xmldb_structure extends xmldb_object {
         // Normalize paths to compare them.
         $filepath = realpath($this->name); // File path comes in name.
         $filename = basename($filepath);
-        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $this->path . DIRECTORY_SEPARATOR . $filename);
+        $normalisedpath = $this->path;
+        if ($CFG->admin !== 'admin') {
+            $needle = 'admin/';
+            if (strpos($this->path, $needle) === 0) {
+                $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
+            }
+        }
+        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
         if ($filepath !== $structurepath) {
             $relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
             $this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;
index c960552..060bf8d 100644 (file)
@@ -1428,3 +1428,32 @@ video::-webkit-media-text-track-display {
 .mediaplugin_videojs video {
   min-height: 32px;
 }
+
+/* MDL-61020: VideoJS timeline progress bar should not be flipped in RTL mode. */
+
+/* Prevent the progress bar from being flipped in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-progress-holder .vjs-play-progress,
+.video-js .vjs-progress-holder .vjs-load-progress,
+.video-js .vjs-progress-holder .vjs-load-progress div {
+  left: 0;
+  right: auto;
+}
+/* Keep the video scrubber button at the end of the progress bar in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-play-progress:before {
+  left: auto;
+  right: -0.5em;
+}
+/* Prevent the volume slider from being flipped in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-volume-level {
+  left: 0;
+  right: auto;
+}
+/* Keep the volume slider handle at the end of the volume slider in RTL. */
+/*rtl:ignore*/
+.vjs-slider-horizontal .vjs-volume-level:before {
+  left: auto;
+  right: -0.5em;
+}
diff --git a/message/output/airnotifier/classes/privacy/provider.php b/message/output/airnotifier/classes/privacy/provider.php
new file mode 100644 (file)
index 0000000..1c02016
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Privacy class for requesting user data.
+ *
+ * @package    message_airnotifier
+ * @copyright  2018 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace message_airnotifier\privacy;
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core_privacy\local\metadata\collection;
+use \core_privacy\local\request\contextlist;
+use \core_privacy\local\request\approved_contextlist;
+use \core_privacy\local\request\transform;
+
+/**
+ * Privacy class for requesting user data.
+ *
+ * @package    message_airnotifier
+ * @copyright  2018 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider {
+
+    /**
+     * Returns meta data about this system.
+     *
+     * @param   collection $collection The initialised collection to add items to.
+     * @return  collection A listing of user data stored through this system.
+     */
+    public static function get_metadata(collection $collection) : collection {
+        $collection->link_subsystem('core_user', 'privacy:metadata:usersubsystem');
+        $collection->add_database_table('message_airnotifier_devices', [
+                'userdeviceid' => 'privacy:metadata:userdeviceid',
+                'enabled' => 'privacy:metadata:enabled'
+            ], 'privacy:metadata:tableexplanation');
+        $collection->link_external_location('External airnotifier site.', [
+                'userid' => 'privacy:metadata:userid',
+                'username' => 'privacy:metadata:username',
+                'userfromid' => 'privacy:metadata:userfromid',
+                'userfromfullname' => 'privacy:metadata:userfromfullname',
+                'date' => 'privacy:metadata:date',
+                'subject' => 'privacy:metadata:subject',
+                'notification' => 'privacy:metadata:notification',
+                'smallmessage' => 'privacy:metadata:smallmessage',
+                'fullmessage' => 'privacy:metadata:fullmessage'
+        ], 'privacy:metadata:externalpurpose');
+        // This system is unaware of user preferences such as message_provider_moodle_instantmessage_loggedin.
+        return $collection;
+    }
+
+    /**
+     * Get the list of contexts that contain user information for the specified user.
+     *
+     * @param   int         $userid     The user to search.
+     * @return  contextlist $contextlist  The contextlist containing the list of contexts used in this plugin.
+     */
+    public static function get_contexts_for_userid(int $userid) : contextlist {
+        $sql = "SELECT ctx.id
+                  FROM {message_airnotifier_devices} mad
+                  JOIN {user_devices} ud ON ud.id = mad.userdeviceid
+                  JOIN {user} u ON ud.userid = u.id
+                  JOIN {context} ctx ON ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel
+                 WHERE ud.userid = :userid";
+
+        $params = ['userid' => $userid, 'contextlevel' => CONTEXT_USER];
+
+        $contextlist = new contextlist();
+        $contextlist->add_from_sql($sql, $params);
+        return $contextlist;
+    }
+
+    /**
+     * Export all user data for the specified user, in the specified contexts.
+     *
+     * @param approved_contextlist $contextlist The approved contexts to export information for.
+     */
+    public static function export_user_data(approved_contextlist $contextlist) {
+        $results = static::get_records($contextlist->get_user()->id);
+        $context = $contextlist->current();
+        foreach ($results as $result) {
+            $data = (object)[
+                'appid' => $result->appid,
+                'pushid' => $result->pushid,
+                'name' => $result->name,
+                'model' => $result->model,
+                'platform' => $result->platform,
+                'version' => $result->version,
+                'timecreated' => transform::datetime($result->timecreated),
+                'timemodified' => transform::datetime($result->timemodified),
+                'enabled' => transform::yesno($result->enable)
+            ];
+            \core_privacy\local\request\writer::with_context($context)->export_data([
+                    get_string('privacy:subcontext', 'message_airnotifier'),
+                    $result->model . '_' . $result->pushid
+                ], $data);
+        }
+    }
+
+    /**
+     * Delete all use data which matches the specified deletion_criteria.
+     *
+     * @param context $context A user context.
+     */
+    public static function delete_data_for_all_users_in_context(\context $context) {
+        static::delete_data($context->instanceid);
+    }
+
+    /**
+     * Delete all user data for the specified user, in the specified contexts.
+     *
+     * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
+     */
+    public static function delete_data_for_user(approved_contextlist $contextlist) {
+        static::delete_data($contextlist->get_user()->id);
+    }
+
+    /**
+     * Delete data related to a userid.
+     *
+     * @param int $userid The user ID
+     */
+    protected static function delete_data(int $userid) {
+        global $DB;
+
+        foreach (static::get_records($userid) as $record) {
+            $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]);
+        }
+    }
+
+    /**
+     * Get records related to this plugin and user.
+     *
+     * @param  int $userid The user ID
+     * @return array An array of records.
+     */
+    protected static function get_records(int $userid) : array {
+        global $DB;
+        $sql = "SELECT mad.id, mad.enable, ud.appid, ud.name, ud.model, ud.platform, ud.version, ud.timecreated, ud.timemodified,
+                        ud.pushid
+                FROM {message_airnotifier_devices} mad
+                JOIN {user_devices} ud ON mad.userdeviceid = ud.id
+                WHERE ud.userid = :userid";
+        $params = ['userid' => $userid];
+        return $DB->get_records_sql($sql, $params);
+    }
+}
index d900e43..666fcda 100644 (file)
@@ -41,6 +41,23 @@ $string['nodevices'] = 'No registered devices. Devices will automatically appear
 $string['nopermissiontomanagedevices'] = 'You don\'t have permission to manage devices.';
 $string['notconfigured'] = 'The Airnotifier server hasn\'t been configured so Airnotifier messages cannot be sent';
 $string['pluginname'] = 'Mobile';
+$string['privacy:appiddescription'] = 'This is an identifier to the application being used.';
+$string['privacy:enableddescription'] = 'If this device is enabled for airnotifier.';
+$string['privacy:metadata:enabled'] = 'If the airnotifier device is enabled.';
+$string['privacy:metadata:date'] = 'The date that the message was sent.';
+$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external site to be ultimately delivered to the mobile device of the user.';
+$string['privacy:metadata:fullmessage'] = 'The full message.';
+$string['privacy:metadata:notification'] = 'If this message is a notification.';
+$string['privacy:metadata:smallmessage'] = 'An section of the message.';
+$string['privacy:metadata:subject'] = 'The subject line of the message.';
+$string['privacy:metadata:tableexplanation'] = 'Airnotifier device information is stored here.';
+$string['privacy:metadata:userdeviceid'] = 'The ID linking to the user\'s mobile device';
+$string['privacy:metadata:userfromfullname'] = 'The full name of the user that sent the message.';
+$string['privacy:metadata:userfromid'] = 'The user ID of the author of the message.';
+$string['privacy:metadata:userid'] = 'The user ID.';
+$string['privacy:metadata:username'] = 'The username for the user.';
+$string['privacy:metadata:usersubsystem'] = 'This plugin is connected to the user subsystem.';
+$string['privacy:subcontext'] = 'Message Airnotifier';
 $string['sitemustberegistered'] = 'In order to use the public Airnotifier instance you must register your site with Moodle.net';
 $string['showhide'] = 'Enable/disable the device.';
 $string['requestaccesskey'] = 'Request access key';
diff --git a/message/output/airnotifier/tests/privacy_test.php b/message/output/airnotifier/tests/privacy_test.php
new file mode 100644 (file)
index 0000000..7559b43
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * Base class for unit tests for message_airnotifier.
+ *
+ * @package    message_airnotifier
+ * @copyright  2018 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core_privacy\tests\provider_testcase;
+/**
+ * Unit tests for message\output\airnotifier\classes\privacy\provider.php
+ *
+ * @copyright  2018 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class message_airnotifier_testcase extends provider_testcase {
+
+    /**
+     * Basic setup for these tests.
+     */
+    public function setUp() {
+        $this->resetAfterTest(true);
+    }
+
+    /**
+     * /
+     * @param object $user User object
+     * @param string $pushid unique string
+     */
+    protected function add_device($user, $pushid) {
+        global $DB;
+
+        // Add fake core device.
+        $device = array(
+            'appid' => 'com.moodle.moodlemobile',
+            'name' => 'occam',
+            'model' => 'Nexus 4',
+            'platform' => 'Android',
+            'version' => '4.2.2',
+            'pushid' => $pushid,
+            'uuid' => 'asdnfl348qlksfaasef859',
+            'userid' => $user->id,
+            'timecreated' => time(),
+            'timemodified' => time(),
+        );
+        $coredeviceid = $DB->insert_record('user_devices', (object) $device);
+
+        $airnotifierdev = array(
+            'userdeviceid' => $coredeviceid,
+            'enable' => 1
+        );
+        $airnotifierdevid = $DB->insert_record('message_airnotifier_devices', (object) $airnotifierdev);
+    }
+
+    /**
+     * Test returning metadata.
+     */
+    public function test_get_metadata() {
+        $collection = new \core_privacy\local\metadata\collection('message_airnotifier');
+        $collection = \message_airnotifier\privacy\provider::get_metadata($collection);
+        $this->assertNotEmpty($collection);
+    }
+
+    /**
+     * Test getting the context for the user ID related to this plugin.
+     */
+    public function test_get_contexts_for_userid() {
+
+        $user = $this->getDataGenerator()->create_user();
+        $context = context_user::instance($user->id);
+
+        $this->add_device($user, 'apuJih874kj');
+        $this->add_device($user, 'bdu09Ikjjsu');
+
+        $contextlist = \message_airnotifier\privacy\provider::get_contexts_for_userid($user->id);
+        $this->assertEquals($context->id, $contextlist->current()->id);
+    }
+
+    /**
+     * Test that data is exported correctly for this plugin.
+     */
+    public function test_export_user_data() {
+        $user = $this->getDataGenerator()->create_user();
+        $context = context_user::instance($user->id);
+
+        $this->add_device($user, 'apuJih874kj');
+        $this->add_device($user, 'bdu09Ikjjsu');
+
+        $writer = \core_privacy\local\request\writer::with_context($context);
+        $this->assertFalse($writer->has_any_data());
+        $this->export_context_data_for_user($user->id, $context, 'message_airnotifier');
+
+        // First device.
+        $data = $writer->get_data([get_string('privacy:subcontext', 'message_airnotifier'), 'Nexus 4_apuJih874kj']);
+        $this->assertEquals('com.moodle.moodlemobile', $data->appid);
+
+        // Second device.
+        $data = $writer->get_data([get_string('privacy:subcontext', 'message_airnotifier'), 'Nexus 4_bdu09Ikjjsu']);
+        $this->assertEquals('bdu09Ikjjsu', $data->pushid);
+    }
+
+    /**
+     * Test that user data is deleted using the context.
+     */
+    public function test_delete_data_for_all_users_in_context() {
+        global $DB;
+
+        $user = $this->getDataGenerator()->create_user();
+        $context = context_user::instance($user->id);
+
+        $this->add_device($user, 'apuJih874kj');
+
+        // Check that we have an entry.
+        $devices = $DB->get_records('message_airnotifier_devices');
+        $this->assertCount(1, $devices);
+
+        \message_airnotifier\privacy\provider::delete_data_for_all_users_in_context($context);
+
+        // Check that it has now been deleted.
+        $devices = $DB->get_records('message_airnotifier_devices');
+        $this->assertCount(0, $devices);
+    }
+
+    /**
+     * Test that user data is deleted for this user.
+     */
+    public function test_delete_data_for_user() {
+        global $DB;
+
+        $user = $this->getDataGenerator()->create_user();
+        $context = context_user::instance($user->id);
+
+        $this->add_device($user, 'apuJih874kj');
+
+        // Check that we have an entry.
+        $devices = $DB->get_records('message_airnotifier_devices');
+        $this->assertCount(1, $devices);
+
+        $approvedlist = new \core_privacy\local\request\approved_contextlist($user, 'message_airnotifier', [$context->id]);
+        \message_airnotifier\privacy\provider::delete_data_for_user($approvedlist);
+
+        // Check that it has now been deleted.
+        $devices = $DB->get_records('message_airnotifier_devices');
+        $this->assertCount(0, $devices);
+    }
+}
index 09b99d4..c833783 100644 (file)
@@ -61,6 +61,12 @@ $mform = new book_chapter_edit_form(null, array('chapter'=>$chapter, 'options'=>
 
 // If data submitted, then process and store.
 if ($mform->is_cancelled()) {
+    // Make sure at least one chapter exists.
+    $chapters = book_preload_chapters($book);
+    if (!$chapters) {
+        redirect(new moodle_url('/course/view.php', array('id' => $course->id))); // Back to course view.
+    }
+
     if (empty($chapter->id)) {
         redirect("view.php?id=$cm->id");
     } else {
index ef6d101..53d0005 100644 (file)
@@ -49,7 +49,7 @@ if (!$file) {
 }
 
 $zipper   = get_file_packer('application/zip');
-$filename = clean_filename($folder->name . "-" . date("Ymd")) . ".zip";
+$filename = shorten_filename(clean_filename($folder->name . "-" . date("Ymd")) . ".zip");
 $temppath = make_request_directory() . $filename;
 
 if ($zipper->archive_to_pathname(array('/' => $file), $temppath)) {
@@ -24,7 +24,7 @@
  */
 
 
-namespace ltiservice_memberships\local\resource;
+namespace ltiservice_memberships\local\resources;
 
 use \mod_lti\local\ltiservice\service_base;
 use ltiservice_memberships\local\service\memberships;
@@ -24,7 +24,7 @@
  */
 
 
-namespace ltiservice_memberships\local\resource;
+namespace ltiservice_memberships\local\resources;
 
 use \mod_lti\local\ltiservice\service_base;
 use ltiservice_memberships\local\service\memberships;
index fbbec96..8066d1b 100644 (file)
@@ -67,8 +67,8 @@ class memberships extends \mod_lti\local\ltiservice\service_base {
 
         if (empty($this->resources)) {
             $this->resources = array();
-            $this->resources[] = new \ltiservice_memberships\local\resource\contextmemberships($this);
-            $this->resources[] = new \ltiservice_memberships\local\resource\linkmemberships($this);
+            $this->resources[] = new \ltiservice_memberships\local\resources\contextmemberships($this);
+            $this->resources[] = new \ltiservice_memberships\local\resources\linkmemberships($this);
         }
 
         return $this->resources;
diff --git a/mod/lti/service/memberships/db/renamedclasses.php b/mod/lti/service/memberships/db/renamedclasses.php
new file mode 100644 (file)
index 0000000..d38e990
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package   mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+    // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+    'ltiservice_memberships\local\resource\linkmemberships'    => 'ltiservice_memberships\local\resources\linkmemberships',
+    'ltiservice_memberships\local\resource\contextmemberships' => 'ltiservice_memberships\local\resources\contextmemberships',
+
+);
@@ -24,7 +24,7 @@
  */
 
 
-namespace ltiservice_profile\local\resource;
+namespace ltiservice_profile\local\resources;
 
 use \mod_lti\local\ltiservice\service_base;
 
@@ -43,7 +43,7 @@ class profile extends \mod_lti\local\ltiservice\resource_base {
     /**
      * Class constructor.
      *
-     * @param ltiservice_profile\local\resource\profile $service Service instance
+     * @param ltiservice_profile\local\resources\profile $service Service instance
      */
     public function __construct($service) {
 
index dcea867..55830e9 100644 (file)
@@ -59,7 +59,7 @@ class profile extends \mod_lti\local\ltiservice\service_base {
 
         if (empty($this->resources)) {
             $this->resources = array();
-            $this->resources[] = new \ltiservice_profile\local\resource\profile($this);
+            $this->resources[] = new \ltiservice_profile\local\resources\profile($this);
         }
 
         return $this->resources;
diff --git a/mod/lti/service/profile/db/renamedclasses.php b/mod/lti/service/profile/db/renamedclasses.php
new file mode 100644 (file)
index 0000000..866e70a
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package   mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+    // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+    'ltiservice_profile\local\resource\profile'      => 'ltiservice_profile\local\resources\profile',
+);
+
@@ -24,7 +24,7 @@
  */
 
 
-namespace ltiservice_toolproxy\local\resource;
+namespace ltiservice_toolproxy\local\resources;
 
 defined('MOODLE_INTERNAL') || die();
 
@@ -47,7 +47,7 @@ class toolproxy extends \mod_lti\local\ltiservice\resource_base {
     /**
      * Class constructor.
      *
-     * @param ltiservice_toolproxy\local\resource\toolproxy $service Service instance
+     * @param ltiservice_toolproxy\local\resources\toolproxy $service Service instance
      */
     public function __construct($service) {
 
index 1d42761..ab69e08 100644 (file)
@@ -58,7 +58,7 @@ class toolproxy extends \mod_lti\local\ltiservice\service_base {
 
         if (empty($this->resources)) {
             $this->resources = array();
-            $this->resources[] = new \ltiservice_toolproxy\local\resource\toolproxy($this);
+            $this->resources[] = new \ltiservice_toolproxy\local\resources\toolproxy($this);
         }
 
         return $this->resources;
diff --git a/mod/lti/service/toolproxy/db/renamedclasses.php b/mod/lti/service/toolproxy/db/renamedclasses.php
new file mode 100644 (file)
index 0000000..0fa7548
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package   mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+    // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+    'ltiservice_toolproxy\local\resource\toolproxy'    => 'ltiservice_toolproxy\local\resources\toolproxy',
+);
+
@@ -24,9 +24,9 @@
  */
 
 
-namespace ltiservice_toolsettings\local\resource;
+namespace ltiservice_toolsettings\local\resources;
 
-use ltiservice_toolsettings\local\resource\systemsettings;
+use ltiservice_toolsettings\local\resources\systemsettings;
 use ltiservice_toolsettings\local\service\toolsettings;
 
 defined('MOODLE_INTERNAL') || die();
@@ -44,7 +44,7 @@ class contextsettings extends \mod_lti\local\ltiservice\resource_base {
     /**
      * Class constructor.
      *
-     * @param ltiservice_toolsettings\local\resource\contextsettings $service Service instance
+     * @param ltiservice_toolsettings\local\resources\contextsettings $service Service instance
      */
     public function __construct($service) {
 
  */
 
 
-namespace ltiservice_toolsettings\local\resource;
+namespace ltiservice_toolsettings\local\resources;
 
-use ltiservice_toolsettings\local\resource\systemsettings;
-use ltiservice_toolsettings\local\resource\contextsettings;
+use ltiservice_toolsettings\local\resources\systemsettings;
+use ltiservice_toolsettings\local\resources\contextsettings;
 use ltiservice_toolsettings\local\service\toolsettings;
 
 defined('MOODLE_INTERNAL') || die();
@@ -45,7 +45,7 @@ class linksettings extends \mod_lti\local\ltiservice\resource_base {
     /**
      * Class constructor.
      *
-     * @param ltiservice_toolsettings\local\resource\linksettings $service Service instance
+     * @param ltiservice_toolsettings\local\resources\linksettings $service Service instance
      */
     public function __construct($service) {
 
index 5626e21..f7969a9 100644 (file)
@@ -58,9 +58,9 @@ class toolsettings extends \mod_lti\local\ltiservice\service_base {
 
         if (empty($this->resources)) {
             $this->resources = array();
-            $this->resources[] = new \ltiservice_toolsettings\local\resource\systemsettings($this);
-            $this->resources[] = new \ltiservice_toolsettings\local\resource\contextsettings($this);
-            $this->resources[] = new \ltiservice_toolsettings\local\resource\linksettings($this);
+            $this->resources[] = new \ltiservice_toolsettings\local\resources\systemsettings($this);
+            $this->resources[] = new \ltiservice_toolsettings\local\resources\contextsettings($this);
+            $this->resources[] = new \ltiservice_toolsettings\local\resources\linksettings($this);
         }
 
         return $this->resources;
diff --git a/mod/lti/service/toolsettings/db/renamedclasses.php b/mod/lti/service/toolsettings/db/renamedclasses.php
new file mode 100644 (file)
index 0000000..4e8d4da
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package   mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+    // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+    'ltiservice_toolsettings\local\resource\contextsettings' => 'ltiservice_toolsettings\local\resources\contextsettings',
+    'ltiservice_toolsettings\local\resource\linksettings' => 'ltiservice_toolsettings\local\resources\linksettings',
+    'ltiservice_toolsettings\local\resource\systemsettings' => 'ltiservice_toolsettings\local\resources\systemsettings',
+);
+
index 7d19b0b..574e3fd 100644 (file)
@@ -14,6 +14,7 @@
         stopOnIncomplete="false"
         stopOnSkipped="false"
         beStrictAboutTestsThatDoNotTestAnything="false"
+        beStrictAboutOutputDuringTests="true"
         printerClass="Hint_ResultPrinter"
         testSuiteLoaderClass="phpunit_autoloader"
         >
index 54b29cf..a60fa58 100644 (file)
@@ -78,7 +78,7 @@ class plugintype_link implements type {
      * @return  array
      */
     public function get_privacy_fields() : array {
-        return null;
+        return [];
     }
 
     /**
index 88eedb5..4ee260e 100644 (file)
@@ -78,7 +78,7 @@ class subsystem_link implements type {
      * @return  array
      */
     public function get_privacy_fields() : array {
-        return null;
+        return [];
     }
 
     /**
index cc8da79..0889f4a 100644 (file)
@@ -131,6 +131,20 @@ class manager {
         return false;
     }
 
+    /**
+     * Retrieve the reason for implementing the null provider interface.
+     *
+     * @param  string $component Frankenstyle component name.
+     * @return string The key to retrieve the language string for the null provider reason.
+     */
+    public function get_null_provider_reason(string $component) : string {
+        if ($this->component_implements($component, \core_privacy\local\metadata\null_provider::class)) {
+            return $this->get_provider_classname($component)::get_reason();
+        } else {
+            throw new \coding_exception('Call to undefined method', 'Please only call this method on a null provider.');
+        }
+    }
+
     /**
      * Get the privacy metadata for all components.
      *
index ca185a6..5ae8a28 100644 (file)
@@ -409,7 +409,7 @@ class content_writer implements \core_privacy\local\request\content_writer {
                 ];
             }
 
-            $this->customfiles[$this->context->id] = array_replace_recursive($this->customfiles[$this->context->id], $finalcontent);
+            $this->files[$this->context->id] = array_replace_recursive($this->files[$this->context->id], $finalcontent);
         }
 
         return $this;
index 9f341c5..8ef4a54 100644 (file)
@@ -201,4 +201,16 @@ class privacy_manager_testcase extends advanced_testcase {
         $metadata = $manager->get_metadata_for_components();
         $this->assertNotEmpty($metadata);
     }
+
+    /**
+     * Test that the reason for the null provider is returned.
+     */
+    public function test_get_null_provider_reason() {
+        $manager = new \core_privacy\manager();
+        // Null providers return the reason string.
+        $this->assertEquals('testcomponent2 null provider reason', $manager->get_null_provider_reason('mod_testcomponent2'));
+        // Throw an exception if the wrong type of provider is given.
+        $this->expectException(\coding_exception::class);
+        $string = $manager->get_null_provider_reason('mod_testcomponent');
+    }
 }
index e37540d..47bf3a9 100644 (file)
@@ -65,6 +65,34 @@ class qbehaviour_manualgraded extends question_behaviour_with_save {
         }
     }
 
+    /**
+     * Like the parent method, except that when a response is gradable, but not
+     * completely, we move it to the invalid state.
+     * @param question_attempt_pending_step $pendingstep a partially initialised step
+     *      containing all the information about the action that is being performed.
+     * @return bool either {@link question_attempt::KEEP} or {@link question_attempt::DISCARD}
+     */
+    public function process_save(question_attempt_pending_step $pendingstep) {
+        if ($this->qa->get_state()->is_finished()) {
+            return question_attempt::DISCARD;
+        } else if (!$this->qa->get_state()->is_active()) {
+            throw new coding_exception('Question is not active, cannot process_actions.');
+        }
+
+        if ($this->is_same_response($pendingstep)) {
+            return question_attempt::DISCARD;
+        }
+
+        if ($this->is_complete_response($pendingstep)) {
+            $pendingstep->set_state(question_state::$complete);
+        } else if ($this->question->is_gradable_response($pendingstep->get_qt_data())) {
+            $pendingstep->set_state(question_state::$invalid);
+        } else {
+            $pendingstep->set_state(question_state::$todo);
+        }
+        return question_attempt::KEEP;
+    }
+
     public function summarise_action(question_attempt_step $step) {
         if ($step->has_behaviour_var('comment')) {
             return $this->summarise_manual_comment($step);
@@ -81,7 +109,7 @@ class qbehaviour_manualgraded extends question_behaviour_with_save {
         }
 
         $response = $this->qa->get_last_step()->get_qt_data();
-        if (!$this->question->is_complete_response($response)) {
+        if (!$this->question->is_gradable_response($response)) {
             $pendingstep->set_state(question_state::$gaveup);
         } else {
             $pendingstep->set_state(question_state::$needsgrading);
index fb4e5f7..842d10a 100644 (file)
@@ -51,7 +51,7 @@ class backup_qtype_essay_plugin extends backup_qtype_plugin {
         $essay = new backup_nested_element('essay', array('id'), array(
                 'responseformat', 'responserequired', 'responsefieldlines',
                 'attachments', 'attachmentsrequired', 'graderinfo',
-                'graderinfoformat', 'responsetemplate', 'responsetemplateformat'));
+                'graderinfoformat', 'responsetemplate', 'responsetemplateformat', 'filetypeslist'));
 
         // Now the own qtype tree.
         $pluginwrapper->add_child($essay);
index b7abfbd..88314ab 100644 (file)
@@ -17,6 +17,7 @@
         <FIELD NAME="graderinfoformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The text format for graderinfo."/>
         <FIELD NAME="responsetemplate" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The template to pre-populate student's response field during attempt."/>
         <FIELD NAME="responsetemplateformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The text format for responsetemplate."/>
+        <FIELD NAME="filetypeslist" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="What attachment file type a student is allowed to include with their response. * or empty means unlimited."/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
index ec07267..2c29c45 100644 (file)
@@ -30,7 +30,9 @@ defined('MOODLE_INTERNAL') || die();
  * @param int $oldversion the version we are upgrading from.
  */
 function xmldb_qtype_essay_upgrade($oldversion) {
-    global $CFG;
+    global $CFG, $DB;
+
+    $dbman = $DB->get_manager();
 
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
@@ -41,5 +43,19 @@ function xmldb_qtype_essay_upgrade($oldversion) {
     // Automatically generated Moodle v3.4.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2018021800) {
+
+        // Add "filetypeslist" column to the question type options to save the allowed file types.
+        $table = new xmldb_table('qtype_essay_options');
+        $field = new xmldb_field('filetypeslist', XMLDB_TYPE_TEXT, null, null, null, null, null, 'responsetemplateformat');
+
+        // Conditionally launch add field filetypeslist.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Essay savepoint reached.
+        upgrade_plugin_savepoint(true, 2018021800, 'qtype', 'essay');
+    }
     return true;
 }
index d50437b..3f97bd3 100644 (file)
@@ -65,6 +65,10 @@ class qtype_essay_edit_form extends question_edit_form {
         $mform->addHelpButton('attachmentsrequired', 'attachmentsrequired', 'qtype_essay');
         $mform->disabledIf('attachmentsrequired', 'attachments', 'eq', 0);
 
+        $mform->addElement('filetypes', 'filetypeslist', get_string('acceptedfiletypes', 'qtype_essay'));
+        $mform->addHelpButton('filetypeslist', 'acceptedfiletypes', 'qtype_essay');
+        $mform->disabledIf('filetypeslist', 'attachments', 'eq', 0);
+
         $mform->addElement('header', 'responsetemplateheader', get_string('responsetemplateheader', 'qtype_essay'));
         $mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_essay'),
                 array('rows' => 10),  array_merge($this->editoroptions, array('maxfiles' => 0)));
@@ -88,6 +92,7 @@ class qtype_essay_edit_form extends question_edit_form {
         $question->responsefieldlines = $question->options->responsefieldlines;
         $question->attachments = $question->options->attachments;
         $question->attachmentsrequired = $question->options->attachmentsrequired;
+        $question->filetypeslist = $question->options->filetypeslist;
 
         $draftid = file_get_submitted_draft_itemid('graderinfo');
         $question->graderinfo = array();
index 388822a..8a4b689 100644 (file)
@@ -23,6 +23,8 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['acceptedfiletypes'] = 'Accepted file types';
+$string['acceptedfiletypes_help'] = 'Accepted file types can be restricted by entering a list of file extensions. If the field is left empty, then all file types are allowed.';
 $string['allowattachments'] = 'Allow attachments';
 $string['attachmentsoptional'] = 'Attachments are optional';
 $string['attachmentsrequired'] = 'Require attachments';
@@ -38,6 +40,7 @@ $string['mustattach'] = 'When "No online text" is selected, or responses are opt
 $string['mustrequire'] = 'When "No online text" is selected, or responses are optional, you must require at least one attachment.';
 $string['mustrequirefewer'] = 'You cannot require more attachments than you allow.';
 $string['nlines'] = '{$a} lines';
+$string['nonexistentfiletypes'] = 'The following file types were not recognised: {$a}';
 $string['pluginname'] = 'Essay';
 $string['pluginname_help'] = 'In response to a question, the respondent may upload one or more files and/or enter text online. A response template may be provided. Responses must be graded manually.';
 $string['pluginname_link'] = 'question/type/essay';
index 2720e15..0e82bd3 100644 (file)
@@ -52,6 +52,9 @@ class qtype_essay_question extends question_with_responses {
     public $responsetemplate;
     public $responsetemplateformat;
 
+    /** @var array The string array of file types accepted upon file submission. */
+    public $filetypeslist;
+
     public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
         return question_engine::make_behaviour('manualgraded', $qa, $preferredbehaviour);
     }
@@ -98,6 +101,18 @@ class qtype_essay_question extends question_with_responses {
 
         // Determine the number of attachments present.
         if ($hasattachments) {
+            // Check the filetypes.
+            $filetypesutil = new \core_form\filetypes_util();
+            $whitelist = $filetypesutil->normalize_file_types($this->filetypeslist);
+            $wrongfiles = array();
+            foreach ($response['attachments']->get_files() as $file) {
+                if (!$filetypesutil->is_allowed_file_type($file->get_filename(), $whitelist)) {
+                    $wrongfiles[] = $file->get_filename();
+                }
+            }
+            if ($wrongfiles) { // At least one filetype is wrong.
+                return false;
+            }
             $attachcount = count($response['attachments']->get_files());
         } else {
             $attachcount = 0;
@@ -114,6 +129,18 @@ class qtype_essay_question extends question_with_responses {
         return $hascontent && $meetsinlinereq && $meetsattachmentreq;
     }
 
+    public function is_gradable_response(array $response) {
+        // Determine if the given response has online text and attachments.
+        if (array_key_exists('answer', $response) && ($response['answer'] !== '')) {
+            return true;
+        } else if (array_key_exists('attachments', $response)
+                && $response['attachments'] instanceof question_response_files) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     public function is_same_response(array $prevresponse, array $newresponse) {
         if (array_key_exists('answer', $prevresponse) && $prevresponse['answer'] !== $this->responsetemplate) {
             $value1 = (string) $prevresponse['answer'];
index 8e5c580..71f03d8 100644 (file)
@@ -67,6 +67,11 @@ class qtype_essay extends question_type {
         $options->responsefieldlines = $formdata->responsefieldlines;
         $options->attachments = $formdata->attachments;
         $options->attachmentsrequired = $formdata->attachmentsrequired;
+        if (!isset($formdata->filetypeslist)) {
+            $options->filetypeslist = "";
+        } else {
+            $options->filetypeslist = $formdata->filetypeslist;
+        }
         $options->graderinfo = $this->import_or_save_files($formdata->graderinfo,
                 $context, 'qtype_essay', 'graderinfo', $formdata->id);
         $options->graderinfoformat = $formdata->graderinfo['format'];
@@ -86,6 +91,8 @@ class qtype_essay extends question_type {
         $question->graderinfoformat = $questiondata->options->graderinfoformat;
         $question->responsetemplate = $questiondata->options->responsetemplate;
         $question->responsetemplateformat = $questiondata->options->responsetemplateformat;
+        $filetypesutil = new \core_form\filetypes_util();
+        $question->filetypeslist = $filetypesutil->normalize_file_types($questiondata->options->filetypeslist);
     }
 
     public function delete_question($questionid, $contextid) {
index 9b04c49..5f649f2 100644 (file)
@@ -119,12 +119,22 @@ class qtype_essay_renderer extends qtype_renderer {
 
         $pickeroptions->itemid = $qa->prepare_response_files_draft_itemid(
                 'attachments', $options->context->id);
+        $pickeroptions->accepted_types = $qa->get_question()->filetypeslist;
 
         $fm = new form_filemanager($pickeroptions);
         $filesrenderer = $this->page->get_renderer('core', 'files');
+
+        $text = '';
+        if (!empty($qa->get_question()->filetypeslist)) {
+            $text = html_writer::tag('p', get_string('acceptedfiletypes', 'qtype_essay'));
+            $filetypesutil = new \core_form\filetypes_util();
+            $filetypes = $qa->get_question()->filetypeslist;
+            $filetypedescriptions = $filetypesutil->describe_file_types($filetypes);
+            $text .= $this->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions);
+        }
         return $filesrenderer->render($fm). html_writer::empty_tag(
                 'input', array('type' => 'hidden', 'name' => $qa->get_qt_field_name('attachments'),
-                'value' => $pickeroptions->itemid));
+                'value' => $pickeroptions->itemid)) . $text;
     }
 
     public function manual_comment(question_attempt $qa, question_display_options $options) {
diff --git a/question/type/essay/tests/behat/file_type_restriction.feature b/question/type/essay/tests/behat/file_type_restriction.feature
new file mode 100644 (file)
index 0000000..a8a476f
--- /dev/null
@@ -0,0 +1,75 @@
+@qtype @qtype_essay
+Feature: In a essay question, limit submittable file types
+In order to constrain student submissions for marking
+As a teacher
+I need to limit the submittable file types
+
+  Background:
+    Given the following "users" exist:
+      | username | firstname | lastname | email                |
+      | teacher1 | Teacher   | 1        | teacher1@example.com |
+      | student1 | Student   | 1        | student0@example.com |
+    And the following "courses" exist:
+      | fullname | shortname | category |
+      | Course 1 | C1        | 0        |
+    And the following "course enrolments" exist:
+      | user     | course | role           |
+      | teacher1 | C1     | editingteacher |
+      | student1 | C1     | student        |
+    And the following "question categories" exist:
+      | contextlevel | reference | name           |
+      | Course       | C1        | Test questions |
+    And the following "questions" exist:
+      | questioncategory | qtype       | name  | questiontext    | defaultmark |
+      | Test questions   | essay       | TF1   | First question  | 20          |
+    And the following "activities" exist:
+      | activity   | name   | intro              | course | idnumber | grade |
+      | quiz       | Quiz 1 | Quiz 1 description | C1     | quiz1    | 20    |
+    And quiz "Quiz 1" contains the following questions:
+      | question | page |
+      | TF1      | 1    |
+    Given I log in as "teacher1"
+    And I am on "Course 1" course homepage
+    And I follow "Quiz 1"
+    And I navigate to "Edit quiz" in current page administration
+    And I click on "Edit question TF1" "link"
+    And I set the field "Allow attachments" to "1"
+    And I set the field "Response format" to "No online text"
+    And I set the field "Require attachments" to "1"
+    And I set the field "filetypeslist[filetypes]" to ".txt"
+    And I press "Save changes"
+    Then I log out
+
+  @javascript @_file_upload
+  Scenario: Preview an Essay question and submit a response with a correct filetype.
+    When I log in as "student1"
+    And I follow "Manage private files"
+    And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
+    And I press "Save changes"
+    And I am on "Course 1" course homepage
+    And I follow "Quiz 1"
+    And I press "Attempt quiz now"
+    And I should see "First question"
+    And I should see "You can drag and drop files here to add them."
+    And I click on "Add..." "button"
+    And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+    And I click on "empty.txt" "link"
+    And I click on "Select this file" "button"
+    # Wait for the page to "settle".
+    And I wait until the page is ready
+    Then I should not see "These file types are not allowed here:"
+
+  @javascript @_file_upload
+  Scenario: Preview an Essay question and try to submit a response with an incorrect filetype.
+    When I log in as "student1"
+    And I follow "Manage private files"
+    And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager
+    And I press "Save changes"
+    And I am on "Course 1" course homepage
+    And I follow "Quiz 1"
+    And I press "Attempt quiz now"
+    And I should see "First question"
+    And I should see "You can drag and drop files here to add them."
+    And I click on "Add..." "button"
+    And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+    Then I should see "No files available"
index 4782ff6..d925ffb 100644 (file)
@@ -27,6 +27,7 @@
     <responsefieldlines>15</responsefieldlines>
     <attachments>0</attachments>
     <attachmentsrequired>0</attachmentsrequired>
+    <filetypeslist></filetypeslist>
     <graderinfo format="html">
       <text></text>
     </graderinfo>
index 07dd4e0..c759bbd 100644 (file)
@@ -53,6 +53,7 @@ class qtype_essay_test_helper extends question_test_helper {
         $q->responsefieldlines = 10;
         $q->attachments = 0;
         $q->attachmentsrequired = 0;
+        $q->filetypeslist = '';
         $q->graderinfo = '';
         $q->graderinfoformat = FORMAT_HTML;
         $q->qtype = question_bank::get_qtype('essay');
@@ -87,6 +88,7 @@ class qtype_essay_test_helper extends question_test_helper {
         $fromform->responsefieldlines = 10;
         $fromform->attachments = 0;
         $fromform->attachmentsrequired = 0;
+        $fromform->filetypeslist = '';
         $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
         $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
 
@@ -105,6 +107,19 @@ class qtype_essay_test_helper extends question_test_helper {
         return $q;
     }
 
+    /**
+     * Makes an essay question using the HTML editor allowing embedded files as
+     * input, and up to two attachments, two needed.
+     * @return qtype_essay_question
+     */
+    public function make_essay_question_editorfilepickertworequired() {
+        $q = $this->initialise_essay_question();
+        $q->responseformat = 'editorfilepicker';
+        $q->attachments = 2;
+        $q->attachmentsrequired = 2;
+        return $q;
+    }
+
     /**
      * Make the data what would be received from the editing form for an essay
      * question using the HTML editor allowing embedded files as input, and up
@@ -124,6 +139,7 @@ class qtype_essay_test_helper extends question_test_helper {
         $fromform->responsefieldlines = 10;
         $fromform->attachments = 3;
         $fromform->attachmentsrequired = 0;
+        $fromform->filetypeslist = '';
         $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
         $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
 
@@ -159,6 +175,7 @@ class qtype_essay_test_helper extends question_test_helper {
         $fromform->responsefieldlines = 10;
         $fromform->attachments = 0;
         $fromform->attachmentsrequired = 0;
+        $fromform->filetypeslist = '';
         $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
         $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
 
@@ -191,6 +208,7 @@ class qtype_essay_test_helper extends question_test_helper {
         $q->responseformat = 'noinline';
         $q->attachments = 3;
         $q->attachmentsrequired = 1;
+        $q->filetypeslist = '';
         return $q;
     }
 
index d398946..a1a9bb9 100644 (file)
@@ -501,4 +501,122 @@ class qtype_essay_walkthrough_testcase extends qbehaviour_walkthrough_test_base
         // Test for the hash of an empty file area.
         $this->assertNotContains('d41d8cd98f00b204e9800998ecf8427e', $this->currentoutput);
     }
+
+    public function test_deferred_feedback_html_editor_with_files_attempt_wrong_filetypes() {
+        global $CFG, $USER, $PAGE;
+
+        $this->resetAfterTest(true);
+        $this->setAdminUser();
+        // Required to init a text editor.
+        $PAGE->set_url('/');
+        $usercontextid = context_user::instance($USER->id)->id;
+        $fs = get_file_storage();
+
+        // Create an essay question in the DB.
+        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
+        $cat = $generator->create_question_category();
+        $question = $generator->create_question('essay', 'editorfilepicker', array('category' => $cat->id));
+
+        // Start attempt at the question.
+        $q = question_bank::load_question($question->id);
+        $q->filetypeslist = ("pdf, docx");
+        $this->start_attempt_at_question($q, 'deferredfeedback', 1);
+
+        $this->check_current_state(question_state::$todo);
+        $this->check_current_mark(null);
+        $this->check_step_count(1);
+
+        // Process a response and check the expected result.
+        // First we need to get the draft item ids.
+        $this->render();
+        if (!preg_match('/env=editor&amp;.*?itemid=(\d+)&amp;/', $this->currentoutput, $matches)) {
+            throw new coding_exception('Editor draft item id not found.');
+        }
+        $editordraftid = $matches[1];
+        if (!preg_match('/env=filemanager&amp;action=browse&amp;.*?itemid=(\d+)&amp;/', $this->currentoutput, $matches)) {
+            throw new coding_exception('File manager draft item id not found.');
+        }
+        $attachementsdraftid = $matches[1];
+
+        $this->save_file_to_draft_area($usercontextid, $editordraftid, 'smile.txt', ':-)');
+        $this->save_file_to_draft_area($usercontextid, $attachementsdraftid, 'greeting.txt', 'Hello world!');
+        $this->process_submission(array(
+            'answer' => 'Here is a picture: <img src="' . $CFG->wwwroot .
+                "/draftfile.php/{$usercontextid}/user/draft/{$editordraftid}/smile.txt" .
+                '" alt="smile">.',
+            'answerformat' => FORMAT_HTML,
+            'answer:itemid' => $editordraftid,
+            'attachments' => $attachementsdraftid));
+
+        $this->check_current_state(question_state::$invalid);
+        $this->check_current_mark(null);
+        $this->check_step_count(2);
+        $this->save_quba();
+
+        // Now submit all and finish.
+        $this->finish();
+        $this->check_current_state(question_state::$needsgrading);
+        $this->check_current_mark(null);
+        $this->check_step_count(3);
+        $this->save_quba();
+    }
+
+    public function test_deferred_feedback_html_editor_with_files_attempt_correct_filetypes() {
+        global $CFG, $USER, $PAGE;
+
+        $this->resetAfterTest(true);
+        $this->setAdminUser();
+        // Required to init a text editor.
+        $PAGE->set_url('/');
+        $usercontextid = context_user::instance($USER->id)->id;
+        $fs = get_file_storage();
+
+        // Create an essay question in the DB.
+        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
+        $cat = $generator->create_question_category();
+        $question = $generator->create_question('essay', 'editorfilepicker', array('category' => $cat->id));
+
+        // Start attempt at the question.
+        $q = question_bank::load_question($question->id);
+        $q->filetypeslist = ("txt, docx");
+        $this->start_attempt_at_question($q, 'deferredfeedback', 1);
+
+        $this->check_current_state(question_state::$todo);
+        $this->check_current_mark(null);
+        $this->check_step_count(1);
+
+        // Process a response and check the expected result.
+        // First we need to get the draft item ids.
+        $this->render();
+        if (!preg_match('/env=editor&amp;.*?itemid=(\d+)&amp;/', $this->currentoutput, $matches)) {
+            throw new coding_exception('Editor draft item id not found.');
+        }
+        $editordraftid = $matches[1];
+        if (!preg_match('/env=filemanager&amp;action=browse&amp;.*?itemid=(\d+)&amp;/', $this->currentoutput, $matches)) {
+            throw new coding_exception('File manager draft item id not found.');
+        }
+        $attachementsdraftid = $matches[1];
+
+        $this->save_file_to_draft_area($usercontextid, $editordraftid, 'smile.txt', ':-)');
+        $this->save_file_to_draft_area($usercontextid, $attachementsdraftid, 'greeting.txt', 'Hello world!');
+        $this->process_submission(array(
+            'answer' => 'Here is a picture: <img src="' . $CFG->wwwroot .
+                "/draftfile.php/{$usercontextid}/user/draft/{$editordraftid}/smile.txt" .
+                '" alt="smile">.',
+            'answerformat' => FORMAT_HTML,
+            'answer:itemid' => $editordraftid,
+            'attachments' => $attachementsdraftid));
+
+        $this->check_current_state(question_state::$complete);
+        $this->check_current_mark(null);
+        $this->check_step_count(2);
+        $this->save_quba();
+
+        // Now submit all and finish.
+        $this->finish();
+        $this->check_current_state(question_state::$needsgrading);
+        $this->check_current_mark(null);
+        $this->check_step_count(3);
+        $this->save_quba();
+    }
 }
index c578e51..7512f57 100644 (file)
@@ -26,7 +26,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'qtype_essay';
-$plugin->version   = 2017111300;
+$plugin->version   = 2018021800;
 
 $plugin->requires  = 2017110800;
 
index b6a4b89..32dbcf8 100644 (file)
@@ -468,6 +468,17 @@ class question_information_item extends question_definition {
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 interface question_manually_gradable {
+    /**
+     * Use by many of the behaviours to determine whether the student
+     * has provided enough of an answer for the question to be graded automatically,
+     * or whether it must be considered aborted.
+     *
+     * @param array $response responses, as returned by
+     *      {@link question_attempt_step::get_qt_data()}.
+     * @return bool whether this response can be graded.
+     */
+    public function is_gradable_response(array $response);
+
     /**
      * Used by many of the behaviours, to work out whether the student's
      * response to the question is complete. That is, whether the question attempt
@@ -554,17 +565,6 @@ class question_classified_response {
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 interface question_automatically_gradable extends question_manually_gradable {
-    /**
-     * Use by many of the behaviours to determine whether the student
-     * has provided enough of an answer for the question to be graded automatically,
-     * or whether it must be considered aborted.
-     *
-     * @param array $response responses, as returned by
-     *      {@link question_attempt_step::get_qt_data()}.
-     * @return bool whether this response can be graded.
-     */
-    public function is_gradable_response(array $response);
-
     /**
      * In situations where is_gradable_response() returns false, this method
      * should generate a description of what the problem is.
@@ -637,6 +637,10 @@ abstract class question_with_responses extends question_definition
     public function classify_response(array $response) {
         return array();
     }
+
+    public function is_gradable_response(array $response) {
+        return $this->is_complete_response($response);
+    }
 }
 
 
@@ -651,10 +655,6 @@ abstract class question_graded_automatically extends question_with_responses
     /** @var Some question types have the option to show the number of sub-parts correct. */
     public $shownumcorrect = false;
 
-    public function is_gradable_response(array $response) {
-        return $this->is_complete_response($response);
-    }
-
     public function get_right_answer_summary() {
         $correctresponse = $this->get_correct_response();
         if (empty($correctresponse)) {
index 8bb92a8..c9a70f3 100644 (file)
@@ -1,9 +1,13 @@
 This files describes API changes for question type plugins.
 
-== 3.5 ==
+=== 3.5 ===
   + Added new classes backup_qtype_extrafields_plugin and restore_qtype_extrafields_plugin
    in order to use extra fields method in backup/restore question type. Require and inherit new classes for using it. See
    backup_qtype_shortanswer_plugin and restore_qtype_shortanswer_plugin for an example of using this.
+  + The declaration of is_gradable_response has been moved from question_automatically_gradable to
+   question_manually_gradable.
+  + The default implementation of is_gradable_response has been moved from question_graded_automatically to
+   question_with_responses.
 
 === 3.1.5, 3.2.2, 3.3 ===
 
index 48e7ea3..102f052 100644 (file)
@@ -1392,7 +1392,8 @@ M.core_filepicker.init = function(Y, options) {
             // processing repository listing
             // Resort the repositories by sortorder
             var sorted_repositories = [];
-            for (var i in this.options.repositories) {
+            var i;
+            for (i in this.options.repositories) {
                 sorted_repositories[i] = this.options.repositories[i];
             }
             sorted_repositories.sort(function(a,b){return a.sortorder-b.sortorder});
@@ -1404,6 +1405,10 @@ M.core_filepicker.init = function(Y, options) {
                 list.removeChild(reponode);
                 for (i in sorted_repositories) {
                     var repository = sorted_repositories[i];
+                    var h = (parseInt(i) == 0) ? parseInt(i) : parseInt(i) - 1,
+                        j = (parseInt(i) == Object.keys(sorted_repositories).length - 1) ? parseInt(i) : parseInt(i) + 1;
+                    var previousrepository = sorted_repositories[h];
+                    var nextrepository = sorted_repositories[j];
                     var node = reponode.cloneNode(true);
                     list.appendChild(node);
                     node.
@@ -1414,6 +1419,15 @@ M.core_filepicker.init = function(Y, options) {
                             this.hide_header();
                             this.list({'repo_id':repository_id});
                         }, this /*handler running scope*/, repository.id/*second argument of handler*/);
+                    node.on('key', function(e, previousrepositoryid, nextrepositoryid, clientid, repositoryid) {
+                        this.changeHighlightedRepository(e, clientid, repositoryid, previousrepositoryid, nextrepositoryid);
+                    }, 'down:38,40', this, previousrepository.id, nextrepository.id, client_id, repository.id);
+                    node.on('key', function(e, repositoryid) {
+                        e.preventDefault();
+                        this.set_preference('recentrepository', repositoryid);
+                        this.hide_header();
+                        this.list({'repo_id': repositoryid});
+                    }, 'enter', this, repository.id);
                     node.one('.fp-repo-name').setContent(Y.Escape.html(repository.name));
                     node.one('.fp-repo-icon').set('src', repository.icon);
                     if (i==0) {
@@ -1437,6 +1451,23 @@ M.core_filepicker.init = function(Y, options) {
             this.mainui.show();
             this.show_recent_repository();
         },
+        /**
+         * Change the highlighted repository to a new one.
+         *
+         * @param  {object} event The key event
+         * @param  {integer} clientid The client id to identify the repo class.
+         * @param  {integer} oldrepositoryid The repository id that we are removing the highlight for
+         * @param  {integer} previousrepositoryid The previous repository id.
+         * @param  {integer} nextrepositoryid The next repository id.
+         */
+        changeHighlightedRepository: function(event, clientid, oldrepositoryid, previousrepositoryid, nextrepositoryid) {
+            event.preventDefault();
+            var newrepositoryid = (event.keyCode == '40') ? nextrepositoryid : previousrepositoryid;
+            this.fpnode.one('#fp-repo-' + clientid + '-' + oldrepositoryid).setAttribute('tabindex', '-1');
+            this.fpnode.one('#fp-repo-' + clientid + '-' + newrepositoryid)
+                    .setAttribute('tabindex', '0')
+                    .focus();
+        },
         parse_repository_options: function(data, appendtolist) {
             if (appendtolist) {
                 if (data.list) {
@@ -1608,8 +1639,19 @@ M.core_filepicker.init = function(Y, options) {
         display_response: function(id, obj, args) {
             var scope = args.scope;
             // highlight the current repository in repositories list
-            scope.fpnode.all('.fp-repo.active').removeClass('active');
-            scope.fpnode.all('#fp-repo-'+scope.options.client_id+'-'+obj.repo_id).addClass('active')
+            scope.fpnode.all('.fp-repo.active')
+                    .removeClass('active')
+                    .setAttribute('aria-selected', 'false')
+                    .setAttribute('tabindex', '-1');
+            scope.fpnode.all('.nav-link')
+                    .removeClass('active')
+                    .setAttribute('aria-selected', 'false')
+                    .setAttribute('tabindex', '-1');
+            var activenode = scope.fpnode.one('#fp-repo-' + scope.options.client_id + '-' + obj.repo_id);
+            activenode.addClass('active')
+                    .setAttribute('aria-selected', 'true')
+                    .setAttribute('tabindex', '0');
+            activenode.all('.nav-link').addClass('active');
             // add class repository_REPTYPE to the filepicker (for repository-specific styles)
             for (var i in scope.options.repositories) {
                 scope.fpnode.removeClass('repository_'+scope.options.repositories[i].type)
index f55f2d0..3e31b35 100644 (file)
@@ -1,7 +1,7 @@
 <div tabindex="0" class="file-picker fp-generallayout container-fluid row" role="dialog" aria-live="assertive">
-    <div class="fp-repo-area col-md-3 nav nav-pills nav-stacked">
-            <div class="fp-repo nav-item">
-                <a href="#" class="nav-link"><img class="fp-repo-icon" alt=" " width="16" height="16" />&nbsp;<span class="fp-repo-name"></span></a>
+    <div class="fp-repo-area col-md-3 nav nav-pills nav-stacked" role="tablist">
+            <div class="fp-repo nav-item" role="tab" aria-selected="false" tabindex="-1">
+                <a href="#" class="nav-link" tabindex="-1"><img class="fp-repo-icon" alt=" " src="#" width="16" height="16" />&nbsp;<span class="fp-repo-name"></span></a>
             </div>
 
     </div>