c3lf-system-3/core/notifications/api_v2.py

49 lines
1.6 KiB
Python
Raw Normal View History

2024-06-26 16:42:56 +00:00
from django.contrib.auth.decorators import permission_required
from rest_framework import routers, viewsets
from django.urls import re_path
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
2024-06-27 22:49:09 +00:00
from notifications.models import MessageTemplate, UserNotificationChannel
2024-06-26 16:42:56 +00:00
from rest_framework import serializers
from notifications.templates import TEMPLATE_VARS
class MessageTemplateSerializer(serializers.ModelSerializer):
class Meta:
model = MessageTemplate
fields = '__all__'
2024-06-27 22:49:09 +00:00
class UserNotificationChannelSerializer(serializers.ModelSerializer):
class Meta:
model = UserNotificationChannel
fields = '__all__'
2024-06-26 16:42:56 +00:00
class MessageTemplateViewSet(viewsets.ModelViewSet):
serializer_class = MessageTemplateSerializer
queryset = MessageTemplate.objects.all()
2024-06-27 22:49:09 +00:00
class UserNotificationChannelViewSet(viewsets.ModelViewSet):
serializer_class = UserNotificationChannelSerializer
queryset = UserNotificationChannel.objects.all()
2024-06-26 16:42:56 +00:00
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@permission_required('tickets.add_issuethread_manual', raise_exception=True) # TDOO: change this permission
def get_template_vars(self):
return Response(TEMPLATE_VARS, status=200)
router = routers.SimpleRouter()
router.register(r'message_templates', MessageTemplateViewSet)
2024-06-27 22:49:09 +00:00
router.register(r'user_notification_channels', UserNotificationChannelViewSet)
2024-06-26 16:42:56 +00:00
urlpatterns = ([
re_path('message_template_variables', get_template_vars),
] + router.urls)