Change User Permission or role in server script

Hello everyone,

I need to change user permission or role after they are approved by admin, I prefer to run a server script on update user to check the user and change user permissions.
How can I do that?

Thanks in advance.

For the first part, checking user permission in server script:

users = frappe.db.get_list('User')

for i in users:
    has_role = frappe.get_all('Has Role', filters=dict(
    #print(, has_role)

I don’t have anything for changing user permissions atm.

To add a user role:

user = frappe.get_doc(“User”, frappe.session.user)
user.append(“roles”, {“role”:”Employee”})

1 Like