oncall-engine/engine/apps/api/tests
Vadim Stepanov eada4a4355
Fix duplicate orders for user notification policies (#2278)
# What this PR does

Fixes an issue when multiple user notification policies have duplicated
order values, leading to the following unexpected behaviours:
1. Not possible to rearrange notification policies that have duplicated
orders.
2. The notification system only executes the first policy from each
order group. For example, if there are policies with orders `[0, 0, 0,
0]`, only the first policy will be executed, and all others will be
skipped. So the user will see four policies in the UI, while only one of
them will be actually executed.

This PR fixes the issue by adding a unique index on `(user_id,
important, order)` for `UserNotificationPolicy` model. However, it's not
possible to add that unique index using the ordering library that we use
due to it's implementation details.
I added a new abstract Django model `OrderedModel` that's able to work
with such unique indices + under concurrent load.

Important info on this new `OrderedModel` abstract model:
- Orders are unique on the DB level
- Orders are allowed to be non-consecutive, for example order sequence
`[100, 150, 400]` is valid
- When deleting an instance, orders of other instances don't change.
This is a notable difference from the library we use. I think it's
better to only delete the instance without changing any other orders,
because it reduces the number of dependencies between instances (e.g.
Terraform drift will be much smaller this way if a policy is deleted via
the web UI).

## Which issue(s) this PR fixes

Related to https://github.com/grafana/oncall-private/issues/1680

## 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-06-21 11:13:56 +00:00
..
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
conftest.py Refactor maintenance (#1340) 2023-02-23 07:13:03 +00:00
test_alert_group.py Update alert group view receive channel filter (#2140) 2023-06-08 19:49:48 +00:00
test_alert_receive_channel.py add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
test_alert_receive_channel_template.py Fix 500 on templates when slack or tg integration is disabled (#2064) 2023-05-31 08:22:58 +00:00
test_channel_filter.py Make viewset actions more consistent (#2120) 2023-06-07 12:10:53 +00:00
test_custom_button.py use CustomURLValidator in custom_button (#1398) 2023-03-23 12:21:17 +00:00
test_escalation_chain.py Allow changing team for escalation chains (#1658) 2023-03-30 10:43:00 +01:00
test_escalation_policy.py Add escalation chain support for new webhooks (#1654) 2023-04-05 12:03:55 +00:00
test_features.py Fix warnings when running backend tests (#2079) 2023-06-06 18:38:00 +00:00
test_gitops.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_integration_heartbeat.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_live_settings.py Fix Telegram ratelimit on live setting change (#2100) 2023-06-06 15:18:12 +00:00
test_maintenance.py Fix teams filter related issue setting maintenance mode (#1885) 2023-05-05 18:09:25 +00:00
test_oncall_shift.py Changed web schedule updates to sync refresh ical (#2279) 2023-06-20 15:01:35 +00:00
test_organization.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_paging.py Return alert group ID in direct paging API (#1241) 2023-01-30 11:48:25 +00:00
test_permissions.py add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
test_postmortem_messages.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_preview_template_options.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
test_public_api_tokens.py only grant admins read/write access to public api keys (#952) 2022-12-06 13:02:53 +01:00
test_route_regex_debugger.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
test_schedule_export.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_schedules.py Fix preview cutting overlapping events (#2218) 2023-06-13 15:27:01 +00:00
test_set_general_log_channel.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_slack_channels.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_slack_team_settings.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_subscription.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_team.py Fix team update (#1794) 2023-04-19 15:22:14 +00:00
test_telegram_channel.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_terraform_renderer.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_user.py remove legacy permission strings (#2269) 2023-06-16 10:00:14 +00:00
test_user_groups.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_user_notification_policy.py Fix duplicate orders for user notification policies (#2278) 2023-06-21 11:13:56 +00:00
test_user_schedule_export.py Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
test_webhooks.py Webhooks 2 hide secrets (#2104) 2023-06-06 07:59:12 +00:00