ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Get user roles in controllers

Hi, in my som_modules.py i want to add validate by the roles, how i can do this? how i can get the roles?

Thanks

Try frappe.get_roles() to get the roles of the current user.

3 Likes

How do we do the same in client side?
and how can we check for a specific role for logged in user in client side?

okey Found it .

frappe.user.has_role(“Role”)

3 Likes

frappe.user.has_role(“Role”) will fetch all the users with role Role? Isn’t working for me.

Just to update, it is now frappe.user_roles in “Frappe Framework: v11.1.44 (master)” version

2 Likes

frappe.user_roles.includes("<Your Role>") This will return true if the user has <Your Role> .
This will work on client side.

This is not working

Works fine for me.

I need to get user roles in portal page.How can I get the roles in portal pages?