mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-66740-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
6d98de3fc1
@ -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);
|
||||
|
||||
|
@ -2973,11 +2973,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
|
||||
* @return bool
|
||||
*/
|
||||
public function can_request_course() {
|
||||
global $CFG;
|
||||
if (empty($CFG->enablecourserequests) || $this->id != $CFG->defaultrequestcategory) {
|
||||
return false;
|
||||
}
|
||||
return !$this->can_create_course() && has_capability('moodle/course:request', $this->get_context());
|
||||
return course_request::can_request($this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -664,7 +664,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
}
|
||||
if ($category->can_request_course()) {
|
||||
// Request a new course.
|
||||
$url = new moodle_url('/course/request.php', array('return' => 'management'));
|
||||
$url = new moodle_url('/course/request.php', array('category' => $category->id, 'return' => 'management'));
|
||||
$actions[] = html_writer::link($url, get_string('requestcourse'));
|
||||
}
|
||||
if ($category->can_resort_courses()) {
|
||||
|
@ -752,16 +752,21 @@ function make_categories_options() {
|
||||
/**
|
||||
* Print the buttons relating to course requests.
|
||||
*
|
||||
* @param object $context current page context.
|
||||
* @param context $context current page context.
|
||||
*/
|
||||
function print_course_request_buttons($context) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
if (empty($CFG->enablecourserequests)) {
|
||||
return;
|
||||
}
|
||||
if (!has_capability('moodle/course:create', $context) && has_capability('moodle/course:request', $context)) {
|
||||
/// Print a button to request a new course
|
||||
echo $OUTPUT->single_button(new moodle_url('/course/request.php'), get_string('requestcourse'), 'get');
|
||||
if (course_request::can_request($context)) {
|
||||
// Print a button to request a new course.
|
||||
$params = [];
|
||||
if ($context instanceof context_coursecat) {
|
||||
$params['category'] = $context->instanceid;
|
||||
}
|
||||
echo $OUTPUT->single_button(new moodle_url('/course/request.php', $params),
|
||||
get_string('requestcourse'), 'get');
|
||||
}
|
||||
/// Print a button to manage pending requests
|
||||
if (has_capability('moodle/site:approvecourse', $context)) {
|
||||
@ -2833,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;
|
||||
}
|
||||
|
||||
@ -2972,6 +2977,31 @@ class course_request {
|
||||
return $this->properties->collision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks user capability to approve a requested course
|
||||
*
|
||||
* If course was requested without category for some reason (might happen if $CFG->defaultrequestcategory is
|
||||
* misconfigured), we check capabilities 'moodle/site:approvecourse' and 'moodle/course:changecategory'.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_approve() {
|
||||
global $CFG;
|
||||
$category = null;
|
||||
if ($this->properties->category) {
|
||||
$category = core_course_category::get($this->properties->category, IGNORE_MISSING);
|
||||
} else if ($CFG->defaultrequestcategory) {
|
||||
$category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING);
|
||||
}
|
||||
if ($category) {
|
||||
return has_capability('moodle/site:approvecourse', $category->get_context());
|
||||
}
|
||||
|
||||
// We can not determine the context where the course should be created. The approver should have
|
||||
// both capabilities to approve courses and change course category in the system context.
|
||||
return has_all_capabilities(['moodle/site:approvecourse', 'moodle/course:changecategory'], context_system::instance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category where this course request should be created
|
||||
*
|
||||
@ -2983,17 +3013,14 @@ class course_request {
|
||||
*/
|
||||
public function get_category() {
|
||||
global $CFG;
|
||||
// If the category is not set, if the current user does not have the rights to change the category, or if the
|
||||
// category does not exist, we set the default category to the course to be approved.
|
||||
// The system level is used because the capability moodle/site:approvecourse is based on a system level.
|
||||
if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) ||
|
||||
(!$category = core_course_category::get($this->properties->category, IGNORE_MISSING, true))) {
|
||||
$category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING, true);
|
||||
if ($this->properties->category && ($category = core_course_category::get($this->properties->category, IGNORE_MISSING))) {
|
||||
return $category;
|
||||
} else if ($CFG->defaultrequestcategory &&
|
||||
($category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING))) {
|
||||
return $category;
|
||||
} else {
|
||||
return core_course_category::get_default();
|
||||
}
|
||||
if (!$category) {
|
||||
$category = core_course_category::get_default();
|
||||
}
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3119,6 +3146,33 @@ class course_request {
|
||||
$eventdata->notification = 1;
|
||||
message_send($eventdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current user can request a course in this context
|
||||
*
|
||||
* @param context $context
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_request(context $context) {
|
||||
global $CFG;
|
||||
if (empty($CFG->enablecourserequests)) {
|
||||
return false;
|
||||
}
|
||||
if (has_capability('moodle/course:create', $context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($context instanceof context_system) {
|
||||
$defaultcontext = context_coursecat::instance($CFG->defaultrequestcategory, IGNORE_MISSING);
|
||||
return $defaultcontext &&
|
||||
has_capability('moodle/course:request', $defaultcontext);
|
||||
} else if ($context instanceof context_coursecat) {
|
||||
if (!$CFG->lockrequestcategory || $CFG->defaultrequestcategory == $context->instanceid) {
|
||||
return has_capability('moodle/course:request', $context);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,20 @@ $approve = optional_param('approve', 0, PARAM_INT);
|
||||
$reject = optional_param('reject', 0, PARAM_INT);
|
||||
|
||||
$baseurl = $CFG->wwwroot . '/course/pending.php';
|
||||
admin_externalpage_setup('coursespending');
|
||||
$context = context_system::instance();
|
||||
if (has_capability('moodle/site:approvecourse', $context)) {
|
||||
// Similar to course management capabilities, if user has approve capability in system context
|
||||
// we add the link to the admin menu. Otherwise we check if user has capability anywhere.
|
||||
admin_externalpage_setup('coursespending');
|
||||
} else {
|
||||
require_login(null, false);
|
||||
$categories = core_course_category::make_categories_list('moodle/site:approvecourse');
|
||||
if (!$categories) {
|
||||
require_capability('moodle/site:approvecourse', $context);
|
||||
}
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url(new moodle_url('/course/pending.php'));
|
||||
}
|
||||
|
||||
/// Process approval of a course.
|
||||
if (!empty($approve) and confirm_sesskey()) {
|
||||
@ -48,7 +61,11 @@ if (!empty($approve) and confirm_sesskey()) {
|
||||
$courseid = $course->approve();
|
||||
|
||||
if ($courseid !== false) {
|
||||
redirect(new moodle_url('/course/edit.php', ['id' => $courseid, 'returnto' => 'pending']));
|
||||
if (has_capability('moodle/course:update', context_course::instance($courseid))) {
|
||||
redirect(new moodle_url('/course/edit.php', ['id' => $courseid, 'returnto' => 'pending']));
|
||||
} else {
|
||||
redirect(new moodle_url('/course/view.php', ['id' => $courseid]));
|
||||
}
|
||||
} else {
|
||||
print_error('courseapprovedfailed');
|
||||
}
|
||||
@ -109,6 +126,9 @@ if (empty($pending)) {
|
||||
// Check here for shortname collisions and warn about them.
|
||||
$course->check_shortname_collision();
|
||||
|
||||
if (!$course->can_approve()) {
|
||||
continue;
|
||||
}
|
||||
$category = $course->get_category();
|
||||
|
||||
$row = array();
|
||||
|
@ -30,6 +30,7 @@ require_once($CFG->dirroot . '/course/request_form.php');
|
||||
// Where we came from. Used in a number of redirects.
|
||||
$url = new moodle_url('/course/request.php');
|
||||
$return = optional_param('return', null, PARAM_ALPHANUMEXT);
|
||||
$categoryid = optional_param('category', null, PARAM_INT);
|
||||
if ($return === 'management') {
|
||||
$url->param('return', $return);
|
||||
$returnurl = new moodle_url('/course/management.php', array('categoryid' => $CFG->defaultrequestcategory));
|
||||
@ -47,12 +48,24 @@ if (isguestuser()) {
|
||||
if (empty($CFG->enablecourserequests)) {
|
||||
print_error('courserequestdisabled', '', $returnurl);
|
||||
}
|
||||
$context = context_system::instance();
|
||||
|
||||
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.
|
||||
// Find a category where user has capability to request courses (preferably the default category).
|
||||
$list = core_course_category::make_categories_list('moodle/course:request');
|
||||
$categoryid = array_key_exists($CFG->defaultrequestcategory, $list) ? $CFG->defaultrequestcategory : key($list);
|
||||
}
|
||||
|
||||
$context = context_coursecat::instance($categoryid ?: $CFG->defaultrequestcategory);
|
||||
$PAGE->set_context($context);
|
||||
require_capability('moodle/course:request', $context);
|
||||
|
||||
// Set up the form.
|
||||
$data = course_request::prepare();
|
||||
$data = $categoryid ? (object)['category' => $categoryid] : null;
|
||||
$data = course_request::prepare($data);
|
||||
$requestform = new course_request_form($url);
|
||||
$requestform->set_data($data);
|
||||
|
||||
|
@ -68,8 +68,8 @@ class course_request_form extends moodleform {
|
||||
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
|
||||
$mform->setType('shortname', PARAM_TEXT);
|
||||
|
||||
if (!empty($CFG->requestcategoryselection)) {
|
||||
$displaylist = core_course_category::make_categories_list();
|
||||
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);
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
|
106
course/tests/behat/course_request.feature
Normal file
106
course/tests/behat/course_request.feature
Normal file
@ -0,0 +1,106 @@
|
||||
@core @core_course
|
||||
Feature: Users can request and approve courses
|
||||
As a moodle admin
|
||||
In order to improve course creation process
|
||||
I need to be able to enable course approval
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| user1 | User | 1 | user1@example.com |
|
||||
| user2 | User | 2 | user2@example.com |
|
||||
| user3 | User | 3 | user3@example.com |
|
||||
|
||||
Scenario: Simple course request workflow
|
||||
Given the following "system role assigns" exist:
|
||||
| user | course | role |
|
||||
| user2 | Acceptance test site | manager |
|
||||
Given I log in as "admin"
|
||||
And I set the following administration settings values:
|
||||
| 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
|
||||
And I press "Request a course"
|
||||
And I set the following fields to these values:
|
||||
| Course full name | My new course |
|
||||
| Course short name | Mynewcourse |
|
||||
| Supporting information | pretty please |
|
||||
And I press "Request a course"
|
||||
And I should see "Your course request has been saved successfully."
|
||||
And I press "Continue"
|
||||
And I am on course index
|
||||
And I should not see "My new course"
|
||||
And I log out
|
||||
And I log in as "user2"
|
||||
And I am on course index
|
||||
And I press "Courses pending approval"
|
||||
And I should see "Miscellaneous" in the "My new course" "table_row"
|
||||
And I click on "Approve" "button" in the "My new course" "table_row"
|
||||
And I press "Save and return"
|
||||
And I should see "There are no courses pending approval"
|
||||
And I press "Back to course listing"
|
||||
And I should see "My new course"
|
||||
And I log out
|
||||
And I log in as "user1"
|
||||
And I am on course index
|
||||
And I follow "My new course"
|
||||
And I navigate to course participants
|
||||
And I should see "Teacher" in the "User 1" "table_row"
|
||||
And I log out
|
||||
|
||||
Scenario: Course request with category selection
|
||||
Given the following "categories" exist:
|
||||
| name | category | idnumber |
|
||||
| Science category | 0 | SCI |
|
||||
| English category | 0 | ENG |
|
||||
| Other category | 0 | MISC |
|
||||
Given the following "roles" exist:
|
||||
| name | shortname | description | archetype |
|
||||
| Course requestor | courserequestor | My custom role 1 | |
|
||||
And the following "role assigns" exist:
|
||||
| user | role | contextlevel | reference |
|
||||
| user1 | courserequestor | Category | SCI |
|
||||
| user1 | courserequestor | Category | ENG |
|
||||
| user2 | manager | Category | SCI |
|
||||
| user3 | manager | Category | ENG |
|
||||
Given I log in as "admin"
|
||||
And I set the following system permissions of "Course requestor" role:
|
||||
| capability | permission |
|
||||
| moodle/course:request | Allow |
|
||||
And I log out
|
||||
And I log in as "user1"
|
||||
And I am on course index
|
||||
And I follow "English category"
|
||||
And I press "Request a course"
|
||||
And the field "Course category" matches value "English category"
|
||||
And I set the following fields to these values:
|
||||
| Course full name | My new course |
|
||||
| Course short name | Mynewcourse |
|
||||
| Supporting information | pretty please |
|
||||
And I press "Request a course"
|
||||
And I log out
|
||||
And I log in as "user2"
|
||||
And I am on course index
|
||||
And I follow "English category"
|
||||
And "Courses pending approval" "button" should not exist
|
||||
And I am on course index
|
||||
And I follow "Science category"
|
||||
And I press "Courses pending approval"
|
||||
And I should not see "Mynewcourse"
|
||||
And I press "Back to course listing"
|
||||
And I log out
|
||||
And I log in as "user3"
|
||||
And I am on course index
|
||||
And I follow "English category"
|
||||
And I press "Courses pending approval"
|
||||
And I should see "English category" in the "Mynewcourse" "table_row"
|
||||
And I click on "Approve" "button" in the "Mynewcourse" "table_row"
|
||||
And I press "Save and return"
|
||||
And I am on course index
|
||||
And I follow "English category"
|
||||
And I should see "My new course"
|
||||
And I log out
|
@ -6811,4 +6811,110 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
course_delete_module($moduleinstances[$indextodelete]->cmid, true); // Try to delete the instance asynchronously.
|
||||
$this->assertEquals($expected, course_modules_pending_deletion($course->id, $gradable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the course_request::can_request
|
||||
*/
|
||||
public function test_can_request_course() {
|
||||
global $CFG, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$cat1 = $CFG->defaultrequestcategory;
|
||||
$cat2 = $this->getDataGenerator()->create_category()->id;
|
||||
$cat3 = $this->getDataGenerator()->create_category()->id;
|
||||
$context1 = context_coursecat::instance($cat1);
|
||||
$context2 = context_coursecat::instance($cat2);
|
||||
$context3 = context_coursecat::instance($cat3);
|
||||
$this->setUser($user);
|
||||
|
||||
// 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));
|
||||
|
||||
// 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. 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));
|
||||
$this->assertTrue(course_request::can_request($context3));
|
||||
|
||||
// Remove cap from cat2.
|
||||
$roleid = create_role('Test role', 'testrole', 'Test role description');
|
||||
assign_capability('moodle/course:request', CAP_PROHIBIT, $roleid,
|
||||
$context2->id, true);
|
||||
role_assign($roleid, $user->id, $context2->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->assertTrue(course_request::can_request(context_system::instance()));
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the course_request::can_approve
|
||||
*/
|
||||
public function test_can_approve_course_request() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$requestor = $this->getDataGenerator()->create_user();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$cat1 = $CFG->defaultrequestcategory;
|
||||
$cat2 = $this->getDataGenerator()->create_category()->id;
|
||||
$cat3 = $this->getDataGenerator()->create_category()->id;
|
||||
|
||||
// Enable course requests. Default 'user' role has capability to request courses.
|
||||
$CFG->enablecourserequests = true;
|
||||
$CFG->lockrequestcategory = 0;
|
||||
$this->setUser($requestor);
|
||||
$requestdata = ['summary_editor' => ['text' => '', 'format' => 0], 'name' => 'Req', 'reason' => 'test'];
|
||||
$request1 = course_request::create((object)($requestdata));
|
||||
$request2 = course_request::create((object)($requestdata + ['category' => $cat2]));
|
||||
$request3 = course_request::create((object)($requestdata + ['category' => $cat3]));
|
||||
|
||||
$this->setUser($user);
|
||||
// Add capability to approve courses.
|
||||
$roleid = create_role('Test role', 'testrole', 'Test role description');
|
||||
assign_capability('moodle/site:approvecourse', CAP_ALLOW, $roleid,
|
||||
context_system::instance()->id, true);
|
||||
role_assign($roleid, $user->id, context_coursecat::instance($cat2)->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->assertFalse($request1->can_approve());
|
||||
$this->assertTrue($request2->can_approve());
|
||||
$this->assertFalse($request3->can_approve());
|
||||
|
||||
// Delete category where course was requested. Now only site-wide manager can approve it.
|
||||
core_course_category::get($cat2, MUST_EXIST, true)->delete_full(false);
|
||||
$this->assertFalse($request2->can_approve());
|
||||
|
||||
$this->setAdminUser();
|
||||
$this->assertTrue($request2->can_approve());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -133,7 +133,7 @@ $capabilities = array(
|
||||
'riskbitmask' => RISK_XSS,
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'contextlevel' => CONTEXT_COURSECAT,
|
||||
'archetypes' => array(
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
@ -782,10 +782,7 @@ $capabilities = array(
|
||||
|
||||
'moodle/course:request' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => array(
|
||||
'user' => CAP_ALLOW,
|
||||
)
|
||||
'contextlevel' => CONTEXT_COURSECAT,
|
||||
),
|
||||
|
||||
'moodle/course:delete' => array(
|
||||
|
@ -3611,5 +3611,13 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2019100900.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2019101600.01) {
|
||||
|
||||
// Change the setting $CFG->requestcategoryselection into $CFG->lockrequestcategory with opposite value.
|
||||
set_config('lockrequestcategory', !$CFG->requestcategoryselection);
|
||||
|
||||
upgrade_main_savepoint(true, 2019101600.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019101600.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019101600.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