Uploading users to custom roles

Uploading users to custom roles

by Grant Beevers -
Number of replies: 24
Hi folks,

I wish to upload a number of users to a custom role which I have created in our 1.9 system, however, I have only seen instructions regarding uploading to type 1, 2 or 3 (student, teacher, non-editing teacher). I assume this custom role will have a type number associated with, however, how do I know what that would be, or, will the system not support the upload of user to a custom role?

Thanks for any input.

Regards,
Grant Beevers
ACNM, Manager, Centre for Flexible Learning Delivery
Average of ratings: -
In reply to Grant Beevers

Re: Uploading users to custom roles

by John Isner -
Hi Grant,
It's me again smile You can use the role id of any role, including roles that you have created. In the example below, I'm assigning the Student role (roleid 5) to John Smith in the "Features" course. You can find the role id of any role by going to Site administration -> Users -> Permissions -> Define roles and letting your mouse hover over any one of the roles (see the roleid in the URI).

username,password,firstname,lastname,email, role1, course1
jsmith, demo, John, Smith, s7@example.com, 5, Features

Average of ratings: Useful (2)
In reply to John Isner

Re: Uploading users to custom roles

by Grant Beevers -

Thanks John. So in my case, where I have created 2 new roles, Account Manager and CanAddToCourse for the Education Advisor position, how would the upload file look then, as I need to allocate the 2 roles to the person.

Grant

In reply to Grant Beevers

Re: Uploading users to custom roles

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hi,

you'll just have to insert one line per role, so, if i expand the example, it could be something like this :
username,password,firstname,lastname,email, role1, course1
jsmith, demo, John, Smith, s7@example.com, 8, Features
jsmith, demo, John, Smith, s7@example.com, 9, Features

If the 2 roles are in the same course
In reply to Séverin Terrier

Re: Uploading users to custom roles

by Grant Beevers -

Hi Severin,

If I don't want to assign them to any course on import, can I just leave the last column off? eg:

username,password,firstname,lastname,email, role1

And secondly, if these guys already exists in the system, will this file only do an update of the role and nothing else?

Thanks,

Grant

Average of ratings: Useful (1)
In reply to Grant Beevers

Re: Uploading users to custom roles

by Sue Dark -

Hi Grant,

Did you ever get an answer to this?  I cannot find a way of uploading users and assigning them a system level role, i.e. not course level. Did you find out how to do that?  I have tried putting different field names in my CSV (e.g. tried roleid).

Does anyone else know what to put in the CSV file against a user so that we also assign them a site level role?

Many thanks

Sue

In reply to Sue Dark

Re: Uploading users to custom roles

by Teresa Gibbison -
Hi Sue
Can I ask which types of roles you are assigning at site level? We have a very limited number of users assigned at site level (only Admin & Helpdesk roles). All other roles are assigned at course (or paper) level with the odd being assigned at category level.
Cheers
Teresa
In reply to Teresa Gibbison

Re: Uploading users to custom roles

by Sue Dark -

Hi Teresa!

There is a management role which has overarching views of all courses, so we assigned them at site level rather than at each course level. Using the bulk upload I was looking for how I assign them to the specific role we have set up for them. i couldn't find the actual field code to use smile... I can do this at other levels but not site level.

Cheers, Sue

In reply to Sue Dark

Re: Uploading users to custom roles

by Teresa Gibbison -
Good to hear from you Sue smile
OK, I understand now - this is similar to our School (course category) role assignment where those involved with that school are allowed to view all courses within that category.

In answer to your question - AFAIK site level role association ( Administration ► Users ► Permissions ► Assign system roles ) can not be done via csv. If you follow the usual csv upload template specifying the courseid as '1' or the shortname of the site it simply associates that users to the Front Page role ( Administration ► Front Page ► Front Page roles ) rather than the system role.

I would assign them manually, I hope you don't have too many! Another thing to think about is that non-Administrator system roles are displayed in each course's Participants page. When you assign the users you can click the 'hidden' checkbox so only those with the View hidden role assignments moodle/role:viewhiddenassigns permission (usually the Teacher type roles) can see them but they will 'crowd' the participants list.

I hope this helps
Cheers
Teresa
Average of ratings: Useful (1)
In reply to Teresa Gibbison

Re: Uploading users to custom roles

by Sue Dark -

Thanks Teresa,

Yes manually assign to system role seems to be the answer - and thanks for reminding me about the 'hidden' option.  I had not thought about that.

Your help much appreciated!

Sue

In reply to Sue Dark

Re: Uploading users to custom roles

by Bill Colen -

Hi Folks,

In keeping with the custon roles topic, I am trying in Moodle 2, to manage what students do outside a course. For example I want to control for all students how they Manage Files on own private file area. I can prohibit this in the student profile but this is only for within courses.

My understanding is I need to create a System Role for students with this feature prohibited, and then add all students to this role. However there seems to be no way to add all students in bulk to a system role, it needs to be done on an individual basis.

