From 498e7ed5f3a27eca95f838b30ea318d355ef4944 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Wed, 5 Apr 2023 14:39:30 +0800 Subject: [PATCH] Allow editing assigned team via public api (#1619) # What this PR does For example, changing the integration's team ``` curl "localhost:8080/api/v1/integrations/CLYV3QBVHDV3T/" \ --request PUT \ --header "Authorization: meow" \ --header "Content-Type: application/json" --data '{"team_id": "TWP6JJJN6LYZX"}' ``` ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- CHANGELOG.md | 1 + engine/apps/public_api/serializers/action.py | 1 - engine/apps/public_api/serializers/escalation_chains.py | 4 ---- engine/apps/public_api/serializers/integrations.py | 1 - engine/apps/public_api/serializers/on_call_shifts.py | 1 - engine/apps/public_api/serializers/schedules_calendar.py | 3 +-- engine/apps/public_api/serializers/schedules_ical.py | 2 +- engine/apps/public_api/serializers/schedules_web.py | 2 +- engine/apps/public_api/views/escalation_chains.py | 6 ++---- 9 files changed, 6 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3da52a501..da1428d863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Allow editing assigned team via public api ([1619](https://github.com/grafana/oncall/pull/1619)) - Disable mentions when resolution note is created by @iskhakov ([1696](https://github.com/grafana/oncall/pull/1696)) - Display warnings on users page in a clean and consistent way by @iskhakov ([#1681](https://github.com/grafana/oncall/pull/1681)) diff --git a/engine/apps/public_api/serializers/action.py b/engine/apps/public_api/serializers/action.py index 5fb3f1ee98..2f33c0bdff 100644 --- a/engine/apps/public_api/serializers/action.py +++ b/engine/apps/public_api/serializers/action.py @@ -93,7 +93,6 @@ def validate_forward_whole_payload(self, data): class ActionUpdateSerializer(ActionCreateSerializer): - team_id = TeamPrimaryKeyRelatedField(source="team", read_only=True) url = serializers.CharField(required=False, allow_null=False, allow_blank=False, source="webhook") class Meta(ActionCreateSerializer.Meta): diff --git a/engine/apps/public_api/serializers/escalation_chains.py b/engine/apps/public_api/serializers/escalation_chains.py index 13b7fa75ac..6563036fc9 100644 --- a/engine/apps/public_api/serializers/escalation_chains.py +++ b/engine/apps/public_api/serializers/escalation_chains.py @@ -18,7 +18,3 @@ class Meta: "organization", "team_id", ) - - -class EscalationChainUpdateSerializer(EscalationChainSerializer): - team_id = TeamPrimaryKeyRelatedField(source="team", read_only=True) diff --git a/engine/apps/public_api/serializers/integrations.py b/engine/apps/public_api/serializers/integrations.py index fb55dcd5a1..2c42da5dd5 100644 --- a/engine/apps/public_api/serializers/integrations.py +++ b/engine/apps/public_api/serializers/integrations.py @@ -359,7 +359,6 @@ def _get_default_route_iterative(self, obj): class IntegrationUpdateSerializer(IntegrationSerializer): type = IntegrationTypeField(source="integration", read_only=True) - team_id = TeamPrimaryKeyRelatedField(source="team", read_only=True) def update(self, instance, validated_data): validated_data = self._correct_validated_data(validated_data) diff --git a/engine/apps/public_api/serializers/on_call_shifts.py b/engine/apps/public_api/serializers/on_call_shifts.py index 5568b23b3b..76d922e2cc 100644 --- a/engine/apps/public_api/serializers/on_call_shifts.py +++ b/engine/apps/public_api/serializers/on_call_shifts.py @@ -359,7 +359,6 @@ class CustomOnCallShiftUpdateSerializer(CustomOnCallShiftSerializer): name = serializers.CharField(required=False) start = serializers.DateTimeField(required=False) rotation_start = serializers.DateTimeField(required=False) - team_id = TeamPrimaryKeyRelatedField(read_only=True, source="team") def update(self, instance, validated_data): event_type = validated_data.get("type", instance.type) diff --git a/engine/apps/public_api/serializers/schedules_calendar.py b/engine/apps/public_api/serializers/schedules_calendar.py index dbbf221cc9..5cecce89b9 100644 --- a/engine/apps/public_api/serializers/schedules_calendar.py +++ b/engine/apps/public_api/serializers/schedules_calendar.py @@ -5,7 +5,7 @@ schedule_notify_about_empty_shifts_in_schedule, schedule_notify_about_gaps_in_schedule, ) -from common.api_helpers.custom_fields import TeamPrimaryKeyRelatedField, UsersFilteredByOrganizationField +from common.api_helpers.custom_fields import UsersFilteredByOrganizationField from common.api_helpers.exceptions import BadRequest from common.timezones import TimeZoneField @@ -60,7 +60,6 @@ def to_internal_value(self, data): class ScheduleCalendarUpdateSerializer(ScheduleCalendarSerializer): time_zone = TimeZoneField(required=False) - team_id = TeamPrimaryKeyRelatedField(read_only=True, source="team") class Meta: model = OnCallScheduleCalendar diff --git a/engine/apps/public_api/serializers/schedules_ical.py b/engine/apps/public_api/serializers/schedules_ical.py index 2f7b9b4ecd..458265c4a1 100644 --- a/engine/apps/public_api/serializers/schedules_ical.py +++ b/engine/apps/public_api/serializers/schedules_ical.py @@ -34,7 +34,7 @@ def validate_ical_url_overrides(self, url): class ScheduleICalUpdateSerializer(ScheduleICalSerializer): - team_id = TeamPrimaryKeyRelatedField(read_only=True, source="team") + team_id = TeamPrimaryKeyRelatedField(required=False, allow_null=True, source="team") class Meta: model = OnCallScheduleICal diff --git a/engine/apps/public_api/serializers/schedules_web.py b/engine/apps/public_api/serializers/schedules_web.py index a4a737c4f7..d1c892543f 100644 --- a/engine/apps/public_api/serializers/schedules_web.py +++ b/engine/apps/public_api/serializers/schedules_web.py @@ -11,6 +11,7 @@ class ScheduleWebSerializer(ScheduleBaseSerializer): + team_id = TeamPrimaryKeyRelatedField(required=False, allow_null=True, source="team") time_zone = TimeZoneField(required=True) shifts = UsersFilteredByOrganizationField( queryset=CustomOnCallShift.objects, @@ -49,7 +50,6 @@ def to_internal_value(self, data): class ScheduleWebUpdateSerializer(ScheduleWebSerializer): time_zone = TimeZoneField(required=False) - team_id = TeamPrimaryKeyRelatedField(read_only=True, source="team") class Meta: model = OnCallScheduleWeb diff --git a/engine/apps/public_api/views/escalation_chains.py b/engine/apps/public_api/views/escalation_chains.py index e24310cdca..017ca47099 100644 --- a/engine/apps/public_api/views/escalation_chains.py +++ b/engine/apps/public_api/views/escalation_chains.py @@ -6,15 +6,14 @@ from apps.alerts.models import EscalationChain from apps.auth_token.auth import ApiTokenAuthentication from apps.public_api.serializers import EscalationChainSerializer -from apps.public_api.serializers.escalation_chains import EscalationChainUpdateSerializer from apps.public_api.throttlers.user_throttle import UserThrottle from common.api_helpers.filters import ByTeamFilter -from common.api_helpers.mixins import RateLimitHeadersMixin, UpdateSerializerMixin +from common.api_helpers.mixins import RateLimitHeadersMixin from common.api_helpers.paginators import FiftyPageSizePaginator from common.insight_log import EntityEvent, write_resource_insight_log -class EscalationChainView(RateLimitHeadersMixin, UpdateSerializerMixin, ModelViewSet): +class EscalationChainView(RateLimitHeadersMixin, ModelViewSet): authentication_classes = (ApiTokenAuthentication,) permission_classes = (IsAuthenticated,) @@ -22,7 +21,6 @@ class EscalationChainView(RateLimitHeadersMixin, UpdateSerializerMixin, ModelVie model = EscalationChain serializer_class = EscalationChainSerializer - update_serializer_class = EscalationChainUpdateSerializer pagination_class = FiftyPageSizePaginator