Problems with a duplicate role

Problems with a duplicate role

by Jason Hollowell -
Number of replies: 14
Hello,

I created a duplicate of the 'Student' role some time back thinking that I was going to make a new role that was somewhere between student and non-editing teacher but after I realized it wasn't possible I left the duplicated role with the same settings as student.

I've recently enrolled about 2000 students using 'Upload user' and 'update existing accounts'. Hope to use a different method the next time (external database) but that is not what I'm having a problem with at the moment.

I just noticed that all my enrollments were given the duplicated role instead of Student. Luckily that role is the same as student as student it its legacy role but I can't figure out why the students were not enrolled as Student...?

I had name the role 'resource contributor' but since the role was identical to student and just went in and renamed it to something closer to student. That will work for the time being but again, I don't understand why Moodle defaulted to this duplicated role instead of the Student role...?

Jason
Average of ratings: -
In reply to Jason Hollowell

Re: Problems with a duplicate role

by John Isner -
What is value of Site administration -> Users -> Permissions -> User policies -> Default role for users in a course? If it is Student, then IMO bulk upload should be using Student, not Resource, and I would file a bug report.
In reply to Jason Hollowell

Re: Problems with a duplicate role

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
The legacy role is the key. Uploading users as "student" will pick the first legacy role it finds. We can't rely on names or anything else as people change them.

Usually you would only have one role "blessed" using the legacy setting as the standard student role. You had two so it picks the first one it finds. You had bad luck this time, sorry.

The fix would be to remove the legacy setting for your new role, and just leave it there for the original role. You can also explicitly specify roles to use by their shortname (see help on that page).
In reply to Martin Dougiamas

Re: Problems with a duplicate role

by John Isner -
Good explanation, but shouldn't the logic be changed to use the role specified as "Default role for users in a course"? If you don't specify a role explicitly in the bulk upload file, you should get the default value, shouldn't you?
In reply to John Isner

Re: Problems with a duplicate role

by Jason Hollowell -
I agree with John here. I thought that Student was the default role and that all my new users would be given that role automatically. Maybe I'm not following the thinking behind the 'legacy role'?

For me this time its not a huge problem because both of the roles have the same permissions so I just changed the name of the role that got used.

I now have users enrolled in courses using both of the roles so I'm nervous about getting rid of either. If I deleted the duplicated role, for example, what would happen to all the students enrolled in courses via that role? I assume they would no longer be enrolled?

Jason

**Edit - After reading Martin's post again I think I understand. So I can remove the legacy role portion of my duplicated role and slowly phase it out. Once I get to a point where no students are enrolled using that role I can delete it. Correct?

Also, could I have specified the role ID when creating accounts and enrolling students? Since I was assuming the Student role would be assigned by default I wasn't thinking of it at the time but now, looking back, I'm just wondering what would have been the best way to specify the role I wanted. (of course deleting the duplicate role would have been best but...)

In reference to the role ID here, when you go to Site administration -> Users -> Permissions -> User policies -> Default role for users in a course as referred to by John, the 'subtext' is defaultcourseroleid. Doesn't that refer to the ID of the default course role? When I select Student here in Site Administration doesn't Moodle lock on to that ID? In my case one is 5 and the other 9.
In reply to Jason Hollowell

Re: Problems with a duplicate role

by John Isner -
Hi Jason,
I wouldn't remove the LRT from Resource on general principle. The consequences of removing the LRT are undocumented, so why take a chance?

Instead, I would specify the Student role explicitly in future bulk uploads. You can use the role id 5 or you can use the role shortname (student), e.g.

username, password, firstname, lastname, email, role1, course1
s1, demo, Joe, Smith, s1@example.com, student, Features
s2, demo, Sue, Jones, s2@example.com, student, Features
s3, demo, Fred, Dobbs, s3@example.com, 5, Features
s4, demo, Mary, Dokes, s4@example.com, 5, Features

Where did I get the 5? Go to to Site administration -> Users -> Permissions -> Define roles and place your cursor over any of the role names. At the bottom of the window you will see a URI containing the roleid (see screenshot).

I'm confused by your last sentence. Are you saying the Default role for users in a course (defaultcourseroleid) is 9? How did you get that? By looking at the page source? Then it's not Student. Maybe it's Resource after all.

Supposing the roleid of Resource is 9, then the quickest way to switch students from Resource to Student is to go to the database and change the roleid value from 9 to 5 in the mdl_role_assignments table.




Attachment student_roleid_is_5.png
In reply to John Isner

Re: Problems with a duplicate role

by Jason Hollowell -
John,

Thanks. Yeah I decided to not mess with things for now as I don't want to mess up what has taken me about a week (enrolling around 2000 students in various courses).

I got the 5 and 9 the way you have presented here, by mousing over the two different roles. 5 is the ID for Student as you have pointed out and 9 is the ID for the 'Resource contributor' role that I had created. I created it by duplicating the student role but then ended up leaving the same (permissions wise) as student when I determined that I wasn't going to be able what I had planned to. I should have just deleted the role but forgot.

