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 d1d10c5..2dc56fe 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -22,6 +22,7 @@ const store = createStore({ messageTemplates: [], messageTemplateVariables: [], shippingVouchers: [], + userNotificationChannels: [], lastEvent: '37C3', lastUsed: {}, @@ -506,7 +507,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 @@