Access denied exception when calling User#getEmail() as a non-admin user???

Hi guys,

I have just found out that if I try to fetch a User inside my plugin by calling UserModel#findUserById() and then call getEmail() method on the instance, I will get an access denied exception in case I am logged in as a normal user (it works fine for admin users though). I can call getters for id or name without any problem but the email getter is somehow restricted inside.
Is there any way how to avoid that exception and get email of the user?

Thank you in advance for any help!

- Jan Pfeffer

Comment actions Permalink

Hi Jan,

Please grant the user you are trying to retrieve the data under "View user profile" permission.
Or perform the operation not under a user via (sic! not open APi) SecurityContextEx.runAsSystem

Comment actions Permalink

Hi Yegor,

the second option sound good... only if the class was a part of the open api... ;)
So then I will have to live with the first option, I guess.

Thank you!



Please sign in to leave a comment.