When team is removed do not delete webhooks belonging to it (#3873)
# What this PR does When a team is deleted webhooks belonging to that team will be marked as having no team instead of the webhook being deleted. ## 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)
This commit is contained in:
parent
caef9e2eb0
commit
617146f5ea
4 changed files with 38 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Check for permissions on Slack escalate command ([#3891](https://github.com/grafana/oncall/pull/3891))
|
||||
- Do not delete webhook if its team is deleted @mderynck ([#3873](https://github.com/grafana/oncall/pull/3873))
|
||||
|
||||
## v1.3.105 (2024-02-13)
|
||||
|
||||
|
|
|
|||
20
engine/apps/webhooks/migrations/0012_alter_webhook_team.py
Normal file
20
engine/apps/webhooks/migrations/0012_alter_webhook_team.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2.10 on 2024-02-14 17:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user_management', '0020_organization_is_grafana_labels_enabled'),
|
||||
('webhooks', '0011_auto_20230920_1813'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='webhook',
|
||||
name='team',
|
||||
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='webhooks', to='user_management.team'),
|
||||
),
|
||||
]
|
||||
|
|
@ -120,7 +120,7 @@ class Webhook(models.Model):
|
|||
)
|
||||
|
||||
team = models.ForeignKey(
|
||||
"user_management.Team", null=True, on_delete=models.CASCADE, related_name="webhooks", default=None
|
||||
"user_management.Team", null=True, on_delete=models.SET_NULL, related_name="webhooks", default=None
|
||||
)
|
||||
|
||||
user = models.ForeignKey(
|
||||
|
|
|
|||
|
|
@ -304,3 +304,19 @@ def test_escaping_unicode_in_string(make_organization, make_custom_webhook, data
|
|||
}
|
||||
request_kwargs = webhook.build_request_kwargs(payload)
|
||||
assert request_kwargs == {"headers": {}, **expected_kwargs}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_webhook_not_deleted_with_team(make_organization, make_team, make_custom_webhook):
|
||||
organization = make_organization()
|
||||
team = make_team(organization=organization)
|
||||
webhook = make_custom_webhook(
|
||||
organization=organization,
|
||||
team=team,
|
||||
)
|
||||
assert webhook.team == team
|
||||
webhook_pk = webhook.pk
|
||||
team.delete()
|
||||
|
||||
webhook = Webhook.objects.get(pk=webhook_pk)
|
||||
assert webhook.team is None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue