mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-69559 course: Add course setting and cap to control course downloads
This commit is contained in:
parent
d661b1148b
commit
840bcd8810
@ -120,6 +120,27 @@ class course_edit_form extends moodleform {
|
||||
$mform->setConstant('visible', $courseconfig->visible);
|
||||
}
|
||||
}
|
||||
|
||||
// Download course content.
|
||||
if ($CFG->downloadcoursecontentallowed) {
|
||||
$downloadchoices = [
|
||||
DOWNLOAD_COURSE_CONTENT_DISABLED => get_string('no'),
|
||||
DOWNLOAD_COURSE_CONTENT_ENABLED => get_string('yes'),
|
||||
];
|
||||
$sitedefaultstring = $downloadchoices[$courseconfig->downloadcontentsitedefault];
|
||||
$downloadchoices[DOWNLOAD_COURSE_CONTENT_SITE_DEFAULT] = get_string('sitedefaultspecified', '', $sitedefaultstring);
|
||||
$downloadselectdefault = $courseconfig->downloadcontent ?? DOWNLOAD_COURSE_CONTENT_SITE_DEFAULT;
|
||||
|
||||
$mform->addElement('select', 'downloadcontent', get_string('enabledownloadcoursecontent', 'course'), $downloadchoices);
|
||||
$mform->addHelpButton('downloadcontent', 'downloadcoursecontent', 'course');
|
||||
$mform->setDefault('downloadcontent', $downloadselectdefault);
|
||||
|
||||
if (!has_capability('moodle/course:configuredownloadcontent', $coursecontext)) {
|
||||
$mform->hardFreeze('downloadcontent');
|
||||
$mform->setConstant('downloadcontent', $downloadselectdefault);
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('date_time_selector', 'startdate', get_string('startdate'));
|
||||
$mform->addHelpButton('startdate', 'startdate');
|
||||
$date = (new DateTime())->setTimestamp(usergetmidnight(time()));
|
||||
|
47
course/tests/behat/course_download_content.feature
Normal file
47
course/tests/behat/course_download_content.feature
Normal file
@ -0,0 +1,47 @@
|
||||
@core @core_course
|
||||
Feature: Course content can be downloaded
|
||||
In order to retain a backup offline copy of course activity/resource data
|
||||
As a user
|
||||
I can download a course's content
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Hockey 101 | C1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "admin"
|
||||
And I navigate to "Courses > Courses > Download course content" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Download course content feature available | 1 |
|
||||
And I press "Save changes"
|
||||
And I navigate to "Courses > Courses > Course default settings" in site administration
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: A student can download course content when the feature is enabled in their course
|
||||
Given I log in as "student1"
|
||||
When I am on "Hockey 101" course homepage
|
||||
And "Download course content" "button" should exist
|
||||
And I press "Download course content"
|
||||
Then I should see "You are about to download a zip file"
|
||||
# Without the ability to check the downloaded file, the absence of an exception being thrown here is considered a success.
|
||||
And I click on "Download" "button" in the "Download course content" "dialogue"
|
||||
|
||||
@javascript
|
||||
Scenario: A teacher can download course content when the feature is enabled in their course
|
||||
Given I log in as "teacher1"
|
||||
When I am on "Hockey 101" course homepage
|
||||
And "Download course content" "link" should exist in current page administration
|
||||
And I navigate to "Download course content" in current page administration
|
||||
Then I should see "You are about to download a zip file"
|
||||
# Without the ability to check the downloaded file, the absence of an exception being thrown here is considered a success.
|
||||
And I click on "Download" "button" in the "Download course content" "dialogue"
|
112
course/tests/behat/course_download_content_permissions.feature
Normal file
112
course/tests/behat/course_download_content_permissions.feature
Normal file
@ -0,0 +1,112 @@
|
||||
@core @core_course
|
||||
Feature: Access to downloading course content can be controlled
|
||||
In order to allow or restrict access to download course content
|
||||
As a trusted user
|
||||
I can control access to the download course content feature
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Hockey 101 | C1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "admin"
|
||||
And the following config values are set as admin:
|
||||
| downloadcoursecontentallowed | 1 |
|
||||
And I log out
|
||||
|
||||
Scenario: Site admins can remove the download course content feature
|
||||
Given I log in as "admin"
|
||||
And I am on "Hockey 101" course homepage
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save and display"
|
||||
And "Download course content" "link" should exist in current page administration
|
||||
When the following config values are set as admin:
|
||||
| downloadcoursecontentallowed | 0 |
|
||||
And I am on "Hockey 101" course homepage
|
||||
Then "Download course content" "link" should not exist in current page administration
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I should not see "Enable download course content"
|
||||
|
||||
Scenario: Site admins can set the default value for whether download course content is enabled in courses
|
||||
Given I log in as "admin"
|
||||
And I am on "Hockey 101" course homepage
|
||||
And "Download course content" "link" should not exist in current page administration
|
||||
When I navigate to "Courses > Courses > Course default settings" in site administration
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save changes"
|
||||
And I am on "Hockey 101" course homepage
|
||||
Then "Download course content" "link" should exist in current page administration
|
||||
|
||||
Scenario: A teacher can enable and disable the download course content feature when it is available
|
||||
Given I log in as "teacher1"
|
||||
When I am on "Hockey 101" course homepage
|
||||
And "Download course content" "link" should not exist in current page administration
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I should see "Enable download course content"
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save and display"
|
||||
Then "Download course content" "link" should exist in current page administration
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I set the field "Enable download course content" to "No"
|
||||
And I press "Save and display"
|
||||
And "Download course content" "link" should not exist in current page administration
|
||||
|
||||
Scenario: Teachers require a capability to access the download course content feature or modify its availability in a course
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Courses > Courses > Course default settings" in site administration
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
# Check teacher can see download option and enable dropdown.
|
||||
And I log in as "teacher1"
|
||||
And I am on "Hockey 101" course homepage
|
||||
And "Download course content" "link" should exist in current page administration
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And "Enable download course content" "select" should exist
|
||||
And I log out
|
||||
# Remove teacher's capabilities for download course content.
|
||||
And I log in as "admin"
|
||||
And I set the following system permissions of "Teacher" role:
|
||||
| capability | permission |
|
||||
| moodle/course:downloadcoursecontent | Prohibit |
|
||||
| moodle/course:configuredownloadcontent | Prohibit |
|
||||
And I log out
|
||||
# Check teacher can no longer see download option, and that enable value is visible, but dropdown no longer available.
|
||||
When I log in as "teacher1"
|
||||
And I am on "Hockey 101" course homepage
|
||||
Then "Download course content" "link" should not exist in current page administration
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I should see "Enable download course content"
|
||||
And I should see "Site default (Yes)"
|
||||
And "Enable download course content" "select" should not exist
|
||||
|
||||
Scenario: Students require a capability to access the download course content feature in a course
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Hockey 101" course homepage
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I set the field "Enable download course content" to "Yes"
|
||||
And I press "Save and display"
|
||||
And I log out
|
||||
# Check student can see download button.
|
||||
And I log in as "student1"
|
||||
And I am on "Hockey 101" course homepage
|
||||
And "Download course content" "button" should exist
|
||||
And I log out
|
||||
And I log in as "admin"
|
||||
# Remove student's capability for download course content.
|
||||
When I set the following system permissions of "Student" role:
|
||||
| capability | permission |
|
||||
| moodle/course:downloadcoursecontent | Prohibit |
|
||||
And I log out
|
||||
# Check student can no longer see download button.
|
||||
And I log in as "student1"
|
||||
And I am on "Hockey 101" course homepage
|
||||
Then "Download course content" "link" should not exist in current page administration
|
@ -1930,6 +1930,7 @@ $string['since'] = 'Since';
|
||||
$string['sincelast'] = 'since last login';
|
||||
$string['site'] = 'Site';
|
||||
$string['sitedefault'] = 'Site default';
|
||||
$string['sitedefaultspecified'] = 'Site default ({$a})';
|
||||
$string['siteerrors'] = 'Site errors';
|
||||
$string['sitefiles'] = 'Site files';
|
||||
$string['sitefilesused'] = 'Site files used in this course';
|
||||
|
@ -172,6 +172,7 @@ $string['course:changelockedcustomfields'] = 'Change locked custom fields';
|
||||
$string['course:changeshortname'] = 'Change course short name';
|
||||
$string['course:changesummary'] = 'Change course summary';
|
||||
$string['course:configurecustomfields'] = 'Configure custom fields';
|
||||
$string['course:configuredownloadcontent'] = 'Configure download course content';
|
||||
$string['course:downloadcoursecontent'] = 'Download course content';
|
||||
$string['course:enrolconfig'] = 'Configure enrol instances in courses';
|
||||
$string['course:enrolreview'] = 'Review course enrolments';
|
||||
|
@ -2588,4 +2588,14 @@ $capabilities = array(
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
],
|
||||
|
||||
// Allow users to configure download course content functionality within a course, if the feature is available.
|
||||
'moodle/course:configuredownloadcontent' => [
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'archetypes' => array(
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
],
|
||||
);
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20201007" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20201021" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -89,6 +89,7 @@
|
||||
<FIELD NAME="showreports" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
|
||||
<FIELD NAME="visibleold" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="the state of visible field when hiding parent category, this helps us to recover hidden states when unhiding the parent category later"/>
|
||||
<FIELD NAME="downloadcontent" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="groupmode" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="groupmodeforce" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="defaultgroupingid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="default grouping used in course modules, does not have key intentionally"/>
|
||||
@ -4322,4 +4323,4 @@
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
@ -2774,6 +2774,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
|
||||
// Add example field.
|
||||
$field = new xmldb_field('example', XMLDB_TYPE_TEXT, null, null, null, null, null, 'tutorial');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
@ -2862,5 +2863,18 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2021052500.30);
|
||||
}
|
||||
|
||||
if ($oldversion < 2021052500.32) {
|
||||
// Define field downloadcontent to be added to course.
|
||||
$table = new xmldb_table('course');
|
||||
$field = new xmldb_field('downloadcontent', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'visibleold');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2021052500.32);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2021052500.31; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2021052500.32; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '4.0dev (Build: 20201023)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user