To check user role from client side
If user role Account Manager is present, then first msgprint will print value greater than one
To check user role from python
1)
2) to check other user role
You can use following(python) code to check particular user roles.
Above script will check user role for 'kolate.sambhaji@gmail.com', you can pass any user id to check its roles.
@frappe.whitelist(allow_guest=True)
def validate_role(self, method):
user="kolate.sambhaji@gmail.com"
frappe.msgprint(_("In role validate function"))
role_list = frappe.db.sql("""select name,owner,parent,idx,role from tabUserRole where parent=%s and role='Blogger'""",
user)
if len(role_list) > 0:
frappe.msgprint("user is blogger")
frappe.msgprint(role_list) #this will test user role blogger
This will print -1 if user role Account Manager is not presentIf user role Account Manager is present, then first msgprint will print value greater than one
To check user role from python
1)
frappe.get_roles()
will give you all roles of current user2) to check other user role
You can use following(python) code to check particular user roles.
@frappe.whitelist(allow_guest=True)
def validate_role(self, method):
user="kolate.sambhaji@gmail.com"
frappe.msgprint(_("In role validate function"))
role_list = frappe.db.sql("""select name,owner,parent,idx,role from tabUserRole where parent=%s and role='Blogger'""",
user)
frappe.msgprint(role_list) #this will test user role blogger
Above script will check user role for 'kolate.sambhaji@gmail.com', you can pass any user id to check its roles.
No comments:
Post a Comment