stash
This commit is contained in:
parent
b7fb0c6fb3
commit
8c01e37224
5 changed files with 63 additions and 7 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: [],
|
||||
|
||||
lastEvent: '37C3',
|
||||
lastUsed: {},
|
||||
|
@ -201,6 +203,12 @@ const store = createStore({
|
|||
setThumbnail(state, {url, data}) {
|
||||
state.thumbnailCache[url] = data;
|
||||
},
|
||||
setMessageTemplates(state, templates) {
|
||||
state.messageTemplates = templates;
|
||||
},
|
||||
setMessageTemplateVariables(state, variables) {
|
||||
state.messageTemplatesVariables = variables;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async login({commit}, {username, password, remember}) {
|
||||
|
@ -415,7 +423,19 @@ const store = createStore({
|
|||
async updateTicketPartial({commit, state}, {id, ...ticket}) {
|
||||
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);
|
||||
}
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
||||
|
@ -443,6 +463,8 @@ const store = createStore({
|
|||
"groups",
|
||||
"loadedBoxes",
|
||||
"loadedItems",
|
||||
"messageTemplates",
|
||||
"messageTemplatesVariables",
|
||||
],
|
||||
watch: [
|
||||
"test",
|
||||
|
@ -453,6 +475,8 @@ const store = createStore({
|
|||
"groups",
|
||||
"loadedBoxes",
|
||||
"loadedItems",
|
||||
"messageTemplates",
|
||||
"messageTemplatesVariables",
|
||||
],
|
||||
mutations: [
|
||||
//"replaceTickets",
|
||||
|
|
|
@ -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