# 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>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
|
|
from apps.alerts.paging import direct_paging
|
|
from apps.api.permissions import RBACPermission
|
|
from apps.api.serializers.paging import DirectPagingSerializer
|
|
from apps.auth_token.auth import PluginAuthentication
|
|
|
|
|
|
class DirectPagingAPIView(APIView):
|
|
authentication_classes = (PluginAuthentication,)
|
|
permission_classes = (IsAuthenticated, RBACPermission)
|
|
|
|
rbac_permissions = {
|
|
"post": [RBACPermission.Permissions.ALERT_GROUPS_WRITE],
|
|
}
|
|
|
|
def post(self, request):
|
|
organization = request.auth.organization
|
|
from_user = request.user
|
|
|
|
serializer = DirectPagingSerializer(
|
|
data=request.data, context={"organization": organization, "request": request}
|
|
)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
users = [(user["instance"], user["important"]) for user in serializer.validated_data["users"]]
|
|
schedules = [
|
|
(schedule["instance"], schedule["important"]) for schedule in serializer.validated_data["schedules"]
|
|
]
|
|
|
|
alert_group = direct_paging(
|
|
organization=organization,
|
|
team=serializer.validated_data["team"],
|
|
from_user=from_user,
|
|
title=serializer.validated_data["title"],
|
|
message=serializer.validated_data["message"],
|
|
users=users,
|
|
schedules=schedules,
|
|
escalation_chain=serializer.validated_data["escalation_chain"],
|
|
alert_group=serializer.validated_data["alert_group"],
|
|
)
|
|
|
|
return Response(data={"alert_group_id": alert_group.public_primary_key}, status=status.HTTP_200_OK)
|