Auto Adding Users into Cohorts based on a value in their Mail

Auto Adding Users into Cohorts based on a value in their Mail

by FatBOY2 Verbic -
Number of replies: 4

Hey, 

I have been brainstorming about this issue for quite some time now and cannot seem to find a suitable solution for it in any plugin.

In our company we have divided users into internal/external/partner users and each of those should only be able to see specific courses. Previously we only had internal users accessing moodle but now we need to provide certain courses to externals and partners as well. 

My train of thought was if I could automatically add users to certain cohorts once their account gets created or they login I can then based on that let them see specific courses based on their cohort. This would be possible as 

  • internal users have name@companyname.com
  • external users have name@external.companyname.com
  • and partner users have name@partner.companyname.com

There are a few plugins that kind of achieve what I need but f.e. https://moodle.org/plugins/local_profilecohort/versions only takes values from custom profile fields. I also tried it this way but then I would need to somehow automatically fill out the custom profile field as I do not want to manually assign each user its company allocation.

Maybe I am thinking way too complicated here. Is there some simpler way to do this? Do you have another idea on how to achieve this?

Thanks for any help!

Average of ratings: -
In reply to FatBOY2 Verbic

Re: Auto Adding Users into Cohorts based on a value in their Mail

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Average of ratings: Useful (1)
In reply to Dan Marsden

Re: Auto Adding Users into Cohorts based on a value in their Mail

by FatBOY2 Verbic -
Hey Dan,

I tried using this but I do not even know where to modify the plugin, the documentation says to head to the *Site administration - Notifications* page but there is nothing to modify there.

Also in my case I would write
{{ email.domain }} in the (`mainrule_fld`) right
and then in (`replace_arr`)
I would say okay:
  • internals.net|Internal
  • partner.net|Partner
  • external.net|External

Would that make sense? 

In reply to FatBOY2 Verbic

Re: Auto Adding Users into Cohorts based on a value in their Mail

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
it puts the config setting with the other cohort related ones - under "Site administration - Users - Accounts" - "Cohort role synchronization" is the one you probably want to start with. - it's been a while since I've set it up myself - probably best that you play around with the settings to get ones that you want to use.
In reply to Dan Marsden

Re: Auto Adding Users into Cohorts based on a value in their Mail

by FatBOY2 Verbic -

Hey Dan, 

Thank you for your answer. I managed to edit it. However it does not work as well yet. 

See the pic for configuration:

AutoCohort Plugin configuration

It worked for my internal user, but when we tested it for an external guy he was not put in any cohort at all. Any idea why this behaviour occurs?

Also the user testing this got an Error when testing the login:

Error Message Cohort Auto

Does this say anything to you? Dont know if this has something to do with my config or the plugin itself...