Merge pull request #24905 from barredterra/invite-contact-as-user

fix: invite contact as user
This commit is contained in:
Raffael Meyer 2024-02-17 16:53:06 +01:00 committed by GitHub
commit 526359b20c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 14 deletions

View file

@ -21,7 +21,12 @@ frappe.ui.form.on("Contact", {
}
}
if (!frm.doc.user && !frm.is_new() && frm.perm[0].write) {
if (
!frm.doc.user &&
!frm.is_new() &&
frm.perm[0].write &&
frappe.boot.user.can_create.includes("User")
) {
frm.add_custom_button(__("Invite as User"), function () {
return frappe.call({
method: "frappe.contacts.doctype.contact.contact.invite_user",

View file

@ -194,25 +194,25 @@ def get_default_contact(doctype, name):
@frappe.whitelist()
def invite_user(contact):
def invite_user(contact: str):
contact = frappe.get_doc("Contact", contact)
contact.check_permission()
if not contact.email_id:
frappe.throw(_("Please set Email Address"))
if contact.has_permission("write"):
user = frappe.get_doc(
{
"doctype": "User",
"first_name": contact.first_name,
"last_name": contact.last_name,
"email": contact.email_id,
"user_type": "Website User",
"send_welcome_email": 1,
}
).insert(ignore_permissions=True)
user = frappe.get_doc(
{
"doctype": "User",
"first_name": contact.first_name,
"last_name": contact.last_name,
"email": contact.email_id,
"user_type": "Website User",
"send_welcome_email": 1,
}
).insert()
return user.name
return user.name
@frappe.whitelist()