From 7313c905ea8ef1885f68a2c7f5da79a897fe8ccd Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Sun, 16 Mar 2025 19:58:56 +0000 Subject: [PATCH] Attach user object when using api_key_required decorator --- PyRIGS/decorators.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PyRIGS/decorators.py b/PyRIGS/decorators.py index ca7cd8ea..fe7d1825 100644 --- a/PyRIGS/decorators.py +++ b/PyRIGS/decorators.py @@ -79,7 +79,9 @@ def api_key_required(function): """ Decorator for views that checks api_pk and api_key. Failed users will be given a 403 error. - Should only be used for urls which include and kwargs + Should only be used for urls which include and kwargs. + + Will update the kwargs to include the user object if successful (under the key 'user'). """ def wrap(request, *args, **kwargs): @@ -97,6 +99,7 @@ def api_key_required(function): try: user_object = models.Profile.objects.get(pk=userid) + kwargs = {**kwargs, 'user': user_object} except models.Profile.DoesNotExist: return error_resp