mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Only allow PartStar creation for the currently authenticated user
This commit is contained in:
parent
70f1097ea0
commit
d245e58990
@ -6,8 +6,10 @@ Provides a JSON API for the Part app
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
|
||||
from rest_framework import filters
|
||||
from rest_framework import generics, permissions
|
||||
from rest_framework.serializers import ValidationError
|
||||
|
||||
from django.db.models import Q
|
||||
from django.conf.urls import url, include
|
||||
@ -161,6 +163,16 @@ class PartStarList(generics.ListCreateAPIView):
|
||||
queryset = PartStar.objects.all()
|
||||
serializer_class = PartStarSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
|
||||
# Ensure the 'user' field is the authenticated user
|
||||
user_id = request.data['user']
|
||||
|
||||
if not str(user_id) == str(request.user.id):
|
||||
raise ValidationError({'user': 'Parts can only be starred for the currently authenticated user'})
|
||||
|
||||
return super(generics.ListCreateAPIView, self).create(request, *args, **kwargs)
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticatedOrReadOnly,
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user