diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index d4ae9379fa..f1a40e106f 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -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", diff --git a/frappe/contacts/doctype/contact/contact.py b/frappe/contacts/doctype/contact/contact.py index 242b08561e..a5b88f2fda 100644 --- a/frappe/contacts/doctype/contact/contact.py +++ b/frappe/contacts/doctype/contact/contact.py @@ -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()