From 74c26ac34d32ca4e35c2f8b62523512ddab00bec Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Tue, 2 Aug 2022 19:16:53 +0530 Subject: [PATCH] fix: use `throw` --- frappe/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index d017a2cc6b..c2a24e6ad0 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -832,12 +832,14 @@ def only_for(roles: list[str] | tuple[str] | str, message=False): roles = (roles,) if not set(roles).intersection(get_roles()): - if message: - msgprint( - _("This action is only allowed for {}").format(bold(", ".join(roles))), - _("Not Permitted"), - ) - raise PermissionError + if not message: + raise PermissionError + + throw( + _("This action is only allowed for {}").format(bold(", ".join(roles))), + PermissionError, + _("Not Permitted"), + ) def get_domain_data(module):