mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 23:46:53 +00:00
Add authorization check in UpdateUserWalletView to restrict updates to the user's own wallet
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m32s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m32s
This commit is contained in:
parent
2368ff408a
commit
a8adddfda4
10
api/views.py
10
api/views.py
@ -53,8 +53,18 @@ class UpdateUserWalletView(generics.UpdateAPIView):
|
||||
serializer_class = CustomUserByWalletBalanceSerializer
|
||||
permission_classes = (permissions.IsAuthenticated,)
|
||||
queryset = User.objects.all()
|
||||
lookup_field = "pk"
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
id_to_update = kwargs.get("pk")
|
||||
user_id = request.user.id
|
||||
print(f"User ID: {user_id}")
|
||||
print(f"ID to update: {id_to_update}")
|
||||
if user_id != id_to_update:
|
||||
return Response(
|
||||
{"message": "You are not authorized to update this user."},
|
||||
status=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
wallet_balance = request.data.get("wallet_balance")
|
||||
if not wallet_balance:
|
||||
return Response(
|
||||
|
Loading…
x
Reference in New Issue
Block a user