From 33d368b5f4ebb5f1444e6b69f820536482ad4e38 Mon Sep 17 00:00:00 2001 From: jedi Date: Fri, 28 Jun 2024 00:49:09 +0200 Subject: [PATCH] stash --- core/notifications/api_v2.py | 15 ++++++++++++-- web/src/store.js | 10 ++++++++- web/src/views/admin/Notifications.vue | 30 +++++++++------------------ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/core/notifications/api_v2.py b/core/notifications/api_v2.py index f50a453..e459d01 100644 --- a/core/notifications/api_v2.py +++ b/core/notifications/api_v2.py @@ -5,7 +5,7 @@ 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 notifications.models import MessageTemplate, UserNotificationChannel from rest_framework import serializers from notifications.templates import TEMPLATE_VARS @@ -17,11 +17,22 @@ class MessageTemplateSerializer(serializers.ModelSerializer): fields = '__all__' +class UserNotificationChannelSerializer(serializers.ModelSerializer): + class Meta: + model = UserNotificationChannel + fields = '__all__' + + class MessageTemplateViewSet(viewsets.ModelViewSet): serializer_class = MessageTemplateSerializer queryset = MessageTemplate.objects.all() +class UserNotificationChannelViewSet(viewsets.ModelViewSet): + serializer_class = UserNotificationChannelSerializer + queryset = UserNotificationChannel.objects.all() + + @api_view(['GET']) @permission_classes([IsAuthenticated]) @permission_required('tickets.add_issuethread_manual', raise_exception=True) # TDOO: change this permission @@ -31,7 +42,7 @@ def get_template_vars(self): router = routers.SimpleRouter() router.register(r'message_templates', MessageTemplateViewSet) - +router.register(r'user_notification_channels', UserNotificationChannelViewSet) urlpatterns = ([ re_path('message_template_variables', get_template_vars), ] + router.urls) diff --git a/web/src/store.js b/web/src/store.js index 3e96d65..c7c37a5 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -20,6 +20,7 @@ const store = createStore({ messageTemplates: [], messageTemplateVariables: [], shippingVouchers: [], + userNotificationChannels: [], loadedItems: {}, loadedTickets: {}, @@ -540,7 +541,14 @@ const store = createStore({ state.fetchedData.tickets = 0; await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]); } - } + }, + async fetchUserNotificationChannels({commit, state}) { + if (!state.user.token) return; + const {data, success} = await http.get('/2/user_notification_channels/', state.user.token); + if (data && success) { + state.userNotificationChannels = data; + } + }, }, plugins: [ persistentStatePlugin({ // TODO change remember to some kind of enable field diff --git a/web/src/views/admin/Notifications.vue b/web/src/views/admin/Notifications.vue index cc2b615..5a451fc 100644 --- a/web/src/views/admin/Notifications.vue +++ b/web/src/views/admin/Notifications.vue @@ -1,22 +1,9 @@