Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrinch committed Dec 16, 2021
1 parent 8f312d1 commit c6cedaf
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions fcm_django/api/rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def validate(self, attrs):
# user
user = self.context["request"].user
registration_id = attrs.get("registration_id")

if request_method == "update":
if registration_id:
if user is not None and user.is_authenticated:
Expand All @@ -66,15 +66,11 @@ def validate(self, attrs):
).exclude(id=primary_key)
elif request_method == "create":
if user is not None and user.is_authenticated:
devices = Device.objects.filter(
registration_id=registration_id
)
devices = Device.objects.filter(registration_id=registration_id)
devices.filter(~Q(user=user)).update(active=False)
devices = devices.filter(user=user, active=True)
else:
devices = Device.objects.filter(
registration_id=registration_id
)
devices = Device.objects.filter(registration_id=registration_id)

if devices:
raise ValidationError({"registration_id": "This field must be unique."})
Expand Down

0 comments on commit c6cedaf

Please sign in to comment.