Moodle

Metacourse: no non-editing teachers possible

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.8.2
  • Fix Version/s: 2.0
  • Component/s: Course
  • Labels:
    None
  • Environment:
    MySQL 5.0.27
    PHP 4.4.7
    Linux-webhosting with apache
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_18_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Hello!

I am using many Metacourses on my Moodle-System. In former Moodle 1.6 it worked very well.

After upgrading directly from 1.6.1 to 1.8, and running now 1.8.2, there I have the following problem:

As Administrator, Course Manager or teacher, I can not set a non-editing teacher to a metacourse. I get the following error message: "Can not assign this role to user "xxx" because Manage metacourse capability is needed."

But rechecking my global role settings, Administrators and teachers have set "Manage metacourses" to allow. Course Manager has set no value at this point. In a normal course (no Metacourse), I can set non-editing teachers without any problem.

Hope there will be a solution for this problem soon because I have many requests from my teachers.

Kind regards, Daniel

Activity

Hide
asdf added a comment -

i confirm this. i cannot add a normal user to a metacourse, it gives me the same error. i can add a teacher though

Show
asdf added a comment - i confirm this. i cannot add a normal user to a metacourse, it gives me the same error. i can add a teacher though
Hide
Michael Penney added a comment -

Confirmed in 1.8.2+. PS, this issue doesn't show up here (the top of this page link* that looks like it should show all 1.8.x bugs):

http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&requestId=10077

  • "as well as bug fixes for Moodle 1.8.x a..."
Show
Michael Penney added a comment - Confirmed in 1.8.2+. PS, this issue doesn't show up here (the top of this page link* that looks like it should show all 1.8.x bugs): http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&requestId=10077
  • "as well as bug fixes for Moodle 1.8.x a..."
Hide
Daniel Schimrik added a comment -

After visiting some message boards at Moodle.org, I found a solution for this problem.

You have to change the role permissions for "non-editing teachers" and change "moodle/course:managemetacourse" to allow. Now you can also add non-editing teachers to your Metacourses.

BUT: I have no feature-description of "moodle/course:managemetacourse". So it may be possible that a non-editing teacher gets more rights than just work in a Metacourse (maybe equal rights to normal teachers).

Regards, Daniel

Show
Daniel Schimrik added a comment - After visiting some message boards at Moodle.org, I found a solution for this problem. You have to change the role permissions for "non-editing teachers" and change "moodle/course:managemetacourse" to allow. Now you can also add non-editing teachers to your Metacourses. BUT: I have no feature-description of "moodle/course:managemetacourse". So it may be possible that a non-editing teacher gets more rights than just work in a Metacourse (maybe equal rights to normal teachers). Regards, Daniel
Hide
Etienne Rozé added a comment -

I confirm what Daniel said.

Show
Etienne Rozé added a comment - I confirm what Daniel said.
Hide
Ann Adamcik added a comment -

The message about needing manage metacourse capability is referring to the non-editing teacher role (this could be clearer). By default, non-editing teachers do not have manage metacourse capabilities, so they cannot be assigned to a metacourse. If you set the managemetacourse capability for non-editing teachers, then it works to assign them to meta courses.

Show
Ann Adamcik added a comment - The message about needing manage metacourse capability is referring to the non-editing teacher role (this could be clearer). By default, non-editing teachers do not have manage metacourse capabilities, so they cannot be assigned to a metacourse. If you set the managemetacourse capability for non-editing teachers, then it works to assign them to meta courses.
Hide
Tony Butler added a comment -

Of course, giving the managemetacourse capability to non-editing teachers allows them to add/remove child courses in any meta courses they are assigned to. In most cases this is probably not desirable.

I think what's needed is an additional capability relating to meta courses - one that allows a user to be assigned a role in a meta course even if they:
a) are not a member of any of its child courses, and
b) should not have the permission for adding/removing child courses (assuming that's the primary purpose of the managemetacourse capabilty).

This would allow greater flexibilty all round. For example, I would like to be able to prevent all teachers (including editing ones) from seeing the 'child courses' link; meta/child course relationships here are managed by the admins, so teachers don't need to understand them.

Show
Tony Butler added a comment - Of course, giving the managemetacourse capability to non-editing teachers allows them to add/remove child courses in any meta courses they are assigned to. In most cases this is probably not desirable. I think what's needed is an additional capability relating to meta courses - one that allows a user to be assigned a role in a meta course even if they: a) are not a member of any of its child courses, and b) should not have the permission for adding/removing child courses (assuming that's the primary purpose of the managemetacourse capabilty). This would allow greater flexibilty all round. For example, I would like to be able to prevent all teachers (including editing ones) from seeing the 'child courses' link; meta/child course relationships here are managed by the admins, so teachers don't need to understand them.
Hide
Vivienne Counter added a comment -

