} else {
$userrole->id = 0;
}
+if (empty($CFG->creatornewroleid)) {
+ if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, $context)) {
+ $teachereditrole = array_shift($teacherroles);
+ set_config('creatornewroleid', $teachereditrole->id);
+ } else {
+ set_config('creatornewroleid', 0);
+ }
+}
// we must not use assignable roles here:
// 1/ unsetting roles as assignable for admin might bork the settings!
// 2/ default user role should not be assignable anyway
get_string('configdefaultuserroleid', 'admin'), $userrole->id, $allroles));
$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $allroles));
+$temp->add(new admin_setting_configselect('creatornewroleid', get_string('creatornewroleid', 'admin'),
+ get_string('configcreatornewroleid', 'admin'), $CFG->creatornewroleid, $allroles));
$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$data->fullname (ID $course->id)") ;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
- if ($data->metacourse and has_capability('moodle/course:managemetacourse', $context)) { // Redirect users with metacourse capability to student import
+ // assign default role to creator if not already having permission to manage course assignments
+ if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
+ role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
+ }
+
+ if ($data->metacourse and has_capability('moodle/course:managemetacourse', $context)) {
+ // Redirect users with metacourse capability to student import
redirect($CFG->wwwroot."/course/importstudents.php?id=$course->id");
- } else if (has_capability('moodle/role:assign', $context)) { // Redirect users with assign capability to assign users to different roles
+ } else {
+ // Redirect to roles assignment
redirect($CFG->wwwroot."/$CFG->admin/roles/assign.php?contextid=$context->id");
- } else { // Add current teacher and send to course
- // find a role with legacy:edittingteacher
- if ($teacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, $context)) {
- // assign the role to this user
- $teachereditrole = array_shift($teacherroles);
- role_assign($teachereditrole->id, $USER->id, 0, $context->id);
- }
- redirect($CFG->wwwroot."/course/view.php?id=$course->id");
}
} else {
$string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.';
$string['configcoursemanager'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.';
$string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.';
+$string['configcreatornewroleid'] = 'This role is automatically assigned to creators in new courses they created. This role is not assigned if creator already has needed capabilitites in parent context.';
$string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. This is especially useful for large/busy sites or sites built on cluster of servers. For most sites this should probably be left disabled so that the server disk is used instead. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.';
$string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.';
$string['configdebugdisplay'] = 'Set to on, the error reporting will go to the HTML page. This is practical, but breaks XHTML, JS, cookies and HTTP headers in general. Set to off, it will send the output to your server logs, allowing better debugging. The PHP setting error_log controls which log this goes to.';
$string['courserequests'] = 'Course Requests';
$string['courses'] = 'Courses';
$string['coursesperpage'] = 'Courses per page';
+$string['creatornewroleid'] = 'Creators\' role in new courses';
$string['cronclionly'] = 'Cron execution via command line only';
$string['cronerrorclionly'] = 'Sorry, internet access to this page has been disabled by the administrator.';
$string['cronerrorpassword'] = 'Sorry, you have not provided a valid password to access this page';
if ($cachedcaps) {
foreach ($cachedcaps as $cachedcap) {
array_push($storedcaps, $cachedcap->name);
- // update risk bitmasks in existing capabilities if needed
+ // update risk bitmasks and context levels in existing capabilities if needed
if (array_key_exists($cachedcap->name, $filecaps)) {
if (!array_key_exists('riskbitmask', $filecaps[$cachedcap->name])) {
$filecaps[$cachedcap->name]['riskbitmask'] = 0; // no risk if not specified
}
if ($cachedcap->riskbitmask != $filecaps[$cachedcap->name]['riskbitmask']) {
- $updatecap = new object;
+ $updatecap = new object();
$updatecap->id = $cachedcap->id;
$updatecap->riskbitmask = $filecaps[$cachedcap->name]['riskbitmask'];
if (!update_record('capabilities', $updatecap)) {
return false;
}
}
+
+ if (!array_key_exists('contextlevel', $filecaps[$cachedcap->name])) {
+ $filecaps[$cachedcap->name]['contextlevel'] = 0; // no context level defined
+ }
+ if ($cachedcap->contextlevel != $filecaps[$cachedcap->name]['contextlevel']) {
+ $updatecap = new object();
+ $updatecap->id = $cachedcap->id;
+ $updatecap->contextlevel = $filecaps[$cachedcap->name]['contextlevel'];
+ if (!update_record('capabilities', $updatecap)) {
+ return false;
+ }
+ }
}
}
}
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'riskbitmask' => RISK_XSS,
'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
+ 'contextlevel' => CONTEXT_COURSECAT,
'legacy' => array(
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),