Setting desktop icons per role

Is it possible to set Desktop icons based on user role? My scenario is that user having the same role should a have a set of uniform icons by default

Not as far as I know, but here’s a workaround I use when a user is created:

from frappe.desk.doctype.desktop_icon.desktop_icon import set_desktop_icons
cur_user = frappe.session.user
frappe.session.user = email_of_the_account_we_want_to_modify #set_desktop_icon need the frappe.session.user of the account we want to modify
set_desktop_icons(["Sales Invoice", "Customer", "Service", "..."])
frappe.session.user = cur_user

Thanks I will try this

This was very helpful.

That method works well for DocTypes since they can be implicitly converted into an icon. Reports and other kinds of icons require a couple more steps so I figured this would be a good place to leave some notes about it.

Import the functions you need:

from frappe.desk.doctype.desktop_icon.desktop_icon import set_desktop_icons, add_user_icon

Get the users you want to effect:

users = frappe.get_all('User', filters={}, fields=["*"])

Retrieve some information we will be working with:

for user in users:
    frappe.session.user =
    cur_user = frappe.session.user
    roles = frappe.get_roles(frappe.session.user)

Add an instance of non-DocType icons we want to use. The link field is just what comes in the URI after the “Desk#”, so I have included an example query report as well as a report builder report:

add_user_icon("Employee", _report="Extensions", label="Extensions", link="query-report/Extensions", standard=1)
add_user_icon("Issue", _report="Open Issues", label="Open Issues", link="List/Issue/Report/Open Issues", standard=1)

Now you can append all of your icons into a nice list depending on the user’s current roles. Don’t worry about duplicates, the add_user_icon function will only take in unique values:

if "Employee" in roles:

Now finally, we make the changes to the current user and then save that to the session:

frappe.session.user = cur_user

Then just need to modify it so it can run automatically as you need, just be aware that “set_desktop_icon” will forget all of the old icons and only populate your desktop with what is in the list you send it.

Hopefully this helps!