fix: use hooks to get allowed fields in the API
This commit is contained in:
parent
c23d188fbf
commit
bd32237fa5
2 changed files with 21 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue