Commit graph

19 commits

Author SHA1 Message Date
Joey Orlando
aa0d4468db
Fix rounding issue with displayed time when sending "You're going oncall" push notification (#3872)
# Which issue(s) this PR fixes

So because of how we run the task that sends the "You're going oncall"
push notifications, there are sometimes rounding "errors" in the
displayed text of the push notification. For example, if you've
configured your mobile app to remind you 12h before your on-call shift
starts it sometimes might say:

> You're going oncall in 11 hours

This is because of the [background task being executed every
10mins](https://github.com/grafana/oncall/blob/dev/engine/settings/base.py#L545-L548)
and us continually checking if now is the appropriate time to send the
notification (we took this approach because we don't have any easy way
of emitting an event exactly when a shift starts.. yay ical).

This PR corrects that by rounding to the closest configuration value
that we allow.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2024-02-09 15:31:34 -05:00
Yulya Artyukhina
2edae70b04
Update wording for mobile push notifications timing choices (#3253)
# What this PR does
Update wording for mobile push notifications timing choices

## Which issue(s) this PR fixes

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-11-02 11:37:28 +00:00
Yulya Artyukhina
76a0643bc5
"Going oncall" notification settings (#3187)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2023-10-30 13:44:18 +00:00
Joey Orlando
dd338372ab
increase mobile app verification token TTL from 1 minute to 5 minutes (#2859)
# What this PR does

Trying to connect a mobile app emulator, following the instructions
[here](https://github.com/grafana/oncall-mobile-app#getting-started), to
a cloud stack is incredibly difficult given the 1 minute token TTL. You
need to retrieve the token from the HTTP response in your browser's
inspect panel, plug that token into the `make run` command and cross
your fingers that the emulator starts up in < 45 seconds before the
token expires.

This PR increases the verification token TTL from 1 minute to 5 minutes.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-08-22 17:09:59 +02:00
Vadim Stepanov
424b2b80f8
Add backend support for push notification sounds with custom extensions (#2759)
# What this PR does

Instead of always adding `.aiff` or `.mp3` at the end of notification
sound names depending on the platform (iOS vs Android), add them only if
no extension is present already. This should make it possible to use
sounds with custom extensions.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-08-07 09:55:17 +00:00
Vadim Stepanov
c855258018
Add mobile app push notifications for shift swap requests (#2717)
# What this PR does

Adds mobile app push notifications for shift swap requests.

## Which issue(s) this PR fixes

https://github.com/grafana/oncall/issues/2630

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-08-02 12:26:45 +01:00
Joey Orlando
67393dd2ba
allowing storing/updating time_zone in mobile app user settings table (#2601)
# What this PR does

closes #2450 

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-07-20 14:12:54 -04:00
Joey Orlando
ce3996c5ff
modify FCMDevice model to be a proxy model so that we dont create a table for it 2023-07-05 18:38:38 +02:00
Joey Orlando
425ffbb740
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](20e275618b/README.rst (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)
2023-07-05 15:14:46 +00:00
Joey Orlando
cc20c9dfdd
re-enable mypy GitHub Actions CI job (#2390)
# What this PR does

```bash
❯ mypy .
Success: no issues found in 595 source files
```

- re-enable the mypy CI check
- fixes all `django-manager-missing` mypy errors
- disable all other rules currently giving mypy errors
- changing the approach here. rather than enforcing that backend
contributors fix >= 1 `mypy` error on their PR, lets simply disable all
the rules that're currently returning errors and slowly re-enable these
one at a time #2392

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required) (N/A)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (N/A)
2023-06-29 14:01:52 +00:00
Joey Orlando
572131b921
add user locale field to mobile app user settings table + change going on call push notification text (#2131)
# What this PR does

- add user locale field to mobile app user settings table + add a test
that sends `PATCH` requests to this endpoint
- change "you're going on call" push notification text to include
localized shift time. The general format is now:
  ```python
f"You're going on call in {time_until_going_oncall} for schedule
{schedule.name}, {formatted_shift}"
  ```
- `time_until_going_oncall` is a "human-readable" format of the time
until the start)
  - `schedule.name` is self-explanatory
- `formatted_shift` this depends on the shift. If the shift starts and
ends on the same day, the format will be "HH:mm - HH:mm". Otherwise, if
the shift starts and ends on different days, the format will be
"YYYY-MM-DD HH:mm - YYYY-MM-DD HH:mm". **Note** that all datetime
related formatting will use the new `locale` field that we are now
storing in the mobile app user settings table. If no locale is yet
present we will fallback to "en"

## Which issue(s) this PR fixes

closes https://github.com/grafana/oncall/issues/2024
https://github.com/grafana/oncall-mobile-app/issues/187

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-06-14 12:19:58 -04:00
Yulya Artyukhina
62412076a2
Disable "You're going OnCall soon" push notification (#1927)
Disable "You're going OnCall soon" push notification for current user
settings
2023-05-12 11:56:12 +00:00
Salvatore Giordano
c2ac74faa3
add user settings for info notifications (#1926)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-05-12 10:23:42 +00:00
Joey Orlando
49d2f477c7
add important_notification_volume_override to mobile app user settings model (#1893)
# What this PR does

add `important_notification_volume_override` to mobile app user settings
model

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [ ] 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)
2023-05-09 14:28:47 +00:00
Joey Orlando
620f69e409
"You're Going OnCall" mobile app push notification (#1814)
# What this PR does

https://www.loom.com/share/c5deb35309604cfdab6176c44de7b15e

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-05-04 16:59:57 +00:00
Vadim Stepanov
ed5b5e153d
Mobile app settings backend (#1571)
# What this PR does
Adds mobile app settings support to OnCall backend.

- Adds a new Django model `MobileAppUserSettings` to store push
notification settings
- Adds a new endpoint `/mobile_app/v1/user_settings` to fetch/update
settings from the mobile app

Some additional info on implementation: at first I wanted to extend the
messaging backend system to allow storing / retrieving per-user data and
implement mobile app settings based on those changes. After some thought
I decided not to extend the messaging backend system and have this as
functionality specific to the `mobile_app` Django app. Currently the
messaging backend system is used by the backend and plugin UI, but
mobile app settings are specific only to the mobile app and not
configurable in the plugin UI.

**tldr: wanted to extend messaging backend system, but decided not to do
that**

# Usage

## Get settings via API

`GET /mobile_app/v1/user_settings`
Example response:

```json
{
  "default_notification_sound_name": "default_sound",  # sound name without file extension
  "default_notification_volume_type": "constant",
  "default_notification_volume": 0.8,
  "default_notification_volume_override": false,
  "important_notification_sound_name": "default_sound_important",  # sound name without file extension
  "important_notification_volume_type": "constant",
  "important_notification_volume": 0.8,
  "important_notification_override_dnd": true
}
```

## Update settings via API
`PUT /mobile_app/v1/user_settings` - see example response above for
payload shape.

Note that sound names must be passed without file extension. When
sending push notifications, the backend will add `.mp3` to sound names
and pass it to push notification data for Android. For iOS, sound names
will be suffixed with `.aiff` to be used by APNS.


## Get settings from notification data for Android
All the settings from example response will be available in push
notification data (along with `orgId`, `alertGroupId`, `title`, etc.).
Fields `default_notification_volume`,
`default_notification_volume_override` and
`important_notification_volume` , `important_notification_override_dnd`
will be converted to strings due to FCM limitations.
Fields `default_notification_sound_name` and
`important_notification_sound_name` will be suffixed with `.mp3` in push
notification data.

## iOS limitations
While Android push notifications are handled purely on the mobile app
side, iOS notifications are sent via APNS which imposes some
limitations.
- Notification volume cannot be overridden for non-critical
notifications (so fields `default_notification_volume_override` and
`default_notification_volume` will be disregarded for iOS notifications)
- It's not possible to control volume type (i.e. "constant" vs
"intensifying") via APNS. A possible workaround is to have different
sound files for "constant" and "intensifying" and pass that as
`default_notification_sound_name` / `important_notification_sound_name`.

# Which issue(s) this PR fixes
Related to https://github.com/grafana/oncall-private/issues/1602

# Checklist

- [x] Tests updated
- [x] No changelog updates since the changes are not user-facing
2023-03-22 14:47:18 +00:00
Joey Orlando
0f23a449c7
add unique idx on user column in mobileapp authtoken table (#1482)
# Which issue(s) this PR fixes
Solves the (rare) issue where a user could potentially have > 1
mobileapp auth token, leading to 500 errors when trying to interact w/
the authtoken (ex. disconnect a mobile app from a user's profile):
```shell
2023-03-07 10:12:13 source=engine:app google_trace_id=e14bf933d634068a48caf093ce43c7f5/5550677047491218352 logger=django.request Internal Server Error: /api/internal/v1/users/U6WJ3BRLM1TR7/unlink_backend
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/etc/app/apps/api/views/user.py", line 453, in unlink_backend
    backend.unlink_user(user)
  File "/etc/app/apps/mobile_app/backend.py", line 34, in unlink_user
    token = MobileAppAuthToken.objects.get(user=user)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 439, in get
    raise self.model.MultipleObjectsReturned(
apps.mobile_app.models.MobileAppAuthToken.MultipleObjectsReturned: get() returned more than one MobileAppAuthToken -- it returned 2!
```

## Checklist

- [x] Tests updated
- [ ] Documentation added (N/A)
- [x] `CHANGELOG.md` updated
2023-03-08 13:50:57 +01:00
Joey Orlando
7ebc9cbbf7
modify push notification settings + use fcm-django library (#998)
- swaps out `django-push-notifications` for
[`fcm-django`](https://github.com/grafana/fcm-django). Again.. this is a
fork of the parent repo for exactly the same reason.. the migrations
point to `auth_user` without letting us use our own user model, this has
been patched in the `grafana` fork. The reason why we are using
`fcm-django` vs `django-push-notifications` is that the latter does not
support the new FCM API, only the "legacy" API. The legacy FCM API does
not support certain push notification settings that we would like to
use.
- modifies the iOS/Android specific push notification settings
- adds a `flower` pod in the `docker-compose-developer.yml`, useful for
debugging tasks locally
- sets the mobile app verification token TTL to 5 minutes when
developing locally. The default of 1 minute makes working with device
emulators really tricky..

This PR also swaps out the base image in `engine/Dockerfile` from
`python:3.9-alpine3.16` to `python:3.9-slim-buster`.

As to why.. in short, with the introduction of the `fcm-django` library
there is now a peer-dependency on
[`grpcio`](https://github.com/grpc/grpc) (which is used by
`firebase_admin`.. which I am using in this PR to interact directly with
Firebase Cloud Messaging (FCM)). `grpcio` does not publish wheels (read:
compiled binaries) for the Alpine distro. It does publish wheels for
Debian and hence `pip install -r requirements.txt` does not need to
build this library from the source distribution.

This is a [known
"issue"](https://github.com/grpc/grpc/issues/22815#issuecomment-1107874367)
and the recommended solution in the community is to.. not use alpine.

These were the numbers, when building the image locally, in terms of
image size and build time:

| | Local image size (uncompressed | Build time (may differ based on
your network speed) |
| ------------------------- | -------------------------------------- |
---------- |
| `python:3.9-alpine3.16`   | 785MB  | 320s |
| `python:3.9-slim-buster` | 1.05GB  | 90s   |

Co-authored-by: Salvatore Giordano <salvatoregiordanoo@gmail.com>
2022-12-20 12:41:34 +01:00
Vadim Stepanov
255964ceaf
Mobile app messaging backend (#874)
* move mobile notifications to a separate backend, remove critical notification

* remove outdated mobile app code

* MOBILE_APP_PUSH_NOTIFICATIONS_ENABLED -> FEATURE_MOBILE_APP_INTEGRATION_ENABLED

* create error log if no devices are set up

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* move mobile auth related code to the mobile_app Django app

* fix typing

* add GCMDevice todos

* add user connection capabilities

* add user connect/disconnect to the messaging backend

* move APNS endpoint to mobile_app Django app

* restore critical notifications

* support hackathon app

* tweak migrations so mobile app auth tokens are preserved

* reuse notify_by IDs

* use mobile app template to render push notification

* add GCM/FCM (Android) support

* fix unlink user

* logger.error -> logger.info
2022-11-23 15:56:43 +00:00
Renamed from engine/apps/auth_token/models/mobile_app_verification_token.py (Browse further)