From cc0bb815ad639415ccb132de39a2f0666208de4c Mon Sep 17 00:00:00 2001 From: Eric Merrill Date: Tue, 24 Sep 2013 08:35:19 -0400 Subject: [PATCH] MDL-41940 files Option to limit legacy course files Adding an option that prevents users from adding new files or directories to legacy course files. Helps with weaning users from them. --- admin/settings/plugins.php | 1 + files/coursefilesedit_form.php | 11 +++++++- files/tests/behat/course_files.feature | 38 ++++++++++++++++++++++++++ lang/en/admin.php | 2 ++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 files/tests/behat/course_files.feature diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 19bace3728f..a4ef423f082 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -251,6 +251,7 @@ if ($hassiteconfig) { $temp->add(new admin_setting_configtext('repositorycacheexpire', new lang_string('cacheexpire', 'repository'), new lang_string('configcacheexpire', 'repository'), 120)); $temp->add(new admin_setting_configcheckbox('repositoryallowexternallinks', new lang_string('allowexternallinks', 'repository'), new lang_string('configallowexternallinks', 'repository'), 1)); $temp->add(new admin_setting_configcheckbox('legacyfilesinnewcourses', new lang_string('legacyfilesinnewcourses', 'admin'), new lang_string('legacyfilesinnewcourses_help', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('legacyfilesaddallowed', new lang_string('legacyfilesaddallowed', 'admin'), new lang_string('legacyfilesaddallowed_help', 'admin'), 1)); $ADMIN->add('repositorysettings', $temp); $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew', new lang_string('addplugin', 'repository'), $url, 'moodle/site:config', true)); diff --git a/files/coursefilesedit_form.php b/files/coursefilesedit_form.php index e1311f0e5d1..bc57f1833e5 100644 --- a/files/coursefilesedit_form.php +++ b/files/coursefilesedit_form.php @@ -19,9 +19,18 @@ require_once($CFG->libdir.'/formslib.php'); class coursefiles_edit_form extends moodleform { function definition() { + global $CFG; + + $maxfiles = 0; + $subdirs = 0; + if ($CFG->legacyfilesaddallowed) { + $maxfiles = -1; + $subdirs = 1; + } + $mform =& $this->_form; $contextid = $this->_customdata['contextid']; - $options = array('subdirs'=>1, 'maxfiles'=>-1, 'accepted_types'=>'*'); + $options = array('subdirs' => $subdirs, 'maxfiles' => $maxfiles, 'accepted_types'=>'*'); $mform->addElement('filemanager', 'files_filemanager', '', null, $options); $mform->addElement('hidden', 'contextid', $this->_customdata['contextid']); $mform->setType('contextid', PARAM_INT); diff --git a/files/tests/behat/course_files.feature b/files/tests/behat/course_files.feature new file mode 100644 index 00000000000..169527521db --- /dev/null +++ b/files/tests/behat/course_files.feature @@ -0,0 +1,38 @@ +@files @files_course @_only_local +Feature: Course files + In order to add legacy files + As a user + I need to upload files + + @javascript + Scenario: Add legacy files + Given the following "courses" exists: + | fullname | shortname | category | legacyfiles | + | Course 1 | C1 | 0 | 2 | + And I log in as "admin" + And I set the following administration settings values: + | Legacy course files in new courses | 1 | + And I follow "Home" + And I follow "Course 1" + Then I should see "Legacy course files" + And I follow "Legacy course files" + And I press "Edit legacy course files" + Then I should see "Add..." + Then I should see "Create folder" + + @javascript + Scenario: Add legacy file disabled + Given the following "courses" exists: + | fullname | shortname | category | legacyfiles | + | Course 1 | C1 | 0 | 2 | + And I log in as "admin" + And I set the following administration settings values: + | Legacy course files in new courses | 1 | + | Allow adding to legacy course files | 1 | + And I follow "Home" + And I follow "Course 1" + Then I should see "Legacy course files" + And I follow "Legacy course files" + And I press "Edit legacy course files" + Then I should not see "Add..." + Then I should not see "Create folder" diff --git a/lang/en/admin.php b/lang/en/admin.php index 71a73d89c36..ab883e6c5ec 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -621,6 +621,8 @@ $string['languagesettings'] = 'Language settings'; $string['latexpreamble'] = 'LaTeX preamble'; $string['latexsettings'] = 'LaTeX renderer Settings'; $string['latinexcelexport'] = 'Excel encoding'; +$string['legacyfilesaddallowed'] = 'Allow adding to legacy course files'; +$string['legacyfilesaddallowed_help'] = 'If a course has legacy course files, allow new files and folders to be added to it.'; $string['legacyfilesinnewcourses'] = 'Legacy course files in new courses'; $string['legacyfilesinnewcourses_help'] = 'By default legacy course files areas are available only in upgraded courses. Please note some features like single activity backup/restore are not compatible with this settings.'; $string['licensesettings'] = 'Licence settings';