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 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 notifications.models import MessageTemplate
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from notifications.templates import TEMPLATE_VARS
|
||||||
|
|
||||||
|
|
||||||
class MessageTemplateSerializer(serializers.ModelSerializer):
|
class MessageTemplateSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -14,7 +22,16 @@ class MessageTemplateViewSet(viewsets.ModelViewSet):
|
||||||
queryset = MessageTemplate.objects.all()
|
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 = routers.SimpleRouter()
|
||||||
router.register(r'message_templates', MessageTemplateViewSet)
|
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
|
return True
|
||||||
|
|
||||||
def __str__(self):
|
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
|
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',
|
'current_state', 'previous_state', 'current_state_pretty', 'previous_state_pretty',
|
||||||
'event_slug', 'event_name',
|
'event_slug', 'event_name',
|
||||||
'username', 'user_nick',
|
'username', 'user_nick',
|
||||||
|
|
|
@ -19,6 +19,8 @@ const store = createStore({
|
||||||
users: [],
|
users: [],
|
||||||
groups: [],
|
groups: [],
|
||||||
state_options: [],
|
state_options: [],
|
||||||
|
messageTemplates: [],
|
||||||
|
messageTemplatesVariables: [],
|
||||||
|
|
||||||
lastEvent: '37C3',
|
lastEvent: '37C3',
|
||||||
lastUsed: {},
|
lastUsed: {},
|
||||||
|
@ -201,6 +203,12 @@ const store = createStore({
|
||||||
setThumbnail(state, {url, data}) {
|
setThumbnail(state, {url, data}) {
|
||||||
state.thumbnailCache[url] = data;
|
state.thumbnailCache[url] = data;
|
||||||
},
|
},
|
||||||
|
setMessageTemplates(state, templates) {
|
||||||
|
state.messageTemplates = templates;
|
||||||
|
},
|
||||||
|
setMessageTemplateVariables(state, variables) {
|
||||||
|
state.messageTemplatesVariables = variables;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async login({commit}, {username, password, remember}) {
|
async login({commit}, {username, password, remember}) {
|
||||||
|
@ -415,8 +423,20 @@ const store = createStore({
|
||||||
async updateTicketPartial({commit, state}, {id, ...ticket}) {
|
async updateTicketPartial({commit, state}, {id, ...ticket}) {
|
||||||
const {data, success} = await http.patch(`/2/tickets/${id}/`, ticket, state.user.token);
|
const {data, success} = await http.patch(`/2/tickets/${id}/`, ticket, state.user.token);
|
||||||
commit('updateTicket', data);
|
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: [
|
plugins: [
|
||||||
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
||||||
prefix: "lf_",
|
prefix: "lf_",
|
||||||
|
@ -443,6 +463,8 @@ const store = createStore({
|
||||||
"groups",
|
"groups",
|
||||||
"loadedBoxes",
|
"loadedBoxes",
|
||||||
"loadedItems",
|
"loadedItems",
|
||||||
|
"messageTemplates",
|
||||||
|
"messageTemplatesVariables",
|
||||||
],
|
],
|
||||||
watch: [
|
watch: [
|
||||||
"test",
|
"test",
|
||||||
|
@ -453,6 +475,8 @@ const store = createStore({
|
||||||
"groups",
|
"groups",
|
||||||
"loadedBoxes",
|
"loadedBoxes",
|
||||||
"loadedItems",
|
"loadedItems",
|
||||||
|
"messageTemplates",
|
||||||
|
"messageTemplatesVariables",
|
||||||
],
|
],
|
||||||
mutations: [
|
mutations: [
|
||||||
//"replaceTickets",
|
//"replaceTickets",
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
<template>
|
<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>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -9,8 +20,12 @@ import Table from '@/components/Table';
|
||||||
export default {
|
export default {
|
||||||
name: 'Settings',
|
name: 'Settings',
|
||||||
components: {Table},
|
components: {Table},
|
||||||
computed: mapState(['events']),
|
computed: mapState(['messageTemplates', 'messageTemplateVariables']),
|
||||||
methods: mapActions(['changeEvent']),
|
methods: mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables']),
|
||||||
|
mounted() {
|
||||||
|
this.fetchMessageTemplates();
|
||||||
|
this.fetchMessageTemplateVariables();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue