How to prevent given users to self-enroll given critical courses?

How to prevent given users to self-enroll given critical courses?

by Benoît M -
Number of replies: 7

Our company is receiving some trainees from another company.
We would like to prevent these trainees to self enroll to critical courses.
Let's say our Moodle instance is having 5 courses, and we want the external trainnes self-enroll as follow:

  •        course 1 (not critical): external trainees can self enroll, regular company users can self enroll
  •        course 2 (not critical): external trainees can self enroll, regular company users can self enroll
  •        course 3 (critical): external trainees can NOT self enroll, regular company users can self enroll
  •        course 4 (critical): external trainees can NOT self enroll, regular company users can self enroll
  •        course 5 (critical): external trainees can NOT self enroll, regular company users can self enroll


As our Moodle site is hosted on the internet, we want the external trainees to be authenticated.
Thus, the use of the guest account won't be a solution.

How can we tell properly Moodle to prevent the external trainees to self enroll to course 3,4,5?
Or is that possible to tell Moodle that we want the external trainnees to be able to enroll to only course 1 or 2?

Average of ratings: -
In reply to Benoît M

Re: How to prevent given users to self-enroll given critical courses?

by C Behan -

Hi Benoît,


You could add your internal users to a cohort. Then go to the settings of the self-enrol method on your course. Scroll down and under "Only cohort members" choose your internal users cohort.


Catherine

Average of ratings: Useful (1)
In reply to C Behan

Re: How to prevent given users to self-enroll given critical courses?

by Benoît M -

Hi Catherine,

this sound interesting but there is something I wonder if I proceed as you suggest.

I have created a cohort named 'my company users' and then  I had all existing users to this cohort.

There are a lot of new users that joined the Moodle site every day, 

How can I add automatically all new users to this default cohort?

If this not done, new regular users won't be able to self enroll to the course they should be able to.


After reflexion, what I am looking for, is the opposite of the 'Only cohort members ' you mentioned, I would be a setting the prevent users of a given cohort to self enroll and this would be perfect!

Any idea?

thanks for your answer

Ben

In reply to Benoît M

Re: How to prevent given users to self-enroll given critical courses?

by C Behan -

Hi Ben,


There is a plugin for automatically adding users to cohorts based on a user profile field. Maybe that would help?

Catherine

In reply to C Behan

Re: How to prevent given users to self-enroll given critical courses?

by Flotter Totte -
Picture of Plugin developers
Might be also the enrol plugin "enrolment upon approval" could help. Users enrol themselves but need to be approved by someone.

In reply to Flotter Totte

Re: How to prevent given users to self-enroll given critical courses?

by Benoît M -

In my case, this won't be possible, there are thousands regular user that must be able to self enroll without human validation.

Thanks for your answer.

Ben

In reply to C Behan

Re: How to prevent given users to self-enroll given critical courses?

by Benoît M -

Hi Catherine,

I have take a look to this plugin. but I saw that it is based on profile field.  In my case, I am not sure to have a field that can discriminate users that should not have the self enroll for some courses. In my situation, I won't add a new custom field to all user. I have to dig about this plugin.

If not relevant for my case, I will develop my own local plugin.

I saw that there was core user events, that will allow to add new user to 'a regular user cohort':

  • core\event\user_created
  • core\event\user_deleted

Thus, I can add all my existing users to this cohort listening to this emitted events. The plugin will be in charge to keep up to date the cohort with user creation/suppression. And i think this can be good. I can then manually remove the user that should not be here.

Many thanks Catherine for sharing your moodle knowledge and your ideas.

Greetings,

Ben

In reply to Benoît M

Re: How to prevent given users to self-enroll given critical courses?

by Benoît M -

Hello,

I wanna share the solution that I choose:

I choose to use the self-enroll limited to 'Only cohort members', described by Catherine (many thanks for that! I wasn't aware of that setting).
I manage that creating 2 cohorts:

  • a regular cohort for regular users (company members that must be allow to self enroll every where)
  • an exceptional cohort for exceptional users (users that must not be allow to self enroll on critical courses)


The self enroll for critical courses is then restricted to the 'regular cohort'

I create a MOODLE plugin called 'regularcohort' to handle that.

The plugin allows to add all newly created users to the regular cohort. There is also a synchronization script that will allow to populate the cohorts at the first time.
Users that are members of the exceptional cohort will be removed by a synchronization script.

Now, this is ok. I can prevent exceptional users to self-enroll to critical courses.
Greetings,
Ben