This commit is contained in:
j3d1 2024-05-09 23:42:30 +02:00
parent b7fb0c6fb3
commit 8c01e37224
5 changed files with 63 additions and 7 deletions

View file

@ -1,7 +1,15 @@
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
from notifications.models import MessageTemplate
from rest_framework import serializers
from notifications.templates import TEMPLATE_VARS
class MessageTemplateSerializer(serializers.ModelSerializer):
class Meta:
@ -14,7 +22,16 @@ class MessageTemplateViewSet(viewsets.ModelViewSet):
queryset = MessageTemplate.objects.all()
@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)
urlpatterns = ([] + router.urls)
urlpatterns = ([
re_path('message_template_variables', get_template_vars),
] + router.urls)

View file

@ -25,4 +25,4 @@ class UserNotificationChannel(models.Model):
return True
def __str__(self):
return self.user.username + ' - ' + self.channel_type + ' -> ' + self.channel_target
return self.user.username + '(' + self.channel_type + ')'

View file

@ -4,7 +4,7 @@ from core.settings import PRIMARY_HOST
from notifications.models import MessageTemplate
TEMLATE_VARS = ['ticket_name', 'ticket_uuid', 'ticket_id', 'ticket_url',
TEMPLATE_VARS = ['ticket_name', 'ticket_uuid', 'ticket_id', 'ticket_url',
'current_state', 'previous_state', 'current_state_pretty', 'previous_state_pretty',
'event_slug', 'event_name',
'username', 'user_nick',