How to get logged in user's role

Hi,

I would like to get the logged in users role

what i have done so far is

class CourseFeedback(Document):
def validate(self):
if frappe.session.user==‘Administrator’:
frappe.throw((“Hello admin”))
frappe.throw(
(frappe.session.role))

but i get empty popup

please help me

3 Likes

for .py
frappe.get_roles(frappe.session.user)
for .js
user_role

7 Likes

@jsukrut
thanks it worked awsome

i have another doubt like this way can i get full name of current user

@shahid_khan021
use frappe.db.get_value()
eg.
frappe.db.get_value(“User”,{“name”:manager},“full_name”)

2 Likes

@shahid_khan021
frappe.db.get_value(“User”,{“name”:frappe.session.user},“full_name”)

4 Likes

@jsukrut thanks again friend

1 Like

@jsukrut, the return of “frappe.db.get_value(“User”,{“name”:frappe.session.user},“full_name”)” is an object. Do you know how to parse the object to get the full name as a string? Thanks!

I think it will return ‘unicode’ .like <type ‘unicode’>

If you have object then you can access properties with ‘.’ (member operator)

eg.
user_doc = frappe.get_doc(“User”,name)
print user_doc.first_name
print user_doc.last_name

for typecast

str(user_doc.last_name)

1 Like

How about getting the password of the session?

you can’t access password through get_doc. What is your use case?