Hi there hope you guys are doing good
there is a feature in erp where admin can do impersonate other users and use erp as that user
but i want to know how we can enable this feature for all users to impersonate each other thankyou
Hello,
Administrator can impersonate other users, but the reverse is not allowed.
If you want to implement this, you can refer to the following link and apply the logic to your custom app:
Note: This is risky as it may lead to security breaches, allowing anyone to change other users’ data.
yes for that we have activity logs and also we have send notification to other users
should i just use this script ?
there is no such directory in my app???
i have my custom app but this settting is avalible in the frappe core file will it still take effect if i make changes to that
Yes, In your custom app just use condition like
if (frappe.session.user != "Administrator" && frm.doc.name != "Administrator")
change according to your requirement
create user.js file and add this:
frappe.ui.form.on("User", {
refresh: function (frm) {
if (
frappe.session.user !== "Administrator" &&
frm.doc.name !== "Administrator" &&
frm.doc.name !== frappe.session.user
) {
frm.add_custom_button(__("Impersonate"), () => {
if (frm.doc.restrict_ip) {
frappe.msgprint({
message:
"There's IP restriction for this user, you can not impersonate as this user.",
title: "IP restriction is enabled",
});
return;
}
frappe.prompt(
[
{
fieldname: "reason",
fieldtype: "Small Text",
label: "Reason for impersonating",
description: __("Note: This will be shared with user."),
reqd: 1,
},
],
(values) => {
frappe
.xcall("frappe.core.doctype.user.user.impersonate", {
user: frm.doc.name,
reason: values.reason,
})
.then(() => window.location.reload());
},
__("Impersonate as {0}", [frm.doc.name]),
__("Confirm")
);
});
}
},
});
then add this file path to hooks.py
in doctype_js
Exmaple:
doctype_js = {
"User": "YOUR_MODULE/client_overrides/user.js",
}
o i see now i already worked on the user file thanks i will test this and comeback to you
can you guide me where should i create this js file in which folder
In your app’s module. You can create any folder like client_overrides
in that you can add this.
Read above answer!
thank you