This is a major issue for us. We have meta-courses that we need to add additional students to, as well as support staff. These students are students of the child courses. We cannot do this without creating "fake" courses, and making this "fake" course a child course, as obviously, we don't want to give our students manage meta-course rights.
Why do we need a special permission to have a role in a meta-course? Does it matter which roles can be assigned to a meta-course?

Show
Vivienne Counter added a comment - This is a major issue for us. We have meta-courses that we need to add additional students to, as well as support staff. These students are students of the child courses. We cannot do this without creating "fake" courses, and making this "fake" course a child course, as obviously, we don't want to give our students manage meta-course rights. Why do we need a special permission to have a role in a meta-course? Does it matter which roles can be assigned to a meta-course?
Hide
Dennis Rochford added a comment -

We have just implemented some changes that get around this problem. The fix allows you to manually add ANYBODY directly into the meta course.

The first part of the fix is to take out the capability check when assigning users. Remove the following line of code from /admin/roles/assign.php:

  • if ($inmeta) {
  • if (has_capability('moodle/course:managemetacourse', $context, $adduser)) { - //ok - } else {
  • $managerroles = get_roles_with_capability('moodle/course:managemetacourse', CAP_ALLOW, $context);
  • if (!empty($managerroles) and !array_key_exists($roleid, $managerroles)) { - $erruser = get_record('user', 'id', $adduser, '','','','', 'id, firstname, lastname'); - $errors[] = get_string('metaassignerror', 'role', fullname($erruser)); - $allow = false; - }
  • }
  • }

The next part of the fix allows the system to know which users were added via the auto meta sync process and then ignores manually created assigments during the sync process. To do this I am assigning the value of 'meta' to the enrol property of the role_asssignment record. The enrol property indicates the enrolment method used to create the assignment (normally set to 'manual'). 'meta' is not a valid enrolment type but I could not find any logic in Moodle that would have a negative impact. We need to modify the sync_metacourse() function within /lib/moodlelib.php. First we want to stop unassignment of users that were not created by the meta sync process. Add "ra.enrol = 'meta'" to the appropriate sql statement. The code should look something like this:

