stash
This commit is contained in:
parent
04e60f6610
commit
69f036481f
5 changed files with 62 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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 + ')'
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -19,6 +19,8 @@ const store = createStore({
|
|||
users: [],
|
||||
groups: [],
|
||||
state_options: [],
|
||||
messageTemplates: [],
|
||||
messageTemplatesVariables: [],
|
||||
shippingVouchers: [],
|
||||
|
||||
lastEvent: '37C3',
|
||||
|
@ -56,7 +58,7 @@ const store = createStore({
|
|||
'2kg-eu': '2kg Paket (EU)',
|
||||
'5kg-eu': '5kg Paket (EU)',
|
||||
'10kg-eu': '10kg Paket (EU)',
|
||||
}
|
||||
},
|
||||
test: ['foo', 'bar', 'baz'],
|
||||
},
|
||||
getters: {
|
||||
|
@ -215,8 +217,11 @@ const store = createStore({
|
|||
setThumbnail(state, {url, data}) {
|
||||
state.thumbnailCache[url] = data;
|
||||
},
|
||||
setThumbnail(state, {url, data}) {
|
||||
state.thumbnailCache[url] = data;
|
||||
setMessageTemplates(state, templates) {
|
||||
state.messageTemplates = templates;
|
||||
},
|
||||
setMessageTemplateVariables(state, variables) {
|
||||
state.messageTemplatesVariables = variables;
|
||||
},
|
||||
setShippingVouchers(state, codes) {
|
||||
state.shippingVouchers = codes;
|
||||
|
@ -437,6 +442,18 @@ const store = createStore({
|
|||
const {data, success} = await http.patch(`/2/tickets/${id}/`, ticket, state.user.token);
|
||||
commit('updateTicket', data);
|
||||
},
|
||||
async fetchMessageTemplates({commit, state}) {
|
||||
const {data, success} = await http.get('/2/message_templates/', state.user.token);
|
||||
if (data && success) {
|
||||
commit('setMessageTemplates', data);
|
||||
}
|
||||
},
|
||||
async fetchMessageTemplateVariables({commit, state}) {
|
||||
const {data, success} = await http.get('/2/message_template_variables/', state.user.token);
|
||||
if (data && success) {
|
||||
commit('setMessageTemplateVariables', data);
|
||||
}
|
||||
},
|
||||
async fetchShippingVouchers({commit, state}) {
|
||||
if (!state.user.token) return;
|
||||
if (state.fetchedData.shippingVouchers > Date.now() - 1000 * 60 * 60 * 24) return;
|
||||
|
@ -491,6 +508,8 @@ const store = createStore({
|
|||
"groups",
|
||||
"loadedBoxes",
|
||||
"loadedItems",
|
||||
"messageTemplates",
|
||||
"messageTemplatesVariables",
|
||||
"shippingVouchers",
|
||||
],
|
||||
watch: [
|
||||
|
@ -502,6 +521,8 @@ const store = createStore({
|
|||
"groups",
|
||||
"loadedBoxes",
|
||||
"loadedItems",
|
||||
"messageTemplates",
|
||||
"messageTemplatesVariables",
|
||||
"shippingVouchers",
|
||||
],
|
||||
mutations: [
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
<template>
|
||||
Settings
|
||||
<h3 class="text-center">Message Templates</h3>
|
||||
<ul>
|
||||
<li v-for="template in messageTemplates" :key="template.id">
|
||||
{{ template.name }}
|
||||
</li>
|
||||
</ul>
|
||||
<h3 class="text-center">Message Template Variables</h3>
|
||||
<ul>
|
||||
<li v-for="variable in messageTemplateVariables" :key="variable.id">
|
||||
{{ variable.name }}
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -9,8 +20,12 @@ import Table from '@/components/Table';
|
|||
export default {
|
||||
name: 'Settings',
|
||||
components: {Table},
|
||||
computed: mapState(['events']),
|
||||
methods: mapActions(['changeEvent']),
|
||||
computed: mapState(['messageTemplates', 'messageTemplateVariables']),
|
||||
methods: mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables']),
|
||||
mounted() {
|
||||
this.fetchMessageTemplates();
|
||||
this.fetchMessageTemplateVariables();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue