Attach user object when using api_key_required decorator

This commit is contained in:
Joe Banks
2025-03-16 19:58:56 +00:00
parent 074d40ea03
commit 7313c905ea

View File

@@ -79,7 +79,9 @@ def api_key_required(function):
""" """
Decorator for views that checks api_pk and api_key. Decorator for views that checks api_pk and api_key.
Failed users will be given a 403 error. Failed users will be given a 403 error.
Should only be used for urls which include <api_pk> and <api_key> kwargs Should only be used for urls which include <api_pk> and <api_key> kwargs.
Will update the kwargs to include the user object if successful (under the key 'user').
""" """
def wrap(request, *args, **kwargs): def wrap(request, *args, **kwargs):
@@ -97,6 +99,7 @@ def api_key_required(function):
try: try:
user_object = models.Profile.objects.get(pk=userid) user_object = models.Profile.objects.get(pk=userid)
kwargs = {**kwargs, 'user': user_object}
except models.Profile.DoesNotExist: except models.Profile.DoesNotExist:
return error_resp return error_resp