jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.24k stars 605 forks source link

Serializer is hard code and isn't using UPDATE_ON_DUPLICATE_REG_ID setting #637

Closed ghost closed 2 years ago

ghost commented 2 years ago

https://github.com/jazzband/django-push-notifications/blob/13a2c6f7b34ab884f65e2791841549975795bebf/push_notifications/api/rest_framework.py#L58

This serializer has hard code to check for duplicate registration_id , so even if i set UPDATE_ON_DUPLICATE_REG_ID in setting the update registration_id on duplicate doesn't work and always return

{
  "registration_id": [
    "This field must be unique."
  ]
}

regardless of the setting

a quick fix should be checking if UPDATE_ON_DUPLICATE_REG_ID is set in setting, if it's set then don't check for duplicate device on create

elif request_method == "create" and not settings.UPDATE_ON_DUPLICATE_REG_ID:
        devices = Device.objects.filter(registration_id=attrs["registration_id"])
ghost commented 2 years ago

it was a mistake, sorry i forgot to put the setting in PUSH_NOTIFICATIONS_SETTINGS