Most of the PR is just renaming ChatOpsType to ChatOpsPlug, core changes are linked below: - Fix insight_logs error writing unlink_backend error https://github.com/grafana/oncall/pull/1757/files#diff-7ae187be84e55ebac962bad0984f7569186cdc83c896132b2ebcbcbb31bbf5dd - Fix insight_logs error writing updated schedule with installed slack integration (https://github.com/grafana/oncall/pull/1757/files#diff-4037b7bbef9fc16d9b541beb3ed46f760916d7cd720847c3123adf7afb5ab4b4L690)
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
from django.apps import apps
|
|
from rest_framework import mixins, status, viewsets
|
|
from rest_framework.decorators import action
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
|
|
from apps.api.permissions import RBACPermission
|
|
from apps.api.serializers.telegram import TelegramToOrganizationConnectorSerializer
|
|
from apps.auth_token.auth import PluginAuthentication
|
|
from common.api_helpers.mixins import PublicPrimaryKeyMixin
|
|
from common.insight_log.chatops_insight_logs import ChatOpsEvent, ChatOpsTypePlug, write_chatops_insight_log
|
|
|
|
|
|
class TelegramChannelViewSet(
|
|
PublicPrimaryKeyMixin,
|
|
mixins.RetrieveModelMixin,
|
|
mixins.DestroyModelMixin,
|
|
mixins.ListModelMixin,
|
|
viewsets.GenericViewSet,
|
|
):
|
|
authentication_classes = (PluginAuthentication,)
|
|
permission_classes = (IsAuthenticated, RBACPermission)
|
|
|
|
rbac_permissions = {
|
|
"metadata": [RBACPermission.Permissions.CHATOPS_READ],
|
|
"list": [RBACPermission.Permissions.CHATOPS_READ],
|
|
"retrieve": [RBACPermission.Permissions.CHATOPS_READ],
|
|
"destroy": [RBACPermission.Permissions.CHATOPS_UPDATE_SETTINGS],
|
|
"set_default": [RBACPermission.Permissions.CHATOPS_UPDATE_SETTINGS],
|
|
}
|
|
|
|
serializer_class = TelegramToOrganizationConnectorSerializer
|
|
|
|
def get_queryset(self):
|
|
TelegramToOrganizationConnector = apps.get_model("telegram", "TelegramToOrganizationConnector")
|
|
return TelegramToOrganizationConnector.objects.filter(organization=self.request.user.organization)
|
|
|
|
@action(detail=True, methods=["post"])
|
|
def set_default(self, request, pk):
|
|
telegram_channel = self.get_object()
|
|
telegram_channel.make_channel_default(request.user)
|
|
|
|
return Response(status=status.HTTP_200_OK)
|
|
|
|
def perform_destroy(self, instance):
|
|
user = self.request.user
|
|
write_chatops_insight_log(
|
|
author=user,
|
|
event_name=ChatOpsEvent.CHANNEL_DISCONNECTED,
|
|
chatops_type=ChatOpsTypePlug.TELEGRAM.value,
|
|
channel_name=instance.channel_name,
|
|
)
|
|
instance.delete()
|