At any rate, I don't understand why all my new students were enrolled under that role (ID 9) when the default is set to Student which has an ID of 5. ??

Jason

P.S. Once things settle down here at school, maybe I'll go in and change all the role assignments from 9 to 5 and then delete the unneeded role.
In reply to Jason Hollowell

Re: Problems with a duplicate role

by John Isner -
If it's not a bug then it's a usability issue, so I created MDL-14459 (Bulk upload of users to a specific course should use "Default role for users in a course" when role not specified).
In reply to John Isner

Re: Problems with a duplicate role

by Jason Hollowell -

John,

Thanks.  And yes, again I agree.  I still can't quite get my head around why Moodle chose the duplicated role.  It had an ID that was sequentially later than the orginal role (9 vs. 5).  The first letter in the title R (resource) and S (student) couldn't have been the root cause could it? (alphabetical ordering?)

This ended up biting me afterall.  I thought that I hadn't made any changes to the duplicated role but I guess I had because the gradebook was not treating any of the students enrolled with the duplicated role as participants who should receive a grade for graded events.  So, my teachers started asking me why they kept getting the "no grades returned" error when they viewed the gradebook even though they had already given several assignments and other taks that were graded.  Ahhhh!

So I had to go in and change the roleid setting from 9 to 5 for all my users in mdl_enrollment_settings.  It wasn't that hard but was a little bump that I would have rather avoided.

Jason

I promptly hid the role from all teachers and will delete it as soon as I can confirm for sure (double check) that it's not being used anywhere.

In reply to Martin Dougiamas

Re: Problems with a duplicate role

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hello,

the legacy role was never used for user uploads in 1.9 wink It was replaced by $course->defaultrole and $CFG->defaultcourseroleid during the cleanup later after the GSOC. I have reviewed the code again and retested it - works fine for me.

Please try the import again and verify that you have the expected role set as Default role in course settings. Also please verify your Default role for users in a course in admin settings.

If you manage to reproduce the problem, please reopen MDL-14459.
In reply to Petr Skoda

Re: Problems with a duplicate role

by John Isner -
Petr said

verify your Default role for users in a course in admin settings.


Good idea. I wonder if this is Jason's problem. If his course setting = Resource, it would override the global setting (Student).

Anyway, I am happy to hear that bulk upload does not depend on the legacy role type smile
In reply to Petr Skoda

Re: Problems with a duplicate role

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Sorry, I missed those changes in 1.9! (What version was Jason using?)

So, looking at the help docs:

Enrolment field names (optional): The course names are the "shortnames" of the courses - if present then the user will be enrolled in those courses. "Type" means type of role to be used for associated course enrolment. Value 1 is default course role, 2 is legacy Teacher role and 3 is legacy Non-editing Teacher. You can use role field instead to specify roles directly - use either role short name or id (numeric names of roles are not supported). Users may be also assigned to groups in course (group1 in course1, group2 in course2, etc.). Groups are again identified by its names or ids (numeric names of groups are not supported).

That seems to cover all bases. Yes
In reply to Martin Dougiamas

Re: Problems with a duplicate role

by Jason Hollowell -
Sorry, I was away from Moodle.org for a while.

I am using 1.8.4+

I did not specify a role in the upload file because I assumed that the default role would be assigned.

Just to re-summarize;

In -> Site Administration -> Users -> Permissions -> User Policies -> Default role for users in a course, I have set the default user to Student.

The id for the Student role is 5 in my database.

The duplicated role that I created was called Resource Contributor and had a role id of 9 in the database. That role was duplicated from the Student role and did retain the legacy setting.

The name and shortname and ID for the duplicated role were all different/unique in comparison with the Student role.

So, again, I don't understand why when I had the course default role set to Student, that the bulk upload/enroll used the duplicated Resource Contributor role?

I've managed to fix the problems that resulted from this oversight on my part but still feel like something is either 'not quite right' or maybe I just don't understand exactly how the roles (especially legacy role) interact.

Jason

P.S. The default role setting within each course is also set to Site Default (Student).

P.P.S. I just tried this again with a test account and the enrollment did again use the Resource Role (I've renamed the role to NU-Students and hidden it from teachers). The following is what my csv file looks like:

lastname,firstname,username,email,course1
Test me,J,testuser,my@address.com,EI-E10-S08

The user with the username testuser was enrolled in the course E1-E10-S08 but with the duplicated role (Now called NU-Students) instead of the Student role.
In reply to Jason Hollowell

Re: Problems with a duplicate role

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I think there may have been a bug there to do with the default role which got fixed in 1.9 and not backported.

In any case, in 1.8.x use a role field with the roleid (5) in it to explicitly specify the role you want. See the help button on the upload page for details.