-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address mobile device push notification delivery issue when user had …
…> 1 registered device (#2421) # What this PR does Address issue where if the user had multiple registered devices w/ FCM, doing django queries like `.first()` could potentially pick the wrong device. Do this in two ways: 1. set the `DELETE_INACTIVE_DEVICES` `fcm_django` setting to `True`. According to the [docs](https://github.com/xtrinch/fcm-django/blob/20e275618b47cea4e1b4dd3b1a8c640a164a7ec5/README.rst?plain=1#L127-L130), this works as follows: > devices to which notifications cannot be sent, are deleted upon receiving error response from FCM 2. Customizing the `FCMDevice` model provided by `fcm_django`. Add a new method, `get_active_device_for_user`, so that we can centralize the logic for this rather than duplicating `FCMDevice.objects.filter(user=user).first()` ## Which issue(s) this PR fixes https://raintank-corp.slack.com/archives/C0229FD3CE9/p1688461915752119 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) (N/A) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required)
- Loading branch information
1 parent
01b1be8
commit 425ffbb
Showing
12 changed files
with
80 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
|
||
from apps.mobile_app.models import FCMDevice | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_active_device_for_user_works(make_organization_and_user): | ||
_, user = make_organization_and_user() | ||
FCMDevice.objects.create(user=user, registration_id="inactive_device_id", active=False) | ||
active_device = FCMDevice.objects.create(user=user, registration_id="active_device_id", active=True) | ||
|
||
assert FCMDevice.objects.filter(user=user).count() == 2 | ||
assert FCMDevice.get_active_device_for_user(user) == active_device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters