-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from wahni-green/impersonation
feat: user impersonation
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2023, Wahni IT Solutions Pvt. Ltd. and Contributors | ||
// MIT License. See license.txt | ||
|
||
|
||
frappe.ui.form.on("User", { | ||
refresh: function(frm) { | ||
if (!frm.doc.__islocal && frm.doc.enabled && frappe.user.has_role("System Manager")) { | ||
frm.add_custom_button(__("Impersonate"), function() { | ||
frappe.call({ | ||
method: "genie.utils.impersonation.generate_impersonation_url", | ||
args: { | ||
"user": frm.doc.name | ||
}, | ||
callback: function(r) { | ||
if (!r.exc && r.message) { | ||
let impersonate_url = `<a href=${r.message}>this link</a>`; | ||
frappe.msgprint( | ||
__("Please open {0} in an incognito window to impersonate {1}", [impersonate_url, frm.doc.name]), | ||
); | ||
} | ||
} | ||
}); | ||
}, __("Password")); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Copyright (c) 2023, Wahni IT Solutions Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe import _ | ||
from frappe.www.login import _generate_temporary_login_link | ||
|
||
|
||
@frappe.whitelist() | ||
def generate_impersonation_url(user): | ||
frappe.only_for("System Manager") | ||
|
||
if not frappe.db.get_single_value("Genie Settings", "enable_user_impersonation"): | ||
frappe.throw(_("User Impersonation is disabled")) | ||
if user == "Administrator": | ||
frappe.throw(_("You cannot impersonate Administrator")) | ||
|
||
return _generate_temporary_login_link(user, 1) |