Update the current user's hotkeys configuration
(self, request, *args, **kwargs)
| 394 | return Response({'error': 'Failed to retrieve hotkeys configuration'}, status=500) |
| 395 | |
| 396 | def patch(self, request, *args, **kwargs): |
| 397 | """Update the current user's hotkeys configuration""" |
| 398 | try: |
| 399 | serializer = HotkeysSerializer(data=request.data) |
| 400 | |
| 401 | if not serializer.is_valid(): |
| 402 | return Response({'error': 'Invalid hotkeys configuration', 'details': serializer.errors}, status=400) |
| 403 | |
| 404 | user = request.user |
| 405 | |
| 406 | # Security check: Ensure user can only update their own hotkeys |
| 407 | if not user.is_authenticated: |
| 408 | return Response({'error': 'Authentication required'}, status=401) |
| 409 | |
| 410 | # Update user's hotkeys |
| 411 | user.custom_hotkeys = serializer.validated_data['custom_hotkeys'] |
| 412 | user.save(update_fields=['custom_hotkeys']) |
| 413 | |
| 414 | logger.info(f'Updated hotkeys for user {user.pk}') |
| 415 | |
| 416 | return Response(serializer.validated_data, status=200) |
| 417 | |
| 418 | except Exception as e: |
| 419 | logger.error(f'Error updating hotkeys for user {request.user.pk}: {str(e)}') |
| 420 | return Response({'error': 'Failed to update hotkeys configuration'}, status=500) |