mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-66740 core_course: change defaults for course request settings
This commit is contained in:
parent
3e15abe500
commit
959e4f0e97
@ -163,9 +163,15 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
|
||||
|
||||
// "courserequests" settingpage.
|
||||
$temp = new admin_settingpage('courserequest', new lang_string('courserequest'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablecourserequests', new lang_string('enablecourserequests', 'admin'), new lang_string('configenablecourserequests', 'admin'), 0));
|
||||
$temp->add(new admin_settings_coursecat_select('defaultrequestcategory', new lang_string('defaultrequestcategory', 'admin'), new lang_string('configdefaultrequestcategory', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('requestcategoryselection', new lang_string('requestcategoryselection', 'admin'), new lang_string('configrequestcategoryselection', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('enablecourserequests',
|
||||
new lang_string('enablecourserequests', 'admin'),
|
||||
new lang_string('configenablecourserequests', 'admin'), 1));
|
||||
$temp->add(new admin_settings_coursecat_select('defaultrequestcategory',
|
||||
new lang_string('defaultrequestcategory', 'admin'),
|
||||
new lang_string('configdefaultrequestcategory', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('lockrequestcategory',
|
||||
new lang_string('lockrequestcategory', 'admin'),
|
||||
new lang_string('configlockrequestcategory', 'admin'), 0));
|
||||
$temp->add(new admin_setting_users_with_capability('courserequestnotify', new lang_string('courserequestnotify', 'admin'), new lang_string('configcourserequestnotify2', 'admin'), array(), 'moodle/site:approvecourse'));
|
||||
$ADMIN->add('courses', $temp);
|
||||
|
||||
|
@ -2838,7 +2838,7 @@ class course_request {
|
||||
$data->requester = $USER->id;
|
||||
|
||||
// Setting the default category if none set.
|
||||
if (empty($data->category) || empty($CFG->requestcategoryselection)) {
|
||||
if (empty($data->category) || !empty($CFG->lockrequestcategory)) {
|
||||
$data->category = $CFG->defaultrequestcategory;
|
||||
}
|
||||
|
||||
@ -3167,7 +3167,7 @@ class course_request {
|
||||
return $defaultcontext &&
|
||||
has_capability('moodle/course:request', $defaultcontext);
|
||||
} else if ($context instanceof context_coursecat) {
|
||||
if ($CFG->requestcategoryselection || $CFG->defaultrequestcategory == $context->instanceid) {
|
||||
if (!$CFG->lockrequestcategory || $CFG->defaultrequestcategory == $context->instanceid) {
|
||||
return has_capability('moodle/course:request', $context);
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ if (empty($CFG->enablecourserequests)) {
|
||||
print_error('courserequestdisabled', '', $returnurl);
|
||||
}
|
||||
|
||||
if (!$CFG->requestcategoryselection) {
|
||||
// Category selection is not enabled, user will always request in the default request category.
|
||||
if ($CFG->lockrequestcategory) {
|
||||
// Course request category is locked, user will always request in the default request category.
|
||||
$categoryid = null;
|
||||
} else if (!$categoryid) {
|
||||
// Category selection is enabled but category is not specified.
|
||||
|
@ -68,7 +68,7 @@ class course_request_form extends moodleform {
|
||||
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
|
||||
$mform->setType('shortname', PARAM_TEXT);
|
||||
|
||||
if (!empty($CFG->requestcategoryselection)) {
|
||||
if (empty($CFG->lockrequestcategory)) {
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:request');
|
||||
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->setDefault('category', $CFG->defaultrequestcategory);
|
||||
|
@ -17,7 +17,10 @@ Feature: Users can request and approve courses
|
||||
| user2 | Acceptance test site | manager |
|
||||
Given I log in as "admin"
|
||||
And I set the following administration settings values:
|
||||
| enablecourserequests | 1 |
|
||||
| lockrequestcategory | 1 |
|
||||
And I set the following system permissions of "Authenticated user" role:
|
||||
| capability | permission |
|
||||
| moodle/course:request | Allow |
|
||||
And I log out
|
||||
When I log in as "user1"
|
||||
And I am on course index
|
||||
@ -65,12 +68,6 @@ Feature: Users can request and approve courses
|
||||
| user2 | manager | Category | SCI |
|
||||
| user3 | manager | Category | ENG |
|
||||
Given I log in as "admin"
|
||||
And I set the following administration settings values:
|
||||
| enablecourserequests | 1 |
|
||||
| requestcategoryselection | 1 |
|
||||
And I set the following system permissions of "Authenticated user" role:
|
||||
| capability | permission |
|
||||
| moodle/course:request | Prevent |
|
||||
And I set the following system permissions of "Course requestor" role:
|
||||
| capability | permission |
|
||||
| moodle/course:request | Allow |
|
||||
|
@ -6816,7 +6816,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
* Tests for the course_request::can_request
|
||||
*/
|
||||
public function test_can_request_course() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@ -6828,18 +6828,29 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$context3 = context_coursecat::instance($cat3);
|
||||
$this->setUser($user);
|
||||
|
||||
// By default course request is not available.
|
||||
// By default users don't have capability to request courses.
|
||||
$this->assertFalse(course_request::can_request(context_system::instance()));
|
||||
$this->assertFalse(course_request::can_request($context1));
|
||||
$this->assertFalse(course_request::can_request($context2));
|
||||
$this->assertFalse(course_request::can_request($context3));
|
||||
|
||||
// Enable course requests. Default 'user' role has capability to request courses.
|
||||
$CFG->enablecourserequests = true;
|
||||
// Allow for the 'user' role the capability to request courses.
|
||||
$userroleid = $DB->get_field('role', 'id', ['shortname' => 'user']);
|
||||
assign_capability('moodle/course:request', CAP_ALLOW, $userroleid,
|
||||
context_system::instance()->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
// Lock category selection.
|
||||
$CFG->lockrequestcategory = 1;
|
||||
|
||||
// Now user can only request course in the default category or in system context.
|
||||
$this->assertTrue(course_request::can_request(context_system::instance()));
|
||||
$this->assertTrue(course_request::can_request($context1));
|
||||
$this->assertFalse(course_request::can_request($context2));
|
||||
$this->assertFalse(course_request::can_request($context3));
|
||||
|
||||
// Enable category selection.
|
||||
$CFG->requestcategoryselection = 1;
|
||||
// Enable category selection. User can request course anywhere.
|
||||
$CFG->lockrequestcategory = 0;
|
||||
$this->assertTrue(course_request::can_request(context_system::instance()));
|
||||
$this->assertTrue(course_request::can_request($context1));
|
||||
$this->assertTrue(course_request::can_request($context2));
|
||||
@ -6856,6 +6867,13 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$this->assertTrue(course_request::can_request($context1));
|
||||
$this->assertFalse(course_request::can_request($context2));
|
||||
$this->assertTrue(course_request::can_request($context3));
|
||||
|
||||
// Disable course request functionality.
|
||||
$CFG->enablecourserequests = false;
|
||||
$this->assertFalse(course_request::can_request(context_system::instance()));
|
||||
$this->assertFalse(course_request::can_request($context1));
|
||||
$this->assertFalse(course_request::can_request($context2));
|
||||
$this->assertFalse(course_request::can_request($context3));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6873,7 +6891,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
|
||||
// Enable course requests. Default 'user' role has capability to request courses.
|
||||
$CFG->enablecourserequests = true;
|
||||
$CFG->requestcategoryselection = 1;
|
||||
$CFG->lockrequestcategory = 0;
|
||||
$this->setUser($requestor);
|
||||
$requestdata = ['summary_editor' => ['text' => '', 'format' => 0], 'name' => 'Req', 'reason' => 'test'];
|
||||
$request1 = course_request::create((object)($requestdata));
|
||||
|
@ -37,7 +37,7 @@ class core_course_courserequest_testcase extends advanced_testcase {
|
||||
|
||||
$defaultcategory = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
|
||||
set_config('enablecourserequests', 1);
|
||||
set_config('requestcategoryselection', 0);
|
||||
set_config('lockrequestcategory', 1);
|
||||
set_config('defaultrequestcategory', $defaultcategory);
|
||||
|
||||
// Create some categories.
|
||||
@ -70,7 +70,7 @@ class core_course_courserequest_testcase extends advanced_testcase {
|
||||
|
||||
// Request with category different than default and category selection allowed.
|
||||
set_config('defaultrequestcategory', $cat3->id);
|
||||
set_config('requestcategoryselection', 1);
|
||||
set_config('lockrequestcategory', 0);
|
||||
$data->category = $cat1->id;
|
||||
$cr = course_request::create($data);
|
||||
$this->assertEquals($cat1->id, $cr->category);
|
||||
@ -83,14 +83,20 @@ class core_course_courserequest_testcase extends advanced_testcase {
|
||||
|
||||
$defaultcategory = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
|
||||
set_config('enablecourserequests', 1);
|
||||
set_config('requestcategoryselection', 0);
|
||||
set_config('lockrequestcategory', 1);
|
||||
set_config('defaultrequestcategory', $defaultcategory);
|
||||
|
||||
// Create some categories.
|
||||
$cat1 = $this->getDataGenerator()->create_category();
|
||||
$cat2 = $this->getDataGenerator()->create_category();
|
||||
|
||||
// Create a user and allow course requests for him.
|
||||
$requester = $this->getDataGenerator()->create_user();
|
||||
$roleid = create_role('Course requestor role', 'courserequestor', '');
|
||||
assign_capability('moodle/course:request', CAP_ALLOW, $roleid,
|
||||
context_system::instance()->id);
|
||||
role_assign($roleid, $requester->id, context_system::instance()->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$data = new stdClass();
|
||||
$data->fullname = 'Həllo World!';
|
||||
@ -116,7 +122,7 @@ class core_course_courserequest_testcase extends advanced_testcase {
|
||||
$this->assertEquals($defaultcategory, $course->category);
|
||||
|
||||
// Test with category.
|
||||
set_config('requestcategoryselection', 1);
|
||||
set_config('lockrequestcategory', 0);
|
||||
set_config('defaultrequestcategory', $cat2->id);
|
||||
$data->shortname .= ' 2nd';
|
||||
$data->category = $cat1->id;
|
||||
@ -138,10 +144,16 @@ class core_course_courserequest_testcase extends advanced_testcase {
|
||||
|
||||
$this->setAdminUser();
|
||||
set_config('enablecourserequests', 1);
|
||||
set_config('requestcategoryselection', 0);
|
||||
set_config('lockrequestcategory', 1);
|
||||
set_config('defaultrequestcategory', $DB->get_field_select('course_categories', "MIN(id)", "parent=0"));
|
||||
|
||||
// Create a user and allow course requests for him.
|
||||
$requester = $this->getDataGenerator()->create_user();
|
||||
$roleid = create_role('Course requestor role', 'courserequestor', '');
|
||||
assign_capability('moodle/course:request', CAP_ALLOW, $roleid,
|
||||
context_system::instance()->id);
|
||||
role_assign($roleid, $requester->id, context_system::instance()->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$data = new stdClass();
|
||||
$data->fullname = 'Həllo World!';
|
||||
|
@ -203,7 +203,7 @@ $string['configdebugdisplay'] = 'Set to on, the error reporting will go to the H
|
||||
$string['configdebugpageinfo'] = 'Enable if you want page information printed in page footer.';
|
||||
$string['configdebugvalidators'] = 'Enable if you want to have links to external validator servers in page footer. You may need to create new user with username <em>w3cvalidator</em>, and enable guest access. These changes may allow unauthorized access to server, do not enable on production sites!';
|
||||
$string['configdefaulthomepage'] = 'This determines the first link in the navigation for logged-in users.';
|
||||
$string['configdefaultrequestcategory'] = 'Courses requested by users will be automatically placed in this category.';
|
||||
$string['configdefaultrequestcategory'] = 'Courses requested by users will be placed in this category if the category is not specified.';
|
||||
$string['configdefaultrequestedcategory'] = 'Default category to put courses that were requested into, if they\'re approved.';
|
||||
$string['configdefaultuserroleid'] = 'All logged in users will be given the capabilities of the role you specify here, at the site level, in ADDITION to any other roles they may have been given. The default is the Authenticated user role. Note that this will not conflict with other roles they have unless you prohibit capabilities, it just ensures that all users have capabilities that are not assignable at the course level (eg post blog entries, manage own calendar, etc).';
|
||||
$string['configdeleteincompleteusers'] = 'After this period, any account without the first name, last name or email field filled in is deleted.';
|
||||
@ -225,7 +225,7 @@ $string['configemailfromvia'] = 'Add via information in the "From" section of ou
|
||||
$string['configemailsubjectprefix'] = 'Text to be prefixed to the subject line of all outgoing mail.';
|
||||
$string['configenablecalendarexport'] = 'Enable exporting or subscribing to calendars.';
|
||||
$string['configenablecomments'] = 'Enable comments';
|
||||
$string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
|
||||
$string['configenablecourserequests'] = 'Enable course request functionality. Users with capability to request courses but without capability to create courses will be able to request courses.';
|
||||
$string['configenablemobilewebservice'] = 'Enable mobile service for the official Moodle app or other app requesting it. For more information, read the {$a}';
|
||||
$string['configenablerssfeeds'] = 'If enabled, RSS feeds are generated by various features across the site, such as blogs, forums, database activities and glossaries. Note that RSS feeds also need to be enabled for the particular activity modules.';
|
||||
$string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.';
|
||||
@ -270,6 +270,7 @@ $string['configlanglist'] = 'If left blank, all languages installed on the site
|
||||
$string['configlangmenu'] = 'Choose whether or not you want to display the general-purpose language menu on the home page, login page etc. This does not affect the user\'s ability to set the preferred language in their own profile.';
|
||||
$string['configlatinexcelexport'] = 'Choose the encoding for Excel exports.';
|
||||
$string['configlocale'] = 'Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left blank.';
|
||||
$string['configlockrequestcategory'] = 'Only allow course requests in the default course request category. This is a legacy setting, it is better not to use it but instead assign capability to request courses in the appropriate course category context';
|
||||
$string['configloglifetime'] = 'This specifies the length of time you want to keep logs about user activity. Logs that are older than this age are automatically deleted. It is best to keep logs as long as possible, in case you need them, but if you have a very busy server and are experiencing performance problems, then you may want to lower the log lifetime. Values lower than 30 are not recommended because statistics may not work properly.';
|
||||
$string['configlookahead'] = 'Days to look ahead';
|
||||
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
|
||||
@ -317,7 +318,6 @@ $string['configproxytype'] = 'Type of web proxy (PHP5 and cURL extension require
|
||||
$string['configproxyuser'] = 'Username needed to access internet through proxy if required, empty if none (PHP cURL extension required).';
|
||||
$string['configrecaptchaprivatekey'] = 'String of characters (secret key) used to communicate between your Moodle server and the recaptcha server. ReCAPTCHA keys can be obtained from <a target="_blank" href="https://www.google.com/recaptcha">Google reCAPTCHA</a>.';
|
||||
$string['configrecaptchapublickey'] = 'String of characters (site key) used to display the reCAPTCHA element in the signup form. ReCAPTCHA keys can be obtained from <a target="_blank" href="https://www.google.com/recaptcha">Google reCAPTCHA</a>.';
|
||||
$string['configrequestcategoryselection'] = 'Allow the selection of a category when requesting a course.';
|
||||
$string['configrequestedstudentname'] = 'Word for student used in requested courses';
|
||||
$string['configrequestedstudentsname'] = 'Word for students used in requested courses';
|
||||
$string['configrequestedteachername'] = 'Word for teacher used in requested courses';
|
||||
@ -716,6 +716,7 @@ $string['lockoutthreshold'] = 'Account lockout threshold';
|
||||
$string['lockoutthreshold_desc'] = 'Select number of failed login attempts that result in account lockout. This feature may be abused in denial of service attacks.';
|
||||
$string['lockoutwindow'] = 'Account lockout observation window';
|
||||
$string['lockoutwindow_desc'] = 'Observation time for lockout threshold, if there are no failed attempts the threshold counter is reset after this time.';
|
||||
$string['lockrequestcategory'] = 'Lock category for the course requests';
|
||||
$string['log'] = 'Logs';
|
||||
$string['logguests'] = 'Log guest access';
|
||||
$string['logguests_help'] = 'This setting enables logging of actions by guest account and not logged in users. High profile sites may want to disable this logging for performance reasons. It is recommended to keep this setting enabled on production sites.';
|
||||
@ -1045,7 +1046,6 @@ $string['purgeselectedcaches'] = 'Purge selected caches';
|
||||
$string['purgeselectedcachesfinished'] = 'The selected caches were purged.';
|
||||
$string['purgetemplates'] = 'Templates';
|
||||
$string['purgethemecache'] = 'Themes';
|
||||
$string['requestcategoryselection'] = 'Enable category selection';
|
||||
$string['restorecourse'] = 'Restore course';
|
||||
$string['restorernewroleid'] = 'Restorers\' role in courses';
|
||||
$string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';
|
||||
@ -1436,3 +1436,5 @@ $string['registermoodleorg'] = 'When you register your site';
|
||||
$string['registermoodleorgli1'] = 'You are added to a low-volume mailing list for important notifications such as security alerts and new releases of Moodle.';
|
||||
$string['registermoodleorgli2'] = 'Statistics about your site will be added to the {$a} of the worldwide Moodle community.';
|
||||
$string['registerwithmoodleorg'] = 'Register your site';
|
||||
$string['configrequestcategoryselection'] = 'Allow the selection of a category when requesting a course.';
|
||||
$string['requestcategoryselection'] = 'Enable category selection';
|
||||
|
@ -115,3 +115,5 @@ completeregistration,core_hub
|
||||
registersite,core_hub
|
||||
updatesite,core_hub
|
||||
unregisterexplained,core_hub
|
||||
configrequestcategoryselection,core_admin
|
||||
requestcategoryselection,core_admin
|
@ -783,9 +783,6 @@ $capabilities = array(
|
||||
'moodle/course:request' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSECAT,
|
||||
'archetypes' => array(
|
||||
'user' => CAP_ALLOW,
|
||||
)
|
||||
),
|
||||
|
||||
'moodle/course:delete' => array(
|
||||
|
@ -3609,5 +3609,13 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2019100900.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2019101200.01) {
|
||||
|
||||
// Change the setting $CFG->requestcategoryselection into $CFG->lockrequestcategory with opposite value.
|
||||
set_config('lockrequestcategory', !$CFG->requestcategoryselection);
|
||||
|
||||
upgrade_main_savepoint(true, 2019101200.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019101200.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019101200.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user