Preventing users from deleting activities with certain tags.

Preventing users from deleting activities with certain tags.

by Arvind Murali -
Number of replies: 3

I want to prevent certain users based on their course roles from being able to delete certain activity modules based on tags on the activity module. 

Let me give you an example - Admin/ course creator creates a bunch of common quizzes for everyone enrolled in a course. Each teacher wants to create an assignment visible only for their group which they can. They should be able to able to delete these if need be. However, they shouldn't be able to delete the modules created by the admin. This is similar to the delete your ownquestion vs delete all questions type capability. Unfortunately it doesnt exist in the context of activities. So far what I have is I realized the delete button calls ../moodle/course/mod.php and passes a sessionkey with the delete=id info. I tried to write an if condition within mod.php but it doesn't work for some reason. Oddly enough I think it uses a cache'd version of the function sometimes that deletes happen even if I comment out the   course_delete_module($cm->id) script. 


Average of ratings: -
In reply to Arvind Murali

Re: Preventing users from deleting activities with certain tags.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
There's certainly no functionality to do this.

I would very strongly recommend that you do not change core code. Other than that.... I'm struggling to think of any way to do this.
In reply to Howard Miller

Re: Preventing users from deleting activities with certain tags.

by Arvind Murali -

Howard, I most definitely hear you about making changes to the core code. I've been trying to find ways out of it for the past week but it is not setup to do this. From a user experience standpoint there are two things I'm trying to do. I have teachers belonging to a grouping. When they make activities, by default I want them to be restricted in access and visibility from other groupings. I know this is possible by going into restrict access right now but I am making it a default thing so they cannot make an activity visible to more than their grouping unless they are an admin. Then there is this which is admin should be able to see, update and edit anyone's activities but non admin roles shouldn't be able to delete an admin created activity. We might be able to do that by requiring a password for deleting activities or other such means that don't exist now either. Maybe there is custom scripting I can do to intercept a call to a core code. I'm not sure which way to go. As of now I'm working on pinning down the user experience by making small additions to the core code but I'd love pointers on how I should be approaching this in a production environment. 


Thank you. 

In reply to Arvind Murali

Re: Preventing users from deleting activities with certain tags.

by Arvind Murali -

I found a callback hook called "_pre_course_module_delete" that the recycle bin tool uses as well. It is supposed to catch the action of module deletion and allow a plugin to act on it. Unfortunately the callback does not work every time and even the recycle bin does not create a backup of every module that is being deleted. I wrote a small local plugin with a lib.php that would to begin with call out that the function is being called. This was not getting calledback prior to module deletion. If I prohibit teachers from being able to edit existing tags, I can make this sort of work ( albeit hackey still ) by checking for certain tags on module an admin would put in place and make sure non-admins cannot delete these modules. Any idea how to make it more reliably call the callback? I would have loved to see an event being created prior to the course deletion but unfortunately there is only one after deletion of a module. 


Thoughts?


function local_myplugin_pre_course_module_delete($cm) {

   debugging('Reached Pre Course Module Del');

 }