oncall-engine/engine/apps/api/views/slack_team_settings.py
Innokentii Konstantinov 4765c9b07c
Insight logs (#348)
* Entity events insight logs

* Insight logging

* Fix event for updating templates

* Format fixes

* Remove organization_log_type.py

* Simplify signature of chatops_insight_log

* insight logs formatting

* Add possibility to enable all insight logging via DynamicSetting

* Fixes

* Style fixes

* Add migration

* Fix migration
2022-08-24 12:04:44 +05:00

72 lines
2.5 KiB
Python

from rest_framework import views
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from apps.api.permissions import AnyRole, IsAdmin, MethodPermission
from apps.api.serializers.organization_slack_settings import OrganizationSlackSettingsSerializer
from apps.auth_token.auth import PluginAuthentication
from apps.user_management.models import Organization
from common.insight_log import EntityEvent, write_resource_insight_log
class SlackTeamSettingsAPIView(views.APIView):
authentication_classes = (PluginAuthentication,)
permission_classes = (IsAuthenticated, MethodPermission)
method_permissions = {
IsAdmin: ("PUT",),
AnyRole: ("GET",),
}
serializer_class = OrganizationSlackSettingsSerializer
def get(self, request):
organization = self.request.auth.organization
serializer = self.serializer_class(organization)
return Response(serializer.data)
def put(self, request):
organization = self.request.auth.organization
prev_state = organization.insight_logs_serialized
serializer = self.serializer_class(organization, data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
new_state = serializer.instance.insight_logs_serialized
write_resource_insight_log(
instance=serializer.instance,
author=self.request.user,
event=EntityEvent.UPDATED,
prev_state=prev_state,
new_state=new_state,
)
return Response(serializer.data)
class AcknowledgeReminderOptionsAPIView(views.APIView):
authentication_classes = (PluginAuthentication,)
permission_classes = (IsAuthenticated,)
def get(self, request):
choices = []
for item in Organization.ACKNOWLEDGE_REMIND_CHOICES:
choices.append(
{"value": item[0], "sec_value": Organization.ACKNOWLEDGE_REMIND_DELAY[item[0]], "display_name": item[1]}
)
return Response(choices)
class UnAcknowledgeTimeoutOptionsAPIView(views.APIView):
authentication_classes = (PluginAuthentication,)
permission_classes = (IsAuthenticated,)
def get(self, request):
choices = []
for item in Organization.UNACKNOWLEDGE_TIMEOUT_CHOICES:
choices.append(
{
"value": item[0],
"sec_value": Organization.UNACKNOWLEDGE_TIMEOUT_DELAY[item[0]],
"display_name": item[1],
}
)
return Response(choices)