From 0bdafc6df8aef5724a67162042f1b44c978d291f Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 8 Apr 2025 12:08:29 +0530 Subject: [PATCH] [UPDT] HORILLA: Added a any_permission_required decorater to check if any of the permission exists --- horilla/decorators.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/horilla/decorators.py b/horilla/decorators.py index d5c172fb0..e7210d728 100755 --- a/horilla/decorators.py +++ b/horilla/decorators.py @@ -52,6 +52,24 @@ def permission_required(function, perm): return _function +@decorator_with_arguments +def any_permission_required(function, perms): + def _function(request, *args, **kwargs): + if any(request.user.has_perm(perm) for perm in perms): + return function(request, *args, **kwargs) + + else: + messages.info(request, "You dont have permission.") + previous_url = request.META.get("HTTP_REFERER", "/") + key = "HTTP_HX_REQUEST" + if key in request.META.keys(): + return render(request, "decorator_404.html") + script = f'' + return HttpResponse(script) + + return _function + + decorator_with_arguments = ( lambda decorator: lambda *args, **kwargs: lambda func: decorator( func, *args, **kwargs