Restrict profile editing to user with student role!

Restrict profile editing to user with student role!

by Eduardo Hm -
Number of replies: 3

Hi to everyone,

I commented what is the "problem" I have in my Moodle platform in version 3.1.6.

I have been investigating if there is a possibility that a user with a "student" role does not have permission to edit the name and surname in the edition of their profile. I have looked at the restrictions at the role level and there is no such thing as the restriction to prohibit editing the profile itself.

So my question is, how can I do, at the code level, prevent a user with a student role from modifying neither his name and lastname, and that those two boxes in the profile appear with the readonly property?

Thank you very much in advance.

Average of ratings: -
In reply to Eduardo Hm

Re: Restrict profile editing to user with student role!

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

It may depend where they are being set from initially - if you are using one of the external authentication methods (eg. LDAP, external database, etc) then the mapped fields can be locked in those settings.

However, if you are using self-registration of some sort then this might be difficult as you would need to allow them to create it and then not allow them to edit it. Otherwise you may need to dig into the code to find out how the external methods lock it down and write some code based on that (someone else may be able to give more advice in that area - I've only used the restrictions from the authentication methods myself).

Richard

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

Re: Restrict profile editing to user with student role!

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Further to Richard's reply, I think practically all authentication methods, including self-registration provide the option to lock user fields, including the first name and surname fields. This would apply to all authenticated users though, not just users with the role of student.

Average of ratings: Useful (2)
In reply to Helen Foster

Re: Restrict profile editing to user with student role!

by Eduardo Hm -

Hi,

Thank you very much for the solutions provided. These solutions are based on the configuration of authentication methods (LDAP, CAS ...), and may or may not block the fields we want is a generic solution, since it applies to all system roles. The ideal and what I am looking for is that only users with a student role can not edit their profile (name and surname) but any other user with another role, for example, teacher role or course creator, can modify name and last names of the students.

Anyway, thank you very much for the instructions.

Regards