Have I understood this correctly or is there an easier way of doing this?

Thanks.

In reply to Grant Beevers

Re: Uploading users to custom roles

by Federica Marra -

Hello everybody!

Has this issue been solved by someone? Is it possible to add the uploaded users to a system role?

In my situation: we are uploading lists of about 12/15 people each time so we are looking for:

1) a possibility to label or to keep this users separated by the other students (so we can have an easy overview of them)

2) quick solution for multiple users and not manually add each of them by a system role.

I was thinking about adding them at the "front page course" and create a role inside it, what do you think about this solution?

In reply to Federica Marra

Re: Uploading users to custom roles

by Federica Marra -

None with suggestions for this? 

In reply to Federica Marra

Re: Uploading users to custom roles

by Stephen Parry -

I suspect that if you assign front page role it will not restrict the users in all the ways you might want, e.g. you cannot disable user profile or password editing this way. I am not sure why the csv import does not allow system role assignment; it should. I think a backend hack (running some SQL against the database) may provide a solution, if you have some way of distinguishing reliably between the users you want in each role. I will have a look....

In reply to Federica Marra

Re: Uploading users to custom roles

by Ravi Alamuri -

Hello


Could you not use cohorts for this? If all you need is to separate the group of student / enrolments then cohorts should work  


Ravi

In reply to Ravi Alamuri

Re: Uploading users to custom roles

by Stephen Parry -
But how do you then assign different system level permissions to the students in those cohorts?
In reply to Stephen Parry

Re: Uploading users to custom roles

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

You can't.  The thing is that system roles are not designed to have a lot of people assigned to them.  Can you not just adjust the student role and the authenticated user role to get the desired effect?

The only way that I can think of to mass add users to a system role would be to do it directly in the database.

Average of ratings: Useful (1)
In reply to Stephen Parry

Re: Uploading users to custom roles

by Ravi Alamuri -
My apologies. I guess I didn't read that part. I was simply addressing the OP's point 1 - labeling or tagging certain group of students for easier maintenance. 


From Moodle's documentation - 

  • If you really feel your Moodle needs to have teachers or students assigned in the system context, go to the teacher/student role in Administration > Site administration > Users > Permissions > Define roles and check the "system" box. Then search for and allow the capability moodle/course:view


I would look into creating a new system role inheriting permissions from an existing role and then modifying the CSV Upload script to read for an additional column which has the System role ID (the one I just created) and then calling a function like assign_role_to_user.

In reply to Ravi Alamuri

Re: Uploading users to custom roles

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

If we are talking about labelling or tagging users for easier searching/maintenance, perhaps you could explore making custom User profile fields ?

In reply to Mary Cooch

Re: Uploading users to custom roles

by Ravi Alamuri -

Hello Mary,


Possibly. I am not sure what the OP intends to do but if it's assigning special roles, I am guessing neither profile fields nor cohorts would be the right answer.


Ravi

In reply to Ravi Alamuri

Re: Uploading users to custom roles

by Federica Marra -

Wow, thanks to all for your answers! 
I think it is a common problem that you cannot assign system roles through the csv file.

However for my issue (more labeling than assign capabilities to the uploaded users) could work well the cohort option. I though that as for the system roles, also the cohorts were course related.

I don't need to label the users in a course level and we like that our teachers enroll their students themselves. As administrator I only create the new users with the uploading procedure, that's why I was looking to the possibility to give a system role (without capabilities) to the new users.

Hope it is clear. smile 

In reply to Federica Marra

Re: Uploading users to custom roles

by Ravi Alamuri -

Hello Federica,

Cohorts can be site wide as per the documentation https://docs.moodle.org/28/en/Cohorts

However I am not sure how you would assign capabilities to a certain cohort since cohorts have nothing to do with capabilities. That said I remember there being an earlier debate with regards to assigning Site Wide roles to specific cohorts based on MDL-36951

Regards


Ravi

In reply to Federica Marra

Re: Uploading users to custom roles

by Ravi Alamuri -

Hello,

Just wanted to add - 


I went through the issue I mentioned earlier and if you follow through the discussion, there is a link to this plugin https://moodle.org/plugins/view.php?plugin=local_cohortrole . Would using Cohorts in conjunction with this plugin resolve your issue?


Ravi

In reply to Ravi Alamuri

Re: Uploading users to custom roles

by Stephen Parry -
FYI I have posted a patch on tracker MDL-15187 to add system role functionality to the CSV upload. If it gets accepted, we will then have a solution the Grant Beever's original 2008 post.
In reply to Stephen Parry

Re: Uploading users to custom roles

by Federica Marra -

Great Stephen, I think this it not my need (because cohorts on the csv file to upload are site wide cohorts and I needed this kind of "labeling/grouping system") but all of you that answered to my post are interested in this. I guess this is a common cr for the developer.

And many thanks also to Ravi for the plugin, indeed a smart solution.