Current Session User Role - Python

Hello,

I want to check if the session user has a certain role or not.
I’m writing a server script to achieve so.

Following is my code:
user = frappe.session.user
if “Laboratory User” in frappe.get_roles(user):

But I get the error - Server Error

AttributeError: module has no attribute ‘get_roles’

What is the correct way of doing so ?

Thanks.

1 Like

Have you figured this out? :thinking:

Has anyone found a solution?

FYI

I used following code to check whether the current user has been assigned System Manager role.

user_doc = frappe.get_doc('User', frappe.user)
has_special_role = [r for r in user_doc.roles if r.role == 'System Manager']