diff --git a/lib/filelib.php b/lib/filelib.php index 20112a00a5f..d2779ced516 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -4650,7 +4650,18 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin if (!plugin_supports('mod', $modname, FEATURE_MOD_INTRO, true)) { send_file_not_found(); } - require_course_login($course, true, $cm); + + // Require login to the course first (without login to the module). + require_course_login($course, true); + + // Now check if module is available OR it is restricted but the intro is shown on the course page. + $cminfo = cm_info::create($cm); + if (!$cminfo->uservisible) { + if (!$cm->showdescription || !$cminfo->is_visible_on_course_page()) { + // Module intro is not visible on the course page and module is not available, show access error. + require_course_login($course, true, $cminfo); + } + } // all users may access it $filename = array_pop($args); diff --git a/mod/label/db/upgrade.php b/mod/label/db/upgrade.php index 679da8db394..9ccf306dfa8 100644 --- a/mod/label/db/upgrade.php +++ b/mod/label/db/upgrade.php @@ -45,7 +45,7 @@ defined('MOODLE_INTERNAL') || die; function xmldb_label_upgrade($oldversion) { - global $CFG; + global $CFG, $DB; // Moodle v3.1.0 release upgrade line. // Put any upgrade step following this. @@ -56,5 +56,16 @@ function xmldb_label_upgrade($oldversion) { // Automatically generated Moodle v3.3.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2017062800) { + // Update all records in 'course_modules' for labels to have showdescription = 1. + if ($modid = $DB->get_field('modules', 'id', ['name' => 'label'])) { + $DB->execute("UPDATE {course_modules} SET showdescription = ? WHERE module = ?", + [1, $modid]); + } + + // Label savepoint reached. + upgrade_mod_savepoint(true, 2017062800, 'label'); + } + return true; } diff --git a/mod/label/mod_form.php b/mod/label/mod_form.php index 7c54cb122bf..a892fd2fd00 100644 --- a/mod/label/mod_form.php +++ b/mod/label/mod_form.php @@ -36,6 +36,10 @@ class mod_label_mod_form extends moodleform_mod { $mform->addElement('header', 'generalhdr', get_string('general')); $this->standard_intro_elements(get_string('labeltext', 'label')); + // Label does not add "Show description" checkbox meaning that 'intro' is always shown on the course page. + $mform->addElement('hidden', 'showdescription', 1); + $mform->setType('showdescription', PARAM_INT); + $this->standard_coursemodule_elements(); //------------------------------------------------------------------------------- diff --git a/mod/label/tests/generator/lib.php b/mod/label/tests/generator/lib.php index 0ed413176bb..465305617ce 100644 --- a/mod/label/tests/generator/lib.php +++ b/mod/label/tests/generator/lib.php @@ -35,5 +35,10 @@ defined('MOODLE_INTERNAL') || die(); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mod_label_generator extends testing_module_generator { - // No additional fields in label module. + + public function create_instance($record = null, array $options = null) { + $record = (array)$record; + $record['showdescription'] = 1; + return parent::create_instance($record, $options); + } } diff --git a/mod/label/version.php b/mod/label/version.php index 6344e4bf7fb..cad0c0c95a1 100644 --- a/mod/label/version.php +++ b/mod/label/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017051500; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2017062800; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2017050500; // Requires this Moodle version $plugin->component = 'mod_label'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0;