oncall-engine/engine/apps
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
..
alerts Teams redesign (#1528) 2023-03-22 00:57:20 +08:00
api Fix resource duplication caused by available_teams_lookup_args (#1593) 2023-03-22 15:43:32 +08:00
api_for_grafana_incident Include alert details in Grafana Incident alert-group endpoint (#1280) 2023-02-03 13:43:21 +00:00
auth_token Change Organization Deleted/Moved Precedence (#1402) 2023-02-24 11:45:21 +00:00
base Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
email Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
grafana_plugin Check stack cluster for insight_logs (#1469) 2023-03-09 06:30:54 +00:00
heartbeat Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
integrations Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
mobile_app Mobile app settings backend (#1571) 2023-03-22 14:47:18 +00:00
oss_installation Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
public_api Teams redesign (#1528) 2023-03-22 00:57:20 +08:00
schedules Add support for web overrides to Terraform schedules (#1222) 2023-03-10 16:21:50 +00:00
slack Add SLACK_INTEGRATION_MAINTENANCE env var (#1582) 2023-03-21 08:15:35 +00:00
social_auth Rework slack login to check backend before redirecting (#1306) 2023-02-08 09:08:18 -03:00
telegram Refactor get_user_verbal_for_team_for_slack. (#809) 2023-03-07 10:09:37 +00:00
twilioapp Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
user_management Fix teams duplication and user list permission control (#1591) 2023-03-22 14:38:31 +08:00
webhooks Keep webhook responses data (#1580) 2023-03-21 13:43:37 +00:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00