Disable teacher edit and delete for activity

Re: Disable teacher edit and delete for activity

by Pedro Laginha -
Number of replies: 6

Hi,

I would be happy if there is a way to disable 'Delete' option in activity context menu in edit mode... Someone knows a solution for that?

Thank's in advance. And sorry for my poor english!

Pedro L.

In reply to Pedro Laginha

Re: Disable teacher edit and delete for activity

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers

Can you do this directly in the Moodle interface?

Go to the course and click on the activity that you don't want teacher to edit/delete.

Click on "permissions" in the admin block.

Choose the role you are looking to limit in the drop down box:


Find the "moodle/course:manageactivities" permission.

Change the permission to prevent or prohibit.


Then, when the teacher turns on editing mode, they will not be able to edit/delete this particular activity.

In reply to John Provasnik

Re: Disable teacher edit and delete for activity

by Pedro Laginha -

Ok John, thank you for your answer.

I did it. But when you said "Go to the course and click on the activity that you don't want teacher to edit/delete" do you mean by clicking on the title of one activity's instance? When I do that, the permissions changes that you made only applies to that instance, not to all instances of the activity. I need to do it automatically to all instances of that activity, to all courses where instances will be created.

I note that the solution you wrote also remove the 'Move' operation from the action menu and that is a problem to me. We want that teacher cannot change or delete the instance but still can move it to another section.

Can you tell me if I am doing something different that you wrote? And if there is solution for my other questions?

Thank's a lot!

Pedro L.

In reply to Pedro Laginha

Re: Disable teacher edit and delete for activity

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers

Ah, so that's why you were trying to do this via some coding. No, I personally don't know how to do that (other than via the Moodle interface) so hopefully someone else will chime in.

As for moving the activity, I believe moving/editing/and deleting all are controlled by the same permission "moodle/course:manageactivities


Edit: Even if a teacher cannot move the activity, they can move the activities other activities that are around it. So essentially, they can still manipulate where the activity will be by moving the other activities.

In reply to John Provasnik

Re: Disable teacher edit and delete for activity

by Pedro Laginha -

Hi John,

Thank you again for your response. I think you are right when you say that moving, editing and deleting are controlled by the same permission. And that's no problem for me that the teachers manipulate de location of the activity.

Now, I have one solution for this that works and that I'm testing on my development computer. But... I really don't like it! What I've made was configure our theme - organization customized - to load a javascript file and use some javascript code to program DOM and destroy  the options Edit and Delete. That can easilly done using the preload YUI framework by creating CSS Selectors and remove the related nodes. That works but... if something changes on page layout, maybe the selectors stop to work!... So, is not a good solution...

Maybe I will look again for the server activity code. I read, and test it, that we can prevent form editing by adding a $mform->freeze() on form definition. That works but still have 'Delete' action to solve. And I really don't want to develop some code 'out-of-the-box' because I'll need some extra efforts, more time and maybe I'll have some upgrade complications.

Pedro L.

In reply to Pedro Laginha

Re: Disable teacher edit and delete for activity

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Without the need for javascript, you could just use css to hide the edit and delete options for the activity

Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Disable teacher edit and delete for activity

by Adarsh Shukla -

Can you please let us know, how can we do this with CSS