Skip to content

Commit

Permalink
Allow editing assigned team via public api (#1619)
Browse files Browse the repository at this point in the history
# 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)
  • Loading branch information
iskhakov authored Apr 5, 2023
1 parent 4229174 commit 498e7ed
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 0 additions & 1 deletion engine/apps/public_api/serializers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions engine/apps/public_api/serializers/escalation_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ class Meta:
"organization",
"team_id",
)


class EscalationChainUpdateSerializer(EscalationChainSerializer):
team_id = TeamPrimaryKeyRelatedField(source="team", read_only=True)
1 change: 0 additions & 1 deletion engine/apps/public_api/serializers/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion engine/apps/public_api/serializers/on_call_shifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions engine/apps/public_api/serializers/schedules_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/public_api/serializers/schedules_ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/public_api/serializers/schedules_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions engine/apps/public_api/views/escalation_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
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,)

throttle_classes = [UserThrottle]

model = EscalationChain
serializer_class = EscalationChainSerializer
update_serializer_class = EscalationChainUpdateSerializer

pagination_class = FiftyPageSizePaginator

Expand Down

0 comments on commit 498e7ed

Please sign in to comment.