In moodle 4.1, due to some security reasons, i have to remove the calendar:manageownentries capability from the authenticated user. I have to assign this capability to a authenticated user which is teacher in any course. This capability is to show the 'add event' button on calendar on the dashboard page.
I remove the capability from the authenticated user role and assign this capability to the teacher role on the course level not on the system level. I know the teacher is also an authenticated user. So if I remove the capability from an authenticated user, it will not work for the teacher(course level) either.
So please let me know how can i show the 'add event' button on the calendar of teachers (course level).
EDIT
Now the requirement has been changed. We have a theme installed in our application and we have to hide the button through the theme. We can make the code changes in the theme code.
I checked and I found out that we only can override the renderer and templates, not general functions. So I am looking for a fix that we can apply through the theme.
Thanks
First thing first : Do not edit code in calendar/lib.php. This is part of the core code and under no circumstances should you touch it. What you could do is write a plugin or a subplugin.
Programmaticaly you can check if someone is teacher anywhere on the site like this : (not my code, but hell knows I use it more than often^^) <?php
If it returns true you can give the role to the teachers (it checks for the connected user. You can adapt the function to target all users but bewarn that it may be one hell of a query depending of the number of users you have, (we have several thousands user, such a request could end with a timeout).
Within the site you can also go to the administration > users > role. What you could do would be add the authorisations of the role directly to the editing teacher role, (not great). Another way which would be cleaner (even if a bit tedious), would be to manually give the roles. This is the best way to avoid conflicts / programming errors and every queries. But it'll depend on your organization.