From bd32237fa5a580bad7bb19fb54f703a49e7f6c5a Mon Sep 17 00:00:00 2001 From: Ritvik Sardana Date: Thu, 26 Feb 2026 13:43:32 +0530 Subject: [PATCH] fix: use hooks to get allowed fields in the API --- frappe/core/api/user_invitation.py | 19 +++++++++++++++++-- .../user_invitation/internal_doc/index.md | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/frappe/core/api/user_invitation.py b/frappe/core/api/user_invitation.py index 814bb854f4..c44ac563b6 100644 --- a/frappe/core/api/user_invitation.py +++ b/frappe/core/api/user_invitation.py @@ -6,7 +6,7 @@ from frappe.core.doctype.user_invitation.user_invitation import UserInvitation @frappe.whitelist(methods=["POST"]) def invite_by_email( - emails: str, roles: list[str], redirect_to_path: str, app_name: str = "frappe", **args + emails: str, roles: list[str], redirect_to_path: str, app_name: str = "frappe", **kwargs ) -> dict[str, list[str]]: UserInvitation.validate_role(app_name) @@ -42,6 +42,9 @@ def invite_by_email( to_invite = list( set(email_list) - set(disabled_user_emails) - set(accepted_invite_emails) - set(pending_invite_emails) ) + + extra_args = get_allowed_invite_params(app_name, kwargs) + for email in to_invite: frappe.get_doc( doctype="User Invitation", @@ -49,7 +52,7 @@ def invite_by_email( roles=[dict(role=role) for role in roles], app_name=app_name, redirect_to_path=redirect_to_path, - **args, + **extra_args, ).insert(ignore_permissions=True) return { @@ -60,6 +63,18 @@ def invite_by_email( } +def get_allowed_invite_params(app_name: str, kwargs: dict) -> dict: + # get extra args based on app_name + allowed_params = frappe._dict() + extra_invite_params = frappe.get_hooks("user_invitation", app_name=app_name).get( + "extra_invite_params", [] + ) + for param in extra_invite_params: + if param in kwargs: + allowed_params[param] = kwargs[param] + return allowed_params + + @frappe.whitelist(allow_guest=True, methods=["GET"]) def accept_invitation(key: str) -> None: _accept_invitation(key, False) diff --git a/frappe/core/doctype/user_invitation/internal_doc/index.md b/frappe/core/doctype/user_invitation/internal_doc/index.md index 49f3241eeb..f6303e4737 100644 --- a/frappe/core/doctype/user_invitation/internal_doc/index.md +++ b/frappe/core/doctype/user_invitation/internal_doc/index.md @@ -28,6 +28,10 @@ Define user invitation hooks in your app's `hooks.py` file. An example is shown A map of `only_for` roles to a list of roles that are allowed to be invited to your app. +- `extra_invite_params` + + A list of additional parameters that can be passed when creating a user invitation. Optional parameter. + - `after_accept` Dot path of the function to execute after the user accepts the invitation.