fix: api's to accept & send invitation
This commit is contained in:
parent
5e875c921e
commit
1930a64532
@ -1,7 +1,7 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.translate import get_all_translations
|
from frappe.translate import get_all_translations
|
||||||
from frappe.utils import cstr
|
from frappe.utils import validate_email_address, split_emails, cstr
|
||||||
from frappe.utils.telemetry import POSTHOG_HOST_FIELD, POSTHOG_PROJECT_FIELD
|
from frappe.utils.telemetry import POSTHOG_HOST_FIELD, POSTHOG_PROJECT_FIELD
|
||||||
|
|
||||||
|
|
||||||
@ -67,3 +67,43 @@ def check_app_permission():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist(allow_guest=True)
|
||||||
|
def accept_invitation(key: str = None):
|
||||||
|
if not key:
|
||||||
|
frappe.throw("Invalid or expired key")
|
||||||
|
|
||||||
|
result = frappe.db.get_all("CRM Invitation", filters={"key": key}, pluck="name")
|
||||||
|
if not result:
|
||||||
|
frappe.throw("Invalid or expired key")
|
||||||
|
|
||||||
|
invitation = frappe.get_doc("CRM Invitation", result[0])
|
||||||
|
invitation.accept()
|
||||||
|
invitation.reload()
|
||||||
|
|
||||||
|
if invitation.status == "Accepted":
|
||||||
|
frappe.local.login_manager.login_as(invitation.email)
|
||||||
|
frappe.local.response["type"] = "redirect"
|
||||||
|
frappe.local.response["location"] = "/crm"
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def invite_by_email(emails: str, role: str):
|
||||||
|
if not emails:
|
||||||
|
return
|
||||||
|
email_string = validate_email_address(emails, throw=False)
|
||||||
|
email_list = split_emails(email_string)
|
||||||
|
if not email_list:
|
||||||
|
return
|
||||||
|
existing_members = frappe.db.get_all("User", filters={"email": ["in", email_list]}, pluck="email")
|
||||||
|
existing_invites = frappe.db.get_all(
|
||||||
|
"CRM Invitation",
|
||||||
|
filters={"email": ["in", email_list], "role": ["in", ["Sales Manager", "Sales User"]]},
|
||||||
|
pluck="email",
|
||||||
|
)
|
||||||
|
|
||||||
|
to_invite = list(set(email_list) - set(existing_members) - set(existing_invites))
|
||||||
|
|
||||||
|
for email in to_invite:
|
||||||
|
frappe.get_doc(doctype="CRM Invitation", email=email, role=role).insert(ignore_permissions=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user