oncall-engine/engine/apps/api/views/team.py
Ildar Iskhakov d3c6621dae
Teams redesign (#1528)
# What this PR does

* api returns all the resources available to the user by default 
* substitutes `team switcher` with `multi-select team filter`
* allow referencing between integrations - escalations chains -
[schedules, outgoing webhooks] across teams



https://user-images.githubusercontent.com/2262529/225634581-2d2e8af2-15ce-4c01-a90e-8267d98f5a23.mov



## Which issue(s) this PR fixes

## Checklist

- [ ] Tests updated
- [ ] Documentation added
- [ ] `CHANGELOG.md` updated

---------

Co-authored-by: Maxim <maxim.mordasov@grafana.com>
Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
2023-03-22 00:57:20 +08:00

33 lines
1.3 KiB
Python

from rest_framework import mixins, viewsets
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from apps.api.serializers.team import TeamSerializer
from apps.auth_token.auth import PluginAuthentication
from apps.mobile_app.auth import MobileAppAuthTokenAuthentication
from apps.user_management.models import Team
from common.api_helpers.mixins import PublicPrimaryKeyMixin
class TeamViewSet(PublicPrimaryKeyMixin, mixins.ListModelMixin, mixins.UpdateModelMixin, viewsets.GenericViewSet):
authentication_classes = (
MobileAppAuthTokenAuthentication,
PluginAuthentication,
)
permission_classes = (IsAuthenticated,)
serializer_class = TeamSerializer
def get_queryset(self):
return self.request.user.available_teams
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
general_team = Team(public_primary_key="null", name="No team", email=None, avatar_url=None)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer([general_team] + list(page), many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer([general_team] + list(queryset), many=True)
return Response(serializer.data)