Activity restriction based on user role

Activity restriction based on user role

by Arvind Murali -
Number of replies: 5

In my moodle site, I have a manager account creating course content. I also have a teacher user definition profile. Users with the teacher profile belong to certain groups. Lets say I have teacher 1 belonging to Group 1. The course has Group 1 and Group 2. Whenever the manager creates a new activity, I want every group in the site to have access to it and since the activity will not have have restrict access enabled, this should work as expected. However, if a teacher profile creates an activity, I want the activity to automatically be restricted to be only visible to the group they belong to. Basically I want the activity creation to automatically check the current user role and the group and include it as a restrict access condition and hide the activity for those not matching the restriction. How can I go about doing this?Restriction

Average of ratings: -
In reply to Arvind Murali

Re: Activity restriction based on user role

by Евгений Мамаев -
Picture of Plugin developers

One possible way to do this is to make a local plugin which will "listen" to course_module_created event and add restriction to just created activity

In reply to Евгений Мамаев

Re: Activity restriction based on user role

by Arvind Murali -

Great suggestion. I'll look into this. Any particular plugin I can look into to make it easier for me to understand how to go about this? I'm pretty new to this.


Thank you.

In reply to Arvind Murali

Re: Activity restriction based on user role

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
This will not be easy to accomplish, even the availability role (https://moodle.org/plugins/availability_role) will not solve your problems:
  • groups were developed to group students - not teachers. So first you will have to avoid that teachers can modify/add groups.
  • restrictions were also not developed to restrict teachers. So you will need to rewrite user restrictions.
  • last but not least you want to give teachers permissions to create new activities but also restrict them to edit other ones. To have this functionality, you will need a herd of programmers to add a new edit_module permission to Moodle.
Instead of restricting teachers, perhaps you can upgrade your student role. But I have the impression that you will end up with more code than content.
In reply to Renaat Debleu

Re: Activity restriction based on user role

by Arvind Murali -

Yeah. You are right. In this case, to truly implement "restriction" I would have to go down that path. I'm going to just setup "hurdles" for now to improve the user experience. In other words, If a spirited teacher wanted, they might be able to make changes by regrouping and other crafty ways or removing restriction manually.