if (!$unassignments = get_records_sql("
SELECT
ra.id, ra.roleid, ra.userid
FROM
{$CFG->prefix}role_assignments ra
WHERE
ra.contextid = {$context->id} AND
ra.enrol = 'meta' AND
$roleexclusions
NOT EXISTS (
SELECT 1 FROM
{$CFG->prefix}role_assignments ra2,
{$CFG->prefix}context con2,
{$CFG->prefix}course_meta cm
WHERE
ra2.userid = ra.userid AND
ra2.roleid = ra.roleid AND
ra2.contextid = con2.id AND
con2.contextlevel = " . CONTEXT_COURSE . " AND
con2.instanceid = cm.child_course AND
cm.parent_course = {$course->id}
)
")) { $unassignments = array(); }

Now we want to take out the check for those users who have 'moodle/course:managemetacourse' capability when performing the unassignment. I.e.: (notice the commented out lines)

foreach ($unassignments as $unassignment) {
//if (!in_array($unassignment->userid, $managers)) { $success = role_unassign($unassignment->roleid, $unassignment->userid, 0, $context->id) && $success; //}
}

Note that you can also remove the code which sets up the $managers variable as it is no longer referenced.

The final thing to do is set the enrol property to 'meta' for new assignments. Should now look like this:

foreach ($assignments as $assignment) { $success = role_assign($assignment->roleid, $assignment->userid, 0, $context->id, 0, 0, 0, 'meta') && $success; }

Sorry I could not provide a patch file as I have a variety of other changes that are not relevant.

But wait... there's more... You will need to set the enrol property for existing role_assignments when implementing the changes. I am attaching a script that will do the trick.

Show
Dennis Rochford added a comment - We have just implemented some changes that get around this problem. The fix allows you to manually add ANYBODY directly into the meta course. The first part of the fix is to take out the capability check when assigning users. Remove the following line of code from /admin/roles/assign.php:
  • if ($inmeta) {
  • if (has_capability('moodle/course:managemetacourse', $context, $adduser)) { - //ok - } else {
  • $managerroles = get_roles_with_capability('moodle/course:managemetacourse', CAP_ALLOW, $context);
  • if (!empty($managerroles) and !array_key_exists($roleid, $managerroles)) { - $erruser = get_record('user', 'id', $adduser, '','','','', 'id, firstname, lastname'); - $errors[] = get_string('metaassignerror', 'role', fullname($erruser)); - $allow = false; - }
  • }
  • }
The next part of the fix allows the system to know which users were added via the auto meta sync process and then ignores manually created assigments during the sync process. To do this I am assigning the value of 'meta' to the enrol property of the role_asssignment record. The enrol property indicates the enrolment method used to create the assignment (normally set to 'manual'). 'meta' is not a valid enrolment type but I could not find any logic in Moodle that would have a negative impact. We need to modify the sync_metacourse() function within /lib/moodlelib.php. First we want to stop unassignment of users that were not created by the meta sync process. Add "ra.enrol = 'meta'" to the appropriate sql statement. The code should look something like this: if (!$unassignments = get_records_sql(" SELECT ra.id, ra.roleid, ra.userid FROM {$CFG->prefix}role_assignments ra WHERE ra.contextid = {$context->id} AND ra.enrol = 'meta' AND $roleexclusions NOT EXISTS ( SELECT 1 FROM {$CFG->prefix}role_assignments ra2, {$CFG->prefix}context con2, {$CFG->prefix}course_meta cm WHERE ra2.userid = ra.userid AND ra2.roleid = ra.roleid AND ra2.contextid = con2.id AND con2.contextlevel = " . CONTEXT_COURSE . " AND con2.instanceid = cm.child_course AND cm.parent_course = {$course->id} ) ")) { $unassignments = array(); } Now we want to take out the check for those users who have 'moodle/course:managemetacourse' capability when performing the unassignment. I.e.: (notice the commented out lines) foreach ($unassignments as $unassignment) { //if (!in_array($unassignment->userid, $managers)) { $success = role_unassign($unassignment->roleid, $unassignment->userid, 0, $context->id) && $success; //} } Note that you can also remove the code which sets up the $managers variable as it is no longer referenced. The final thing to do is set the enrol property to 'meta' for new assignments. Should now look like this: foreach ($assignments as $assignment) { $success = role_assign($assignment->roleid, $assignment->userid, 0, $context->id, 0, 0, 0, 'meta') && $success; } Sorry I could not provide a patch file as I have a variety of other changes that are not relevant. But wait... there's more... You will need to set the enrol property for existing role_assignments when implementing the changes. I am attaching a script that will do the trick.
Hide
Alex Djachenko added a comment -

Version 1.9. Problem still here
You can't enroll non-edit teacher to metacourse if they haven't got "course:managemetacourse" capabilitie.

Show
Alex Djachenko added a comment - Version 1.9. Problem still here You can't enroll non-edit teacher to metacourse if they haven't got "course:managemetacourse" capabilitie.
Hide
Paul Fynn added a comment -

As for Alex 1.9.4 + Still can't add non-editing teachers - I also have the same need as Dennis.

**Dennis Rochford added a comment - 29/May/08 01:57 PM
**We have just implemented some changes that get around this problem. The fix allows you to manually **add ANYBODY directly into the meta course.

Additionally I would like to be able to use Metacourse Capabilities in conjunction with individual enrolment. I also need to be able to make a central decision to suspend a student, and automatically cut their access to all courses.

Currently we have too many 'non-standard' students infilling in different ways, so we are working in one of two ways:

    • Create a temproary metacourse, pull in the relevant courses, and export a grades report to output a user list, which is then bulk uploaded to the relevant course
    • Have a course for each class group, and use backup and restore to put the users into the new course in bulk

Currently the issue with not being able to add non-editing teachers is so severe in impact that we will cease to use metacourses at the end of this semester.

I would like to see this prioritised, at least by 2.0.
Regards
Paul

Show
Paul Fynn added a comment - As for Alex 1.9.4 + Still can't add non-editing teachers - I also have the same need as Dennis. **Dennis Rochford added a comment - 29/May/08 01:57 PM **We have just implemented some changes that get around this problem. The fix allows you to manually **add ANYBODY directly into the meta course. Additionally I would like to be able to use Metacourse Capabilities in conjunction with individual enrolment. I also need to be able to make a central decision to suspend a student, and automatically cut their access to all courses. Currently we have too many 'non-standard' students infilling in different ways, so we are working in one of two ways:
    • Create a temproary metacourse, pull in the relevant courses, and export a grades report to output a user list, which is then bulk uploaded to the relevant course
    • Have a course for each class group, and use backup and restore to put the users into the new course in bulk
Currently the issue with not being able to add non-editing teachers is so severe in impact that we will cease to use metacourses at the end of this semester. I would like to see this prioritised, at least by 2.0. Regards Paul
Hide
Petr Škoda (skodak) added a comment -

Hello,
this should be finally fixed in Moodle 2.0dev, the metacourses and enrolments were completely reimplemented. Please test and report any new problems if necessary.

If anybody creates some working solution for 1:9.x please post it here, I am sure some admins would be still interested in it before they upgrade to Moodle 2.0.

Thanks everybody for the report, patches and general ideas, it was very valuable for me when I was working on the new code.

Petr Skoda

Show
Petr Škoda (skodak) added a comment - Hello, this should be finally fixed in Moodle 2.0dev, the metacourses and enrolments were completely reimplemented. Please test and report any new problems if necessary. If anybody creates some working solution for 1:9.x please post it here, I am sure some admins would be still interested in it before they upgrade to Moodle 2.0. Thanks everybody for the report, patches and general ideas, it was very valuable for me when I was working on the new code. Petr Skoda

Dates

  • Created:
    Updated:
    Resolved: