Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
b6b29d9fed | |||
61c4beda47 |
49 changed files with 237 additions and 1621 deletions
|
@ -20,12 +20,9 @@ jobs:
|
||||||
- name: Run django tests
|
- name: Run django tests
|
||||||
working-directory: core
|
working-directory: core
|
||||||
run: python3 manage.py test
|
run: python3 manage.py test
|
||||||
- name: Run django coverage
|
|
||||||
working-directory: core
|
|
||||||
run: coverage manage.py test
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: [ test ]
|
needs: [test]
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
||||||
[submodule "web/extras"]
|
|
||||||
path = web/extras
|
|
||||||
url = https://git.neulandlabor.de/j3d1/vue-extras.git
|
|
|
@ -10,8 +10,5 @@ class ExtendedUserAdmin(UserAdmin):
|
||||||
ordering = ('username',)
|
ordering = ('username',)
|
||||||
filter_horizontal = ('groups', 'user_permissions', 'permissions')
|
filter_horizontal = ('groups', 'user_permissions', 'permissions')
|
||||||
|
|
||||||
# def permissions(self, obj):
|
|
||||||
# return ', '.join(obj.get_all_permissions())
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(ExtendedUser, ExtendedUserAdmin)
|
admin.site.register(ExtendedUser, ExtendedUserAdmin)
|
||||||
|
|
|
@ -49,14 +49,9 @@ SYSTEM3_VERSION = "0.0.0-dev.0"
|
||||||
|
|
||||||
ACTIVE_SPAM_TRAINING = truthy_str(os.getenv('ACTIVE_SPAM_TRAINING', 'False'))
|
ACTIVE_SPAM_TRAINING = truthy_str(os.getenv('ACTIVE_SPAM_TRAINING', 'False'))
|
||||||
|
|
||||||
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN', '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi')
|
|
||||||
|
|
||||||
TELEGRAM_GROUP_CHAT_ID = os.getenv('TELEGRAM_GROUP_CHAT_ID', '-1234567890')
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
*(['daphne'] if 'runserver' in sys.argv else []),
|
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
@ -70,7 +65,6 @@ INSTALLED_APPS = [
|
||||||
'drf_yasg',
|
'drf_yasg',
|
||||||
'channels',
|
'channels',
|
||||||
'authentication',
|
'authentication',
|
||||||
'notifications',
|
|
||||||
'files',
|
'files',
|
||||||
'tickets',
|
'tickets',
|
||||||
'inventory',
|
'inventory',
|
||||||
|
@ -130,7 +124,7 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
ASGI_APPLICATION = 'core.asgi.application'
|
WSGI_APPLICATION = 'core.wsgi.application'
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||||
|
|
|
@ -28,7 +28,6 @@ urlpatterns = [
|
||||||
path('api/2/', include('mail.api_v2')),
|
path('api/2/', include('mail.api_v2')),
|
||||||
path('api/2/', include('notify_sessions.api_v2')),
|
path('api/2/', include('notify_sessions.api_v2')),
|
||||||
path('api/2/', include('authentication.api_v2')),
|
path('api/2/', include('authentication.api_v2')),
|
||||||
path('api/2/', include('notifications.api_v2')),
|
|
||||||
path('api/', get_info),
|
path('api/', get_info),
|
||||||
path('', include('django_prometheus.urls')),
|
path('', include('django_prometheus.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from inventory.models import Item, Container, Event
|
from inventory.models import Item, Container, ItemPlacement, Comment, Event
|
||||||
|
|
||||||
|
|
||||||
class ItemAdmin(admin.ModelAdmin):
|
class ItemAdmin(admin.ModelAdmin):
|
||||||
|
@ -22,3 +22,17 @@ class EventAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Event, EventAdmin)
|
admin.site.register(Event, EventAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
class ItemPlacementAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(ItemPlacement, ItemPlacementAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
class CommentAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Comment, CommentAdmin)
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
# Generated by Django 4.2.7 on 2024-11-23 00:19
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('inventory', '0006_alter_event_table'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='item',
|
|
||||||
name='container',
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='ItemPlacement',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
|
||||||
('timestamp', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('container', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_history', to='inventory.container')),
|
|
||||||
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='container_history', to='inventory.item')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Comment',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
|
||||||
('comment', models.TextField()),
|
|
||||||
('timestamp', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='inventory.item')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
# Generated by Django 4.2.7 on 2024-11-23 15:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('inventory', '0006_alter_event_table'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def set_initial_container(apps, schema_editor):
|
||||||
|
Item = apps.get_model('inventory', 'Item')
|
||||||
|
for item in Item.objects.all():
|
||||||
|
item.container_history.get_or_create(container=item.container_old)
|
||||||
|
item.save()
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='item',
|
||||||
|
old_name='container',
|
||||||
|
new_name='container_old',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ItemPlacement',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('timestamp', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('container',
|
||||||
|
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_history',
|
||||||
|
to='inventory.container')),
|
||||||
|
('item',
|
||||||
|
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='container_history',
|
||||||
|
to='inventory.item')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Comment',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('comment', models.TextField()),
|
||||||
|
('timestamp', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments',
|
||||||
|
to='inventory.item')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.RunPython(set_initial_container),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='item',
|
||||||
|
name='container_old',
|
||||||
|
),
|
||||||
|
]
|
|
@ -92,7 +92,7 @@ class Comment(models.Model):
|
||||||
timestamp = models.DateTimeField(auto_now_add=True)
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.issue_thread) + ' comment #' + str(self.id)
|
return str(self.item) + ' comment #' + str(self.id)
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
|
|
|
@ -25,6 +25,7 @@ class EventSerializer(serializers.ModelSerializer):
|
||||||
dict['addresses'] = [EventAddress.objects.get_or_create(address=x)[0] for x in addresses]
|
dict['addresses'] = [EventAddress.objects.get_or_create(address=x)[0] for x in addresses]
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
|
|
||||||
class ContainerSerializer(serializers.ModelSerializer):
|
class ContainerSerializer(serializers.ModelSerializer):
|
||||||
itemCount = serializers.SerializerMethodField()
|
itemCount = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
@ -105,6 +106,14 @@ class ItemSerializer(BasicItemSerializer):
|
||||||
'timestamp': relation.timestamp,
|
'timestamp': relation.timestamp,
|
||||||
'issue_thread': BasicIssueSerializer(relation.issue_thread).data,
|
'issue_thread': BasicIssueSerializer(relation.issue_thread).data,
|
||||||
})
|
})
|
||||||
|
for placement in (obj.container_history.all()):
|
||||||
|
timeline.append({
|
||||||
|
'type': 'placement',
|
||||||
|
'id': placement.id,
|
||||||
|
'timestamp': placement.timestamp,
|
||||||
|
'cid': placement.container.id,
|
||||||
|
'box': placement.container.name
|
||||||
|
})
|
||||||
return sorted(timeline, key=lambda x: x['timestamp'])
|
return sorted(timeline, key=lambda x: x['timestamp'])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from knox.models import AuthToken
|
||||||
|
|
||||||
from authentication.models import ExtendedUser
|
from authentication.models import ExtendedUser
|
||||||
from files.models import File
|
from files.models import File
|
||||||
from inventory.models import Event, Container, Item, Comment
|
from inventory.models import Event, Container, Item, Comment, ItemPlacement
|
||||||
|
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ class ItemTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.event = Event.objects.create(slug='EVENT', name='Event')
|
self.event = Event.objects.create(slug='EVENT', name='Event')
|
||||||
self.box = Container.objects.create(name='BOX')
|
self.box1 = Container.objects.create(name='BOX1')
|
||||||
|
self.box2 = Container.objects.create(name='BOX2')
|
||||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
||||||
self.user.user_permissions.add(*Permission.objects.all())
|
self.user.user_permissions.add(*Permission.objects.all())
|
||||||
self.token = AuthToken.objects.create(user=self.user)
|
self.token = AuthToken.objects.create(user=self.user)
|
||||||
|
@ -36,7 +37,7 @@ class ItemTestCase(TestCase):
|
||||||
|
|
||||||
def test_members_and_timeline(self):
|
def test_members_and_timeline(self):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
comment = Comment.objects.create(
|
comment = Comment.objects.create(
|
||||||
item=item,
|
item=item,
|
||||||
comment="test",
|
comment="test",
|
||||||
|
@ -44,7 +45,12 @@ class ItemTestCase(TestCase):
|
||||||
)
|
)
|
||||||
match = ItemRelation.objects.create(
|
match = ItemRelation.objects.create(
|
||||||
issue_thread=self.issue,
|
issue_thread=self.issue,
|
||||||
item = item,
|
item=item,
|
||||||
|
timestamp=now + timedelta(seconds=4),
|
||||||
|
)
|
||||||
|
placement = ItemPlacement.objects.create(
|
||||||
|
container=self.box2,
|
||||||
|
item=item,
|
||||||
timestamp=now + timedelta(seconds=5),
|
timestamp=now + timedelta(seconds=5),
|
||||||
)
|
)
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
|
@ -52,25 +58,34 @@ class ItemTestCase(TestCase):
|
||||||
self.assertEqual(len(response.json()), 1)
|
self.assertEqual(len(response.json()), 1)
|
||||||
self.assertEqual(response.json()[0]['id'], item.id)
|
self.assertEqual(response.json()[0]['id'], item.id)
|
||||||
self.assertEqual(response.json()[0]['description'], '1')
|
self.assertEqual(response.json()[0]['description'], '1')
|
||||||
self.assertEqual(response.json()[0]['box'], 'BOX')
|
self.assertEqual(response.json()[0]['box'], 'BOX2')
|
||||||
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
self.assertEqual(response.json()[0]['cid'], self.box2.id)
|
||||||
self.assertEqual(response.json()[0]['file'], None)
|
self.assertEqual(response.json()[0]['file'], None)
|
||||||
self.assertEqual(response.json()[0]['returned'], False)
|
self.assertEqual(response.json()[0]['returned'], False)
|
||||||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||||
self.assertEqual(len(response.json()[0]['timeline']), 2)
|
self.assertEqual(len(response.json()[0]['timeline']), 4)
|
||||||
self.assertEqual(response.json()[0]['timeline'][0]['type'], 'comment')
|
self.assertEqual(response.json()[0]['timeline'][0]['type'], 'placement')
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['type'], 'issue_relation')
|
self.assertEqual(response.json()[0]['timeline'][1]['type'], 'comment')
|
||||||
self.assertEqual(response.json()[0]['timeline'][0]['id'], comment.id)
|
self.assertEqual(response.json()[0]['timeline'][2]['type'], 'issue_relation')
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['id'], match.id)
|
self.assertEqual(response.json()[0]['timeline'][3]['type'], 'placement')
|
||||||
self.assertEqual(response.json()[0]['timeline'][0]['comment'], 'test')
|
self.assertEqual(response.json()[0]['timeline'][1]['id'], comment.id)
|
||||||
self.assertEqual(response.json()[0]['timeline'][0]['timestamp'],
|
self.assertEqual(response.json()[0]['timeline'][2]['id'], match.id)
|
||||||
comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
self.assertEqual(response.json()[0]['timeline'][3]['id'], placement.id)
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['status'], 'possible')
|
self.assertEqual(response.json()[0]['timeline'][0]['box'], 'BOX1')
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][0]['cid'], self.box1.id)
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][1]['comment'], 'test')
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['timestamp'],
|
self.assertEqual(response.json()[0]['timeline'][1]['timestamp'],
|
||||||
|
comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][2]['status'], 'possible')
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][2]['timestamp'],
|
||||||
match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['name'], "test issue")
|
self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['name'], "test issue")
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['event'], "EVENT")
|
self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['event'], "EVENT")
|
||||||
self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['state'], "pending_new")
|
self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['state'], "pending_new")
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][3]['box'], 'BOX2')
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][3]['cid'], self.box2.id)
|
||||||
|
self.assertEqual(response.json()[0]['timeline'][3]['timestamp'],
|
||||||
|
placement.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
||||||
self.assertEqual(len(response.json()[0]['related_issues']), 1)
|
self.assertEqual(len(response.json()[0]['related_issues']), 1)
|
||||||
self.assertEqual(response.json()[0]['related_issues'][0]['name'], "test issue")
|
self.assertEqual(response.json()[0]['related_issues'][0]['name'], "test issue")
|
||||||
self.assertEqual(response.json()[0]['related_issues'][0]['event'], "EVENT")
|
self.assertEqual(response.json()[0]['related_issues'][0]['event'], "EVENT")
|
||||||
|
@ -78,15 +93,15 @@ class ItemTestCase(TestCase):
|
||||||
|
|
||||||
def test_members_with_file(self):
|
def test_members_with_file(self):
|
||||||
import base64
|
import base64
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
file = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
file = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.json()), 1)
|
self.assertEqual(len(response.json()), 1)
|
||||||
self.assertEqual(response.json()[0]['id'], item.id)
|
self.assertEqual(response.json()[0]['id'], item.id)
|
||||||
self.assertEqual(response.json()[0]['description'], '1')
|
self.assertEqual(response.json()[0]['description'], '1')
|
||||||
self.assertEqual(response.json()[0]['box'], 'BOX')
|
self.assertEqual(response.json()[0]['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
self.assertEqual(response.json()[0]['cid'], self.box1.id)
|
||||||
self.assertEqual(response.json()[0]['file'], file.hash)
|
self.assertEqual(response.json()[0]['file'], file.hash)
|
||||||
self.assertEqual(response.json()[0]['returned'], False)
|
self.assertEqual(response.json()[0]['returned'], False)
|
||||||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||||
|
@ -94,36 +109,38 @@ class ItemTestCase(TestCase):
|
||||||
|
|
||||||
def test_members_with_two_file(self):
|
def test_members_with_two_file(self):
|
||||||
import base64
|
import base64
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
file1 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
file1 = File.objects.create(item=item,
|
||||||
file2 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"bar").decode('utf-8'))
|
data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
||||||
|
file2 = File.objects.create(item=item,
|
||||||
|
data="data:text/plain;base64," + base64.b64encode(b"bar").decode('utf-8'))
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.json()), 1)
|
self.assertEqual(len(response.json()), 1)
|
||||||
self.assertEqual(response.json()[0]['id'], item.id)
|
self.assertEqual(response.json()[0]['id'], item.id)
|
||||||
self.assertEqual(response.json()[0]['description'], '1')
|
self.assertEqual(response.json()[0]['description'], '1')
|
||||||
self.assertEqual(response.json()[0]['box'], 'BOX')
|
self.assertEqual(response.json()[0]['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
self.assertEqual(response.json()[0]['cid'], self.box1.id)
|
||||||
self.assertEqual(response.json()[0]['file'], file2.hash)
|
self.assertEqual(response.json()[0]['file'], file2.hash)
|
||||||
self.assertEqual(response.json()[0]['returned'], False)
|
self.assertEqual(response.json()[0]['returned'], False)
|
||||||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||||
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
||||||
|
|
||||||
def test_multi_members(self):
|
def test_multi_members(self):
|
||||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
||||||
Item.objects.create(container=self.box, event=self.event, description='3')
|
Item.objects.create(container=self.box1, event=self.event, description='3')
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.json()), 3)
|
self.assertEqual(len(response.json()), 3)
|
||||||
|
|
||||||
def test_create_item(self):
|
def test_create_item(self):
|
||||||
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box.id, 'description': '1'})
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box1.id, 'description': '1'})
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 201)
|
||||||
self.assertEqual(response.json()['id'], 1)
|
self.assertEqual(response.json()['id'], 1)
|
||||||
self.assertEqual(response.json()['description'], '1')
|
self.assertEqual(response.json()['description'], '1')
|
||||||
self.assertEqual(response.json()['box'], 'BOX')
|
self.assertEqual(response.json()['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()['cid'], self.box.id)
|
self.assertEqual(response.json()['cid'], self.box1.id)
|
||||||
self.assertEqual(response.json()['file'], None)
|
self.assertEqual(response.json()['file'], None)
|
||||||
self.assertEqual(response.json()['returned'], False)
|
self.assertEqual(response.json()['returned'], False)
|
||||||
self.assertEqual(response.json()['event'], self.event.slug)
|
self.assertEqual(response.json()['event'], self.event.slug)
|
||||||
|
@ -131,43 +148,43 @@ class ItemTestCase(TestCase):
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
self.assertEqual(Item.objects.all()[0].id, 1)
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
||||||
self.assertEqual(Item.objects.all()[0].description, '1')
|
self.assertEqual(Item.objects.all()[0].description, '1')
|
||||||
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
||||||
|
|
||||||
def test_create_item_without_container(self):
|
def test_create_item_without_container(self):
|
||||||
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'description': '1'})
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'description': '1'})
|
||||||
self.assertEqual(response.status_code, 400)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
def test_create_item_without_description(self):
|
def test_create_item_without_description(self):
|
||||||
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box.id})
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box1.id})
|
||||||
self.assertEqual(response.status_code, 400)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
def test_create_item_with_file(self):
|
def test_create_item_with_file(self):
|
||||||
import base64
|
import base64
|
||||||
response = self.client.post(f'/api/2/{self.event.slug}/item/',
|
response = self.client.post(f'/api/2/{self.event.slug}/item/',
|
||||||
{'cid': self.box.id, 'description': '1',
|
{'cid': self.box1.id, 'description': '1',
|
||||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
||||||
'utf-8')}, content_type='application/json')
|
'utf-8')}, content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 201)
|
||||||
self.assertEqual(response.json()['id'], 1)
|
self.assertEqual(response.json()['id'], 1)
|
||||||
self.assertEqual(response.json()['description'], '1')
|
self.assertEqual(response.json()['description'], '1')
|
||||||
self.assertEqual(response.json()['box'], 'BOX')
|
self.assertEqual(response.json()['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()['id'], self.box.id)
|
self.assertEqual(response.json()['id'], self.box1.id)
|
||||||
self.assertEqual(len(response.json()['file']), 64)
|
self.assertEqual(len(response.json()['file']), 64)
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
self.assertEqual(Item.objects.all()[0].id, 1)
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
||||||
self.assertEqual(Item.objects.all()[0].description, '1')
|
self.assertEqual(Item.objects.all()[0].description, '1')
|
||||||
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
||||||
self.assertEqual(len(File.objects.all()), 1)
|
self.assertEqual(len(File.objects.all()), 1)
|
||||||
|
|
||||||
def test_update_item(self):
|
def test_update_item(self):
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json()['id'], item.id)
|
self.assertEqual(response.json()['id'], item.id)
|
||||||
self.assertEqual(response.json()['description'], '2')
|
self.assertEqual(response.json()['description'], '2')
|
||||||
self.assertEqual(response.json()['box'], 'BOX')
|
self.assertEqual(response.json()['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()['cid'], self.box.id)
|
self.assertEqual(response.json()['cid'], self.box1.id)
|
||||||
self.assertEqual(response.json()['file'], None)
|
self.assertEqual(response.json()['file'], None)
|
||||||
self.assertEqual(response.json()['returned'], False)
|
self.assertEqual(response.json()['returned'], False)
|
||||||
self.assertEqual(response.json()['event'], self.event.slug)
|
self.assertEqual(response.json()['event'], self.event.slug)
|
||||||
|
@ -175,60 +192,62 @@ class ItemTestCase(TestCase):
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
self.assertEqual(Item.objects.all()[0].id, 1)
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
||||||
self.assertEqual(Item.objects.all()[0].description, '2')
|
self.assertEqual(Item.objects.all()[0].description, '2')
|
||||||
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
||||||
|
|
||||||
def test_update_item_with_file(self):
|
def test_update_item_with_file(self):
|
||||||
import base64
|
import base64
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/',
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/',
|
||||||
{'description': '2',
|
{'description': '2',
|
||||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
||||||
|
'utf-8')},
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json()['id'], 1)
|
self.assertEqual(response.json()['id'], 1)
|
||||||
self.assertEqual(response.json()['description'], '2')
|
self.assertEqual(response.json()['description'], '2')
|
||||||
self.assertEqual(response.json()['box'], 'BOX')
|
self.assertEqual(response.json()['box'], 'BOX1')
|
||||||
self.assertEqual(response.json()['id'], self.box.id)
|
self.assertEqual(response.json()['id'], self.box1.id)
|
||||||
self.assertEqual(len(response.json()['file']), 64)
|
self.assertEqual(len(response.json()['file']), 64)
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
self.assertEqual(Item.objects.all()[0].id, 1)
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
||||||
self.assertEqual(Item.objects.all()[0].description, '2')
|
self.assertEqual(Item.objects.all()[0].description, '2')
|
||||||
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
||||||
self.assertEqual(len(File.objects.all()), 1)
|
self.assertEqual(len(File.objects.all()), 1)
|
||||||
|
|
||||||
def test_delete_item(self):
|
def test_delete_item(self):
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
||||||
self.assertEqual(len(Item.objects.all()), 2)
|
self.assertEqual(len(Item.objects.all()), 2)
|
||||||
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item.id}/')
|
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item.id}/')
|
||||||
self.assertEqual(response.status_code, 204)
|
self.assertEqual(response.status_code, 204)
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
|
|
||||||
def test_delete_item2(self):
|
def test_delete_item2(self):
|
||||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
item2 = Item.objects.create(container=self.box, event=self.event, description='2')
|
item2 = Item.objects.create(container=self.box1, event=self.event, description='2')
|
||||||
self.assertEqual(len(Item.objects.all()), 2)
|
self.assertEqual(len(Item.objects.all()), 2)
|
||||||
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item2.id}/')
|
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item2.id}/')
|
||||||
self.assertEqual(response.status_code, 204)
|
self.assertEqual(response.status_code, 204)
|
||||||
self.assertEqual(len(Item.objects.all()), 1)
|
self.assertEqual(len(Item.objects.all()), 1)
|
||||||
item3 = Item.objects.create(container=self.box, event=self.event, description='3')
|
item3 = Item.objects.create(container=self.box1, event=self.event, description='3')
|
||||||
self.assertEqual(item3.id, 3)
|
self.assertEqual(item3.id, 3)
|
||||||
self.assertEqual(len(Item.objects.all()), 2)
|
self.assertEqual(len(Item.objects.all()), 2)
|
||||||
|
|
||||||
def test_item_count(self):
|
def test_item_count(self):
|
||||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
||||||
response = self.client.get('/api/2/boxes/')
|
response = self.client.get('/api/2/boxes/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.json()), 1)
|
self.assertEqual(len(response.json()), 2)
|
||||||
self.assertEqual(response.json()[0]['itemCount'], 2)
|
self.assertEqual(response.json()[0]['itemCount'], 2)
|
||||||
|
self.assertEqual(response.json()[1]['itemCount'], 0)
|
||||||
|
|
||||||
def test_item_nonexistent(self):
|
def test_item_nonexistent(self):
|
||||||
response = self.client.get(f'/api/2/NOEVENT/item/')
|
response = self.client.get(f'/api/2/NOEVENT/item/')
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
def test_item_return(self):
|
def test_item_return(self):
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
self.assertEqual(item.returned_at, None)
|
self.assertEqual(item.returned_at, None)
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -243,8 +262,8 @@ class ItemTestCase(TestCase):
|
||||||
self.assertEqual(len(response.json()), 0)
|
self.assertEqual(len(response.json()), 0)
|
||||||
|
|
||||||
def test_item_show_not_returned(self):
|
def test_item_show_not_returned(self):
|
||||||
item1 = Item.objects.create(container=self.box, event=self.event, description='1')
|
item1 = Item.objects.create(container=self.box1, event=self.event, description='1')
|
||||||
item2 = Item.objects.create(container=self.box, event=self.event, description='2')
|
item2 = Item.objects.create(container=self.box1, event=self.event, description='2')
|
||||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.json()), 2)
|
self.assertEqual(len(response.json()), 2)
|
||||||
|
@ -261,15 +280,15 @@ class ItemSearchTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.event = Event.objects.create(slug='EVENT', name='Event')
|
self.event = Event.objects.create(slug='EVENT', name='Event')
|
||||||
self.box = Container.objects.create(name='BOX')
|
self.box1 = Container.objects.create(name='BOX1')
|
||||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
||||||
self.user.user_permissions.add(*Permission.objects.all())
|
self.user.user_permissions.add(*Permission.objects.all())
|
||||||
self.token = AuthToken.objects.create(user=self.user)
|
self.token = AuthToken.objects.create(user=self.user)
|
||||||
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
||||||
self.item1 = Item.objects.create(container=self.box, event=self.event, description='abc def')
|
self.item1 = Item.objects.create(container=self.box1, event=self.event, description='abc def')
|
||||||
self.item2 = Item.objects.create(container=self.box, event=self.event, description='def ghi')
|
self.item2 = Item.objects.create(container=self.box1, event=self.event, description='def ghi')
|
||||||
self.item3 = Item.objects.create(container=self.box, event=self.event, description='jkl mno pqr')
|
self.item3 = Item.objects.create(container=self.box1, event=self.event, description='jkl mno pqr')
|
||||||
self.item4 = Item.objects.create(container=self.box, event=self.event, description='stu vwx')
|
self.item4 = Item.objects.create(container=self.box1, event=self.event, description='stu vwx')
|
||||||
|
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
search_query = b64encode(b'abc').decode('utf-8')
|
search_query = b64encode(b'abc').decode('utf-8')
|
||||||
|
@ -278,8 +297,8 @@ class ItemSearchTestCase(TestCase):
|
||||||
self.assertEqual(1, len(response.json()))
|
self.assertEqual(1, len(response.json()))
|
||||||
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
||||||
self.assertEqual('abc def', response.json()[0]['description'])
|
self.assertEqual('abc def', response.json()[0]['description'])
|
||||||
self.assertEqual('BOX', response.json()[0]['box'])
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
||||||
self.assertEqual(1, response.json()[0]['search_score'])
|
self.assertEqual(1, response.json()[0]['search_score'])
|
||||||
|
|
||||||
def test_search2(self):
|
def test_search2(self):
|
||||||
|
@ -289,13 +308,13 @@ class ItemSearchTestCase(TestCase):
|
||||||
self.assertEqual(2, len(response.json()))
|
self.assertEqual(2, len(response.json()))
|
||||||
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
||||||
self.assertEqual('abc def', response.json()[0]['description'])
|
self.assertEqual('abc def', response.json()[0]['description'])
|
||||||
self.assertEqual('BOX', response.json()[0]['box'])
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
||||||
self.assertEqual(1, response.json()[0]['search_score'])
|
self.assertEqual(1, response.json()[0]['search_score'])
|
||||||
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
||||||
self.assertEqual('def ghi', response.json()[1]['description'])
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
||||||
self.assertEqual('BOX', response.json()[1]['box'])
|
self.assertEqual('BOX1', response.json()[1]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[1]['cid'])
|
self.assertEqual(self.box1.id, response.json()[1]['cid'])
|
||||||
self.assertEqual(1, response.json()[0]['search_score'])
|
self.assertEqual(1, response.json()[0]['search_score'])
|
||||||
|
|
||||||
def test_search3(self):
|
def test_search3(self):
|
||||||
|
@ -305,8 +324,8 @@ class ItemSearchTestCase(TestCase):
|
||||||
self.assertEqual(1, len(response.json()))
|
self.assertEqual(1, len(response.json()))
|
||||||
self.assertEqual(self.item3.id, response.json()[0]['id'])
|
self.assertEqual(self.item3.id, response.json()[0]['id'])
|
||||||
self.assertEqual('jkl mno pqr', response.json()[0]['description'])
|
self.assertEqual('jkl mno pqr', response.json()[0]['description'])
|
||||||
self.assertEqual('BOX', response.json()[0]['box'])
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
||||||
self.assertEqual(1, response.json()[0]['search_score'])
|
self.assertEqual(1, response.json()[0]['search_score'])
|
||||||
|
|
||||||
def test_search4(self):
|
def test_search4(self):
|
||||||
|
@ -316,12 +335,11 @@ class ItemSearchTestCase(TestCase):
|
||||||
self.assertEqual(2, len(response.json()))
|
self.assertEqual(2, len(response.json()))
|
||||||
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
||||||
self.assertEqual('abc def', response.json()[0]['description'])
|
self.assertEqual('abc def', response.json()[0]['description'])
|
||||||
self.assertEqual('BOX', response.json()[0]['box'])
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
||||||
self.assertEqual(2, response.json()[0]['search_score'])
|
self.assertEqual(2, response.json()[0]['search_score'])
|
||||||
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
||||||
self.assertEqual('def ghi', response.json()[1]['description'])
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
||||||
self.assertEqual('BOX', response.json()[1]['box'])
|
self.assertEqual('BOX1', response.json()[1]['box'])
|
||||||
self.assertEqual(self.box.id, response.json()[1]['cid'])
|
self.assertEqual(self.box1.id, response.json()[1]['cid'])
|
||||||
self.assertEqual(1, response.json()[1]['search_score'])
|
self.assertEqual(1, response.json()[1]['search_score'])
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 4.2.7 on 2024-11-22 18:57
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('mail', '0006_email_raw_file'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='eventaddress',
|
|
||||||
name='address',
|
|
||||||
field=models.CharField(max_length=255, unique=True),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -4,8 +4,6 @@ from django.db import models
|
||||||
from django_softdelete.models import SoftDeleteModel
|
from django_softdelete.models import SoftDeleteModel
|
||||||
|
|
||||||
from core.settings import MAIL_DOMAIN, ACTIVE_SPAM_TRAINING
|
from core.settings import MAIL_DOMAIN, ACTIVE_SPAM_TRAINING
|
||||||
from authentication.models import ExtendedUser
|
|
||||||
from core.settings import MAIL_DOMAIN
|
|
||||||
from files.models import AbstractFile
|
from files.models import AbstractFile
|
||||||
from inventory.models import Event
|
from inventory.models import Event
|
||||||
from tickets.models import IssueThread
|
from tickets.models import IssueThread
|
||||||
|
@ -46,7 +44,7 @@ class Email(SoftDeleteModel):
|
||||||
class EventAddress(models.Model):
|
class EventAddress(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
event = models.ForeignKey(Event, models.SET_NULL, null=True, related_name='addresses')
|
event = models.ForeignKey(Event, models.SET_NULL, null=True, related_name='addresses')
|
||||||
address = models.CharField(max_length=255, unique=True)
|
address = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
|
||||||
class EmailAttachment(AbstractFile):
|
class EmailAttachment(AbstractFile):
|
||||||
|
|
|
@ -7,7 +7,6 @@ from channels.db import database_sync_to_async
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
|
||||||
from mail.models import Email, EventAddress, EmailAttachment
|
from mail.models import Email, EventAddress, EmailAttachment
|
||||||
from notifications.templates import render_auto_reply
|
|
||||||
from notify_sessions.models import SystemEvent
|
from notify_sessions.models import SystemEvent
|
||||||
from tickets.models import IssueThread
|
from tickets.models import IssueThread
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ def make_reply(reply_email, references=None, event=None):
|
||||||
reply["From"] = reply_email.sender
|
reply["From"] = reply_email.sender
|
||||||
reply["To"] = reply_email.recipient
|
reply["To"] = reply_email.recipient
|
||||||
reply["Subject"] = reply_email.subject
|
reply["Subject"] = reply_email.subject
|
||||||
reply["Reply-To"] = f"{event.lower()}@{MAIL_DOMAIN}"
|
reply["Reply-To"] = f"{event}@{MAIL_DOMAIN}"
|
||||||
if reply_email.in_reply_to:
|
if reply_email.in_reply_to:
|
||||||
reply["In-Reply-To"] = reply_email.in_reply_to
|
reply["In-Reply-To"] = reply_email.in_reply_to
|
||||||
if reply_email.reference:
|
if reply_email.reference:
|
||||||
|
@ -88,22 +87,6 @@ def make_reply(reply_email, references=None, event=None):
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
|
||||||
def make_notification(message, to, title): # TODO where should replies to this go
|
|
||||||
from email.message import EmailMessage
|
|
||||||
from core.settings import MAIL_DOMAIN
|
|
||||||
notification = EmailMessage()
|
|
||||||
notification["From"] = "notifications@%s" % MAIL_DOMAIN
|
|
||||||
notification["To"] = to
|
|
||||||
notification["Subject"] = f"[C3LF Notification]%s" % title
|
|
||||||
# notification["Reply-To"] = f"{event}@{MAIL_DOMAIN}"
|
|
||||||
# notification["In-Reply-To"] = email.reference
|
|
||||||
# notification["Message-ID"] = email.id + "@" + MAIL_DOMAIN
|
|
||||||
|
|
||||||
notification.set_content(message)
|
|
||||||
|
|
||||||
return notification
|
|
||||||
|
|
||||||
|
|
||||||
async def send_smtp(message):
|
async def send_smtp(message):
|
||||||
await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False)
|
await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False)
|
||||||
|
|
||||||
|
@ -202,16 +185,6 @@ def receive_email(envelope, log=None):
|
||||||
header_in_reply_to = parsed.get('In-Reply-To')
|
header_in_reply_to = parsed.get('In-Reply-To')
|
||||||
header_message_id = parsed.get('Message-ID')
|
header_message_id = parsed.get('Message-ID')
|
||||||
|
|
||||||
# if header_from != envelope.mail_from:
|
|
||||||
# log.warning("Header from does not match envelope from")
|
|
||||||
# log.info(f"Header from: {header_from}, envelope from: {envelope.mail_from}")
|
|
||||||
#
|
|
||||||
# if header_to != envelope.rcpt_tos[0]:
|
|
||||||
# log.warning("Header to does not match envelope to")
|
|
||||||
# log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}")
|
|
||||||
|
|
||||||
# handle undelivered mail header_from : 'Mail Delivery System <MAILER-DAEMON@...'
|
|
||||||
|
|
||||||
if match(r'^([a-zA-Z ]*<)?MAILER-DAEMON@', header_from) and envelope.mail_from.strip("<>") == "":
|
if match(r'^([a-zA-Z ]*<)?MAILER-DAEMON@', header_from) and envelope.mail_from.strip("<>") == "":
|
||||||
log.warning("Ignoring mailer daemon")
|
log.warning("Ignoring mailer daemon")
|
||||||
raise SpecialMailException("Ignoring mailer daemon")
|
raise SpecialMailException("Ignoring mailer daemon")
|
||||||
|
@ -248,7 +221,16 @@ def receive_email(envelope, log=None):
|
||||||
references = collect_references(active_issue_thread)
|
references = collect_references(active_issue_thread)
|
||||||
if not sender.startswith('noreply'):
|
if not sender.startswith('noreply'):
|
||||||
subject = f"Re: {subject} [#{active_issue_thread.short_uuid()}]"
|
subject = f"Re: {subject} [#{active_issue_thread.short_uuid()}]"
|
||||||
body = render_auto_reply(active_issue_thread)
|
body = '''Your request (#{}) has been received and will be reviewed by our lost&found angels.
|
||||||
|
|
||||||
|
We are reviewing incoming requests during the event and teardown. Immediately after the event, expect a delay as the \
|
||||||
|
workload is high. We will not forget about your request and get back in touch once we have updated information on your \
|
||||||
|
request. Requests for devices, wallets, credit cards or similar items will be handled with priority.
|
||||||
|
|
||||||
|
If you happen to find your lost item or just want to add additional information, please reply to this email. Please \
|
||||||
|
do not create a new request.
|
||||||
|
|
||||||
|
Your c3lf (Cloakroom + Lost&Found) Team'''.format(active_issue_thread.short_uuid())
|
||||||
reply_email = Email.objects.create(
|
reply_email = Email.objects.create(
|
||||||
sender=recipient, recipient=sender, body=body, subject=subject,
|
sender=recipient, recipient=sender, body=body, subject=subject,
|
||||||
in_reply_to=header_message_id, event=target_event, issue_thread=active_issue_thread)
|
in_reply_to=header_message_id, event=target_event, issue_thread=active_issue_thread)
|
||||||
|
@ -291,19 +273,11 @@ class LMTPHandler:
|
||||||
'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
|
||||||
"message": "email received"})
|
"message": "email received"})
|
||||||
log.info(f"Sent message to frontend")
|
log.info(f"Sent message to frontend")
|
||||||
|
|
||||||
if new and reply:
|
if new and reply:
|
||||||
log.info('Sending message to %s' % reply['To'])
|
log.info('Sending message to %s' % reply['To'])
|
||||||
await send_smtp(reply)
|
await send_smtp(reply)
|
||||||
log.info("Sent auto reply")
|
log.info("Sent auto reply")
|
||||||
|
|
||||||
if thread:
|
|
||||||
await channel_layer.group_send(
|
|
||||||
'general', {"type": "generic.event", "name": "user_notification", "event_id": systemevent.id,
|
|
||||||
"ticket_id": thread.id, "new": new})
|
|
||||||
else:
|
|
||||||
print("No thread found")
|
|
||||||
|
|
||||||
return '250 Message accepted for delivery'
|
return '250 Message accepted for delivery'
|
||||||
except SpecialMailException as e:
|
except SpecialMailException as e:
|
||||||
import uuid
|
import uuid
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
from django.contrib.auth.models import Permission
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from authentication.models import ExtendedUser
|
|
||||||
from notifications.models import UserNotificationChannel
|
|
||||||
|
|
||||||
|
|
||||||
class UserNotificationTestCase(TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super().setUp()
|
|
||||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
|
||||||
self.user.user_permissions.add(*Permission.objects.all())
|
|
||||||
self.user.save()
|
|
||||||
self.channel = UserNotificationChannel.objects.create(user=self.user, channel_type='telegram',
|
|
||||||
channel_target='123456789',
|
|
||||||
event_filter='*', active=True)
|
|
||||||
|
|
||||||
async def test_telegram_notify(self):
|
|
||||||
pass
|
|
|
@ -1,15 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
from notifications.models import MessageTemplate, UserNotificationChannel
|
|
||||||
|
|
||||||
|
|
||||||
class MessageTemplateAdmin(admin.ModelAdmin):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UserNotificationChannelAdmin(admin.ModelAdmin):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(MessageTemplate, MessageTemplateAdmin)
|
|
||||||
admin.site.register(UserNotificationChannel, UserNotificationChannelAdmin)
|
|
|
@ -1,51 +0,0 @@
|
||||||
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, UserNotificationChannel
|
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from notifications.templates import TEMPLATE_VARS
|
|
||||||
from authentication.serializers import UserSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class MessageTemplateSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = MessageTemplate
|
|
||||||
fields = '__all__'
|
|
||||||
|
|
||||||
|
|
||||||
class UserNotificationChannelSerializer(serializers.ModelSerializer):
|
|
||||||
user = UserSerializer()
|
|
||||||
|
|
||||||
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
|
|
||||||
def get_template_vars(self):
|
|
||||||
return Response(TEMPLATE_VARS, status=200)
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
|
@ -1,16 +0,0 @@
|
||||||
auto_reply_body = '''Your request (#{{ ticket_uuid }}) has been received and will be reviewed by our lost&found angels.
|
|
||||||
|
|
||||||
We are reviewing incoming requests during the event and teardown. Immediately after the event, expect a delay as the \
|
|
||||||
workload is high. We will not forget about your request and get back in touch once we have updated information on your \
|
|
||||||
request. Requests for devices, wallets, credit cards or similar items will be handled with priority.
|
|
||||||
|
|
||||||
If you happen to find your lost item or just want to add additional information, please reply to this email. Please \
|
|
||||||
do not create a new request.
|
|
||||||
|
|
||||||
Your c3lf (Cloakroom + Lost&Found) Team'''
|
|
||||||
|
|
||||||
new_issue_notification = '''New issue "{{ ticket_name | limit_length }}" [{{ ticket_uuid }}] created
|
|
||||||
{{ ticket_url }}'''
|
|
||||||
|
|
||||||
reply_issue_notification = '''Reply to issue "{{ ticket_name }}" [{{ ticket_uuid }}] (was {{ previous_state_pretty }})
|
|
||||||
{{ ticket_url }}'''
|
|
|
@ -1,85 +0,0 @@
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from aiohttp.client import ClientSession
|
|
||||||
from channels.layers import get_channel_layer
|
|
||||||
from channels.db import database_sync_to_async
|
|
||||||
from urllib.parse import quote as urlencode
|
|
||||||
|
|
||||||
from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID
|
|
||||||
from mail.protocol import send_smtp, make_notification
|
|
||||||
from notifications.models import UserNotificationChannel
|
|
||||||
from notifications.templates import render_notification_new_ticket_async, render_notification_reply_ticket_async
|
|
||||||
from tickets.models import IssueThread
|
|
||||||
|
|
||||||
|
|
||||||
async def http_get(url):
|
|
||||||
async with ClientSession() as session:
|
|
||||||
async with session.get(url) as response:
|
|
||||||
return await response.text()
|
|
||||||
|
|
||||||
|
|
||||||
async def telegram_notify(message, chat_id):
|
|
||||||
encoded_message = urlencode(message)
|
|
||||||
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage?chat_id={chat_id}&text={encoded_message}"
|
|
||||||
return await http_get(url)
|
|
||||||
|
|
||||||
|
|
||||||
async def email_notify(message, title, email):
|
|
||||||
mail = make_notification(message, email, title)
|
|
||||||
await send_smtp(mail)
|
|
||||||
|
|
||||||
|
|
||||||
class NotificationDispatcher:
|
|
||||||
channel_layer = None
|
|
||||||
room_group_name = "general"
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.channel_layer = get_channel_layer('default')
|
|
||||||
if not self.channel_layer:
|
|
||||||
raise Exception("Could not get channel layer")
|
|
||||||
|
|
||||||
@database_sync_to_async
|
|
||||||
def get_notification_targets(self):
|
|
||||||
channels = UserNotificationChannel.objects.filter(active=True)
|
|
||||||
return list(channels)
|
|
||||||
|
|
||||||
@database_sync_to_async
|
|
||||||
def get_ticket(self, ticket_id):
|
|
||||||
return IssueThread.objects.filter(id=ticket_id).select_related('event').first()
|
|
||||||
|
|
||||||
async def run_forever(self):
|
|
||||||
# Infinite loop to continuously listen for messages
|
|
||||||
print("Listening for messages...")
|
|
||||||
channel_name = await self.channel_layer.new_channel()
|
|
||||||
await self.channel_layer.group_add(self.room_group_name, channel_name)
|
|
||||||
print("Channel name:", channel_name)
|
|
||||||
while True:
|
|
||||||
# Blocking receive to get the message from the channel layer
|
|
||||||
message = await self.channel_layer.receive(channel_name)
|
|
||||||
|
|
||||||
if (message and 'type' in message and message['type'] == 'generic.event' and 'name' in message and
|
|
||||||
message['name'] == 'user_notification'):
|
|
||||||
if 'ticket_id' in message and 'event_id' in message and 'new' in message:
|
|
||||||
ticket = await self.get_ticket(message['ticket_id'])
|
|
||||||
await self.dispatch(ticket, message['event_id'], message['new'])
|
|
||||||
else:
|
|
||||||
print("Error: Invalid message format")
|
|
||||||
|
|
||||||
async def dispatch(self, ticket, event_id, new):
|
|
||||||
message = await render_notification_new_ticket_async(
|
|
||||||
ticket) if new else await render_notification_reply_ticket_async(ticket)
|
|
||||||
title = f"[#{ticket.short_uuid()}] {ticket.name}"
|
|
||||||
print("Dispatching message:", message, "with event_id:", event_id)
|
|
||||||
targets = await self.get_notification_targets()
|
|
||||||
jobs = []
|
|
||||||
jobs.append(telegram_notify(message, TELEGRAM_GROUP_CHAT_ID))
|
|
||||||
for target in targets:
|
|
||||||
if target.channel_type == 'telegram':
|
|
||||||
print("Sending telegram notification to:", target.channel_target)
|
|
||||||
jobs.append(telegram_notify(message, target.channel_target))
|
|
||||||
elif target.channel_type == 'email':
|
|
||||||
print("Sending email notification to:", target.channel_target)
|
|
||||||
jobs.append(email_notify(message, title, target.channel_target))
|
|
||||||
else:
|
|
||||||
print("Unknown channel type:", target.channel_type)
|
|
||||||
await asyncio.gather(*jobs)
|
|
|
@ -1,51 +0,0 @@
|
||||||
# Generated by Django 4.2.7 on 2024-05-03 21:02
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
from notifications.defaults import auto_reply_body, new_issue_notification, reply_issue_notification
|
|
||||||
from notifications.models import MessageTemplate
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
|
||||||
|
|
||||||
def create_required_templates(apps, schema_editor):
|
|
||||||
MessageTemplate.objects.create(name='auto_reply', message=auto_reply_body, marked_required=True)
|
|
||||||
MessageTemplate.objects.create(name='new_issue_notification', message=new_issue_notification,
|
|
||||||
marked_required=True)
|
|
||||||
MessageTemplate.objects.create(name='reply_issue_notification', message=reply_issue_notification,
|
|
||||||
marked_required=True)
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='MessageTemplate',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=255)),
|
|
||||||
('message', models.TextField()),
|
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('marked_confidential', models.BooleanField(default=False)),
|
|
||||||
('marked_required', models.BooleanField(default=False)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='UserNotificationChannel',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('channel_type',
|
|
||||||
models.CharField(choices=[('telegram', 'telegram'), ('email', 'email')], max_length=255)),
|
|
||||||
('channel_target', models.CharField(max_length=255)),
|
|
||||||
('event_filter', models.CharField(max_length=255)),
|
|
||||||
('active', models.BooleanField(default=True)),
|
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.RunPython(create_required_templates),
|
|
||||||
]
|
|
|
@ -1,29 +0,0 @@
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
from authentication.models import ExtendedUser
|
|
||||||
|
|
||||||
|
|
||||||
class MessageTemplate(models.Model):
|
|
||||||
name = models.CharField(max_length=255)
|
|
||||||
message = models.TextField()
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
marked_confidential = models.BooleanField(default=False)
|
|
||||||
marked_required = models.BooleanField(default=False) # may not be deleted
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
class UserNotificationChannel(models.Model):
|
|
||||||
user = models.ForeignKey(ExtendedUser, models.CASCADE)
|
|
||||||
channel_type = models.CharField(choices=[('telegram', 'telegram'), ('email', 'email')], max_length=255)
|
|
||||||
channel_target = models.CharField(max_length=255)
|
|
||||||
event_filter = models.CharField(max_length=255)
|
|
||||||
active = models.BooleanField(default=True)
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
def validate_constraints(self, exclude=None): # TODO: email -> emailaddress, telegram -> chatid
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.user.username + '(' + self.channel_type + ')'
|
|
|
@ -1,69 +0,0 @@
|
||||||
import jinja2
|
|
||||||
from channels.db import database_sync_to_async
|
|
||||||
from core.settings import PRIMARY_HOST
|
|
||||||
|
|
||||||
from notifications.models import MessageTemplate
|
|
||||||
|
|
||||||
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',
|
|
||||||
'web_host'] # TODO customer_name, tracking_code
|
|
||||||
|
|
||||||
|
|
||||||
def limit_length(s, length=50):
|
|
||||||
if len(s) > length:
|
|
||||||
return s[:(length - 3)] + "..."
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def ticket_url(ticket):
|
|
||||||
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
|
|
||||||
return f"https://{PRIMARY_HOST}/{eventslug}/ticket/{ticket.id}/"
|
|
||||||
|
|
||||||
|
|
||||||
def render_template(template, **kwargs):
|
|
||||||
try:
|
|
||||||
environment = jinja2.Environment()
|
|
||||||
environment.filters['limit_length'] = limit_length
|
|
||||||
tmpl = MessageTemplate.objects.get(name=template)
|
|
||||||
template = environment.from_string(tmpl.message)
|
|
||||||
return template.render(**kwargs, web_host=PRIMARY_HOST)
|
|
||||||
except MessageTemplate.DoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_ticket_vars(ticket):
|
|
||||||
states = list(ticket.state_changes.order_by('-timestamp'))
|
|
||||||
return {
|
|
||||||
'ticket_name': ticket.name,
|
|
||||||
'ticket_uuid': ticket.short_uuid(),
|
|
||||||
'ticket_id': ticket.id,
|
|
||||||
'ticket_url': ticket_url(ticket),
|
|
||||||
'current_state': states[0].state if states else 'none',
|
|
||||||
'previous_state': states[1].state if len(states) > 1 else 'none',
|
|
||||||
'current_state_pretty': states[0].get_state_display() if states else 'none',
|
|
||||||
'previous_state_pretty': states[1].get_state_display() if len(states) > 1 else 'none',
|
|
||||||
'event_slug': ticket.event.slug if ticket.event else "37C3", # TODO 37C3 should not be hardcoded
|
|
||||||
'event_name': ticket.event.name if ticket.event else "37C3",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def render_auto_reply(ticket):
|
|
||||||
return render_template('auto_reply', **get_ticket_vars(ticket))
|
|
||||||
|
|
||||||
|
|
||||||
def render_notification_new_ticket(ticket):
|
|
||||||
return render_template('new_issue_notification', **get_ticket_vars(ticket))
|
|
||||||
|
|
||||||
|
|
||||||
def render_notification_reply_ticket(ticket):
|
|
||||||
return render_template('reply_issue_notification', **get_ticket_vars(ticket))
|
|
||||||
|
|
||||||
|
|
||||||
async def render_notification_new_ticket_async(ticket):
|
|
||||||
return await database_sync_to_async(render_notification_new_ticket)(ticket)
|
|
||||||
|
|
||||||
|
|
||||||
async def render_notification_reply_ticket_async(ticket):
|
|
||||||
return await database_sync_to_async(render_notification_reply_ticket)(ticket)
|
|
|
@ -1,21 +0,0 @@
|
||||||
from asgiref.sync import async_to_sync
|
|
||||||
from channels.layers import get_channel_layer
|
|
||||||
|
|
||||||
|
|
||||||
def notify_sessions(event, data):
|
|
||||||
def wrapper(func):
|
|
||||||
def wrapped(*args, **kwargs):
|
|
||||||
ret = func(*args, **kwargs)
|
|
||||||
channel_layer = get_channel_layer()
|
|
||||||
async_to_sync(channel_layer.group_send)(
|
|
||||||
event,
|
|
||||||
{
|
|
||||||
'type': 'notify',
|
|
||||||
'data': data,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
return wrapper
|
|
7
core/server.py
Executable file → Normal file
7
core/server.py
Executable file → Normal file
|
@ -12,7 +12,6 @@ django.setup()
|
||||||
from helper import init_loop
|
from helper import init_loop
|
||||||
from mail.protocol import LMTPHandler
|
from mail.protocol import LMTPHandler
|
||||||
from mail.socket import UnixSocketLMTPController
|
from mail.socket import UnixSocketLMTPController
|
||||||
from notifications.dispatch import NotificationDispatcher
|
|
||||||
|
|
||||||
|
|
||||||
class UvicornServer(uvicorn.Server):
|
class UvicornServer(uvicorn.Server):
|
||||||
|
@ -55,11 +54,6 @@ async def lmtp(loop):
|
||||||
log.info("LMTP done")
|
log.info("LMTP done")
|
||||||
|
|
||||||
|
|
||||||
async def notifications(loop):
|
|
||||||
dispatcher = NotificationDispatcher()
|
|
||||||
await dispatcher.run_forever()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sdnotify
|
import sdnotify
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
@ -73,7 +67,6 @@ def main():
|
||||||
loop.create_task(web(loop))
|
loop.create_task(web(loop))
|
||||||
# loop.create_task(tcp(loop))
|
# loop.create_task(tcp(loop))
|
||||||
loop.create_task(lmtp(loop))
|
loop.create_task(lmtp(loop))
|
||||||
loop.create_task(notifications(loop))
|
|
||||||
n = sdnotify.SystemdNotifier()
|
n = sdnotify.SystemdNotifier()
|
||||||
n.notify("READY=1")
|
n.notify("READY=1")
|
||||||
log.info("Server ready")
|
log.info("Server ready")
|
||||||
|
|
|
@ -21,8 +21,7 @@ from tickets.shared_serializers import RelationSerializer
|
||||||
|
|
||||||
class IssueViewSet(viewsets.ModelViewSet):
|
class IssueViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = IssueSerializer
|
serializer_class = IssueSerializer
|
||||||
queryset = IssueThread.objects.all().prefetch_related('state_changes', 'comments', 'emails', 'emails__attachments',
|
queryset = IssueThread.objects.all().prefetch_related('state_changes', 'comments', 'emails', 'emails__attachments', 'assignments', 'item_relation_changes', 'shipping_vouchers')
|
||||||
'assignments', 'item_relation_changes', 'shipping_vouchers')
|
|
||||||
|
|
||||||
|
|
||||||
class RelationViewSet(viewsets.ModelViewSet):
|
class RelationViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -166,7 +165,6 @@ router.register(r'tickets', IssueViewSet, basename='issues')
|
||||||
router.register(r'matches', RelationViewSet, basename='matches')
|
router.register(r'matches', RelationViewSet, basename='matches')
|
||||||
router.register(r'shipping_vouchers', ShippingVoucherViewSet, basename='shipping_vouchers')
|
router.register(r'shipping_vouchers', ShippingVoucherViewSet, basename='shipping_vouchers')
|
||||||
|
|
||||||
# [-A-Za-z0-9+/]*={0,3}
|
|
||||||
urlpatterns = ([
|
urlpatterns = ([
|
||||||
re_path(r'tickets/states/$', get_available_states, name='get_available_states'),
|
re_path(r'tickets/states/$', get_available_states, name='get_available_states'),
|
||||||
re_path(r'^tickets/(?P<pk>\d+)/reply/$', reply, name='reply'),
|
re_path(r'^tickets/(?P<pk>\d+)/reply/$', reply, name='reply'),
|
||||||
|
|
|
@ -129,6 +129,7 @@ class IssueSerializer(BasicIssueSerializer):
|
||||||
return sorted(timeline, key=lambda x: x['timestamp'])
|
return sorted(timeline, key=lambda x: x['timestamp'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SearchResultSerializer(serializers.Serializer):
|
class SearchResultSerializer(serializers.Serializer):
|
||||||
search_score = serializers.IntegerField()
|
search_score = serializers.IntegerField()
|
||||||
item = IssueSerializer()
|
item = IssueSerializer()
|
||||||
|
|
|
@ -117,7 +117,6 @@ class IssueApiTest(TestCase):
|
||||||
self.assertEqual(response.json()[0]['timeline'][5]['item']['description'], "foo")
|
self.assertEqual(response.json()[0]['timeline'][5]['item']['description'], "foo")
|
||||||
self.assertEqual(response.json()[0]['timeline'][5]['item']['event'], "evt")
|
self.assertEqual(response.json()[0]['timeline'][5]['item']['event'], "evt")
|
||||||
self.assertEqual(response.json()[0]['timeline'][5]['item']['box'], "box1")
|
self.assertEqual(response.json()[0]['timeline'][5]['item']['box'], "box1")
|
||||||
self.assertEqual(len(response.json()[0]['related_items']), 1)
|
|
||||||
self.assertEqual(response.json()[0]['related_items'][0]['description'], "foo")
|
self.assertEqual(response.json()[0]['related_items'][0]['description'], "foo")
|
||||||
self.assertEqual(response.json()[0]['related_items'][0]['event'], "evt")
|
self.assertEqual(response.json()[0]['related_items'][0]['event'], "evt")
|
||||||
self.assertEqual(response.json()[0]['related_items'][0]['box'], "box1")
|
self.assertEqual(response.json()[0]['related_items'][0]['box'], "box1")
|
||||||
|
|
|
@ -13,5 +13,3 @@ STATIC_ROOT=/var/www/c3lf-sys3/staticfiles
|
||||||
ACTIVE_SPAM_TRAINING=True
|
ACTIVE_SPAM_TRAINING=True
|
||||||
DEBUG_MODE_ACTIVE={{ debug_mode_active }}
|
DEBUG_MODE_ACTIVE={{ debug_mode_active }}
|
||||||
DJANGO_SECRET_KEY={{ django_secret_key }}
|
DJANGO_SECRET_KEY={{ django_secret_key }}
|
||||||
TELEGRAM_GROUP_CHAT_ID={{ telegram_group_chat_id }}
|
|
||||||
TELEGRAM_BOT_TOKEN={{ telegram_bot_token }}
|
|
|
@ -8,7 +8,6 @@
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chenfengyuan/vue-qrcode": "^2.0.0",
|
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.5.1",
|
"@fortawesome/fontawesome-svg-core": "^6.5.1",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.5.1",
|
"@fortawesome/free-solid-svg-icons": "^6.5.1",
|
||||||
"@fortawesome/vue-fontawesome": "^3.0.6",
|
"@fortawesome/vue-fontawesome": "^3.0.6",
|
||||||
|
|
|
@ -1,31 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3 col-xl-2">
|
<div class="col-lg-3 col-xl-2">
|
||||||
<!--div class="card bg-dark text-light mb-2" id="filters">
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title text-info">Sort & Filter</h5>
|
|
||||||
<div class="form-group" v-for="(column, index) in columns" :key="index">
|
|
||||||
<label>{{ column }}</label>
|
|
||||||
<div class="input-group">
|
|
||||||
<div class="input-group-prepend">
|
|
||||||
<button
|
|
||||||
:class="[ 'btn', column === sortBy ? 'btn-outline-info' : 'btn-outline-secondary' ]"
|
|
||||||
type="button"
|
|
||||||
@click="toggleSort(column)">
|
|
||||||
<font-awesome-icon :icon="getSortIcon(column)"/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
class="form-control"
|
|
||||||
placeholder="filter"
|
|
||||||
:value="filters[column]"
|
|
||||||
@input="changeFilter(column, $event.target.value)"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-9 col-xl-8">
|
<div class="col-lg-9 col-xl-8">
|
||||||
<div class="w-100"
|
<div class="w-100"
|
||||||
|
@ -73,10 +48,11 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
collapsed: [],
|
collapsed: [],
|
||||||
|
symbols: ['▲', '▼', '▶', '◀'],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
const query = this.route ? (this.route.query ? this.route.query.collapsed : null) : null;
|
const query = this.$router.currentRoute ? (this.$router.currentRoute.query ? this.$router.currentRoute.query.collapsed : null) : null;
|
||||||
if (query !== null && query !== undefined) {
|
if (query !== null && query !== undefined) {
|
||||||
this.collapsed = this.unpackInt(parseInt(query), this.sections.length);
|
this.collapsed = this.unpackInt(parseInt(query), this.sections.length);
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,8 +84,8 @@ export default {
|
||||||
const encoded = this.packInt(this.collapsed).toString()
|
const encoded = this.packInt(this.collapsed).toString()
|
||||||
if (this.route.query.collapsed !== encoded)
|
if (this.route.query.collapsed !== encoded)
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
...this.route,
|
...this.$router.currentRoute,
|
||||||
query: {...this.route.query, collapsed: encoded}
|
query: {...this.$router.currentRoute.query, collapsed: encoded}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
field="description"
|
field="description"
|
||||||
:validation-fn="str => str && str.length > 0"
|
:validation-fn="str => str && str.length > 0"
|
||||||
/>
|
/>
|
||||||
<div class="form-group">
|
|
||||||
<label for="box">box</label>
|
|
||||||
<InputCombo
|
<InputCombo
|
||||||
label="box"
|
label="box"
|
||||||
:model="item"
|
:model="item"
|
||||||
|
@ -22,7 +20,6 @@
|
||||||
:options="boxes"
|
:options="boxes"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -1,222 +0,0 @@
|
||||||
<template>
|
|
||||||
<ol class="timeline">
|
|
||||||
<li v-for="(item, index) in timeline" :key="index"
|
|
||||||
:class="{'timeline-item':true, 'extra-space': item.type === 'mail'}">
|
|
||||||
<span class="timeline-item-icon filled-icon" v-if="item.type === 'mail'">
|
|
||||||
<font-awesome-icon icon="envelope"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else-if="item.type === 'comment'">
|
|
||||||
<font-awesome-icon icon="comment"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else-if="item.type === 'state'"
|
|
||||||
:class="'bg-' + stateInfo(item.state).color">
|
|
||||||
<font-awesome-icon :icon="stateInfo(item.state).icon"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else-if="item.type === 'assignment'" :class="'bg-secondary'">
|
|
||||||
<font-awesome-icon icon="user"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else-if="item.type === 'item_relation'">
|
|
||||||
<font-awesome-icon icon="object-group"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else-if="item.type === 'shipping_voucher'">
|
|
||||||
<font-awesome-icon icon="truck"/>
|
|
||||||
</span>
|
|
||||||
<span class="timeline-item-icon faded-icon" v-else>
|
|
||||||
<font-awesome-icon icon="pen"/>
|
|
||||||
</span>
|
|
||||||
<TimelineMail v-if="item.type === 'mail'" :item="item"/>
|
|
||||||
<TimelineComment v-else-if="item.type === 'comment'" :item="item"/>
|
|
||||||
<TimelineStateChange v-else-if="item.type === 'state'" :item="item"/>
|
|
||||||
<TimelineAssignment v-else-if="item.type === 'assignment'" :item="item"/>
|
|
||||||
<TimelineRelatedItem v-else-if="item.type === 'item_relation'" :item="item"/>
|
|
||||||
<TimelineShippingVoucher v-else-if="item.type === 'shipping_voucher'" :item="item"/>
|
|
||||||
<p v-else>{{ item }}</p>
|
|
||||||
</li>
|
|
||||||
<li class="timeline-item">
|
|
||||||
<span class="timeline-item-icon | faded-icon">
|
|
||||||
<font-awesome-icon icon="comment"/>
|
|
||||||
</span>
|
|
||||||
<div class="new-comment card bg-dark">
|
|
||||||
<div class="">
|
|
||||||
<textarea placeholder="add comment..." v-model="newComment" class="form-control">
|
|
||||||
</textarea>
|
|
||||||
<AsyncButton class="btn btn-primary float-right" :task="addCommentAndClear">
|
|
||||||
<font-awesome-icon icon="comment"/>
|
|
||||||
Save Comment
|
|
||||||
</AsyncButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
import TimelineMail from "@/components/TimelineMail.vue";
|
|
||||||
import TimelineComment from "@/components/TimelineComment.vue";
|
|
||||||
import TimelineStateChange from "@/components/TimelineStateChange.vue";
|
|
||||||
import {mapActions, mapGetters} from "vuex";
|
|
||||||
import TimelineAssignment from "@/components/TimelineAssignment.vue";
|
|
||||||
import TimelineRelatedItem from "@/components/TimelineRelatedItem.vue";
|
|
||||||
import TimelineShippingVoucher from "@/components/TimelineShippingVoucher.vue";
|
|
||||||
import AsyncButton from "@/components/inputs/AsyncButton.vue";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Timeline',
|
|
||||||
components: {
|
|
||||||
TimelineShippingVoucher, AsyncButton,
|
|
||||||
TimelineRelatedItem, TimelineAssignment, TimelineStateChange, TimelineComment, TimelineMail
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
timeline: {
|
|
||||||
type: Array,
|
|
||||||
default: () => []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
emits: ['sendMail', 'addComment'],
|
|
||||||
data: () => ({
|
|
||||||
newMail: "",
|
|
||||||
newComment: ""
|
|
||||||
}),
|
|
||||||
computed: {
|
|
||||||
...mapGetters(['stateInfo']),
|
|
||||||
newestMailSubject() {
|
|
||||||
const mail = this.timeline.filter(item => item.type === 'mail').pop();
|
|
||||||
return mail ? mail.subject : "";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
...mapActions(['sendMail', 'postComment']),
|
|
||||||
sendMailAndClear: async function () {
|
|
||||||
await this.sendMail(this.newMail);
|
|
||||||
this.newMail = "";
|
|
||||||
},
|
|
||||||
addCommentAndClear: async function () {
|
|
||||||
await this.postComment(this.newComment);
|
|
||||||
this.newComment = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
*,
|
|
||||||
*:before,
|
|
||||||
*:after {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
button,
|
|
||||||
input,
|
|
||||||
select,
|
|
||||||
textarea {
|
|
||||||
font: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
display: block;
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* End basic CSS override */
|
|
||||||
|
|
||||||
.timeline {
|
|
||||||
width: 85%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 32px 0 32px 32px;
|
|
||||||
border-left: 2px solid var(--gray);
|
|
||||||
font-size: 1.125rem;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-item {
|
|
||||||
display: flex;
|
|
||||||
gap: 24px;
|
|
||||||
|
|
||||||
& + * {
|
|
||||||
margin-top: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
& + .extra-space {
|
|
||||||
margin-top: 48px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.new-comment, .new-mail {
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
textarea, input {
|
|
||||||
border: 1px solid var(--gray);
|
|
||||||
border-radius: 6px;
|
|
||||||
height: 5em;
|
|
||||||
padding: 8px 16px;
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--gray-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
border-color: var(--gray-dark);
|
|
||||||
outline: 0; /* Don't actually do this */
|
|
||||||
box-shadow: 0 0 0 4px var(--dark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-item-icon {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 50px;
|
|
||||||
height: 50px;
|
|
||||||
border-radius: 50%;
|
|
||||||
margin-left: -57px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: 20px;
|
|
||||||
height: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.faded-icon {
|
|
||||||
background-color: var(--secondary);
|
|
||||||
color: var(--light);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.filled-icon {
|
|
||||||
background-color: var(--primary);
|
|
||||||
color: var(--light);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.button {
|
|
||||||
border: 0;
|
|
||||||
display: inline-flex;
|
|
||||||
vertical-align: middle;
|
|
||||||
margin-right: 4px;
|
|
||||||
margin-top: 12px;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: 1rem;
|
|
||||||
height: 32px;
|
|
||||||
padding: 0 8px;
|
|
||||||
background-color: var(--dark);
|
|
||||||
flex-shrink: 0;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 99em;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--gray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
|
|
@ -1,105 +0,0 @@
|
||||||
<template>
|
|
||||||
<table class="table table-striped table-dark">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col" v-for="(column, index) in columns" :key="index"
|
|
||||||
v-if="columnHasData[index]||columnHasSlot[index]">
|
|
||||||
<div class="input-group" v-if="columnHasData[index]">
|
|
||||||
<div class="input-group-prepend">
|
|
||||||
<button
|
|
||||||
:class="[ 'btn', column === sortBy ? 'btn-outline-info' : 'btn-outline-secondary' ]"
|
|
||||||
@click="toggleSort(column)"
|
|
||||||
>
|
|
||||||
{{ column }}
|
|
||||||
<span :class="{ 'text-info': column === sortBy }">
|
|
||||||
<font-awesome-icon :icon="getSortIcon(column)"/>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
class="form-control"
|
|
||||||
placeholder="filter"
|
|
||||||
:value="filters[column]"
|
|
||||||
@input="changeFilter(column, $event.target.value)"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<span v-else-if="columnHasSlot[index]">
|
|
||||||
{{ column }}
|
|
||||||
</span>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<slot name="header_actions"/>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="item in internalItems" :key="item[keyName]" @click="$emit('itemActivated', item)">
|
|
||||||
<td v-for="(column, index) in columns" :key="index" v-if="columnHasSlot[index]||columnHasData[index]">
|
|
||||||
<slot v-if="columnHasSlot[index]" :name="column" :item="item"/>
|
|
||||||
<span v-else-if="columnHasData[index]">
|
|
||||||
{{ item[column] }}
|
|
||||||
</span>
|
|
||||||
<span v-else>
|
|
||||||
{{ column }}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<slot v-bind:item="item" name="actions"/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import DataContainer from '@/mixins/data-container';
|
|
||||||
import router from '../router';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'SlotTable',
|
|
||||||
mixins: [DataContainer],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
columnHasSlot: [],
|
|
||||||
columnHasData: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.columns.map(e => ({
|
|
||||||
k: e,
|
|
||||||
v: this.$store.getters.getFilters[e]
|
|
||||||
})).filter(e => e.v).forEach(e => this.setFilter(e.k, e.v));
|
|
||||||
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.columnHasSlot = this.columns.map(e => Object.keys(this.$slots).includes(e));
|
|
||||||
this.columnHasData = this.columns.map(e => this.items.reduce((a, b) => a || b[e] !== undefined, false));
|
|
||||||
//console.log(this.columnHasData, this.columnHasSlot, this.columns, Object.keys(this.$slots), this.$slots);
|
|
||||||
for (let slot in this.$slots) {
|
|
||||||
console.log(`Slot: ${slot}`);
|
|
||||||
console.log(`Data: ${this.$slots[slot]}`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeUpdate() {
|
|
||||||
this.columnHasSlot = this.columns.map(e => Object.keys(this.$slots).includes(e));
|
|
||||||
this.columnHasData = this.columns.map(e => this.items.reduce((a, b) => a || b[e] !== undefined, false));
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
changeFilter(col, val) {
|
|
||||||
this.setFilter(col, val);
|
|
||||||
let newquery = Object.entries({
|
|
||||||
...this.$store.getters.getFilters,
|
|
||||||
[col]: val
|
|
||||||
}).reduce((a, [k, v]) => (v ? {...a, [k]: v} : a), {});
|
|
||||||
router.push({query: newquery});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.table-body-move {
|
|
||||||
transition: transform 1s;
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -1,48 +0,0 @@
|
||||||
<template>
|
|
||||||
<div class="toast" :class="color && ('border-' + color)" role="alert" ref="toast" data-autohide="false">
|
|
||||||
<div class="toast-header" :class="[color && ('bg-' + color), color && 'text-light']">
|
|
||||||
<strong class="mr-auto pr-3">{{ title }}</strong>
|
|
||||||
<small>{{ displayTime }}</small>
|
|
||||||
<button type="button" class="ml-2 mb-1 close" @click="close()">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<!--div class="toast-body" v-html="message">{{ message }}</div-->
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import $ from 'jquery';
|
|
||||||
import 'bootstrap/js/dist/toast';
|
|
||||||
import {DateTime} from 'luxon';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Toast',
|
|
||||||
props: ['title', 'message', 'color'],
|
|
||||||
data: () => ({
|
|
||||||
creationTime: DateTime.local(),
|
|
||||||
displayTime: 'just now',
|
|
||||||
timer: undefined
|
|
||||||
}),
|
|
||||||
mounted() {
|
|
||||||
const {toast} = this.$refs;
|
|
||||||
$(toast).toast('show');
|
|
||||||
this.timer = setInterval(this.updateDisplayTime, 1000);
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
close() {
|
|
||||||
const {toast} = this.$refs;
|
|
||||||
$(toast).toast('hide');
|
|
||||||
window.setTimeout(() => {
|
|
||||||
this.$emit('close');
|
|
||||||
}, 500);
|
|
||||||
},
|
|
||||||
updateDisplayTime() {
|
|
||||||
this.displayTime = this.creationTime.toRelative();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeDestroy() {
|
|
||||||
clearInterval(this.timer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
|
@ -1,112 +0,0 @@
|
||||||
<template>
|
|
||||||
<div contenteditable @input="onchange" ref="text">
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'FormatedText',
|
|
||||||
props: {
|
|
||||||
value: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
format: {
|
|
||||||
type: Function,
|
|
||||||
default: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
selection: {start: 0, end: 0, direction: 'forward', type: 'Caret'}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
emits: ['input'],
|
|
||||||
methods: {
|
|
||||||
rawhtml(value) {
|
|
||||||
if (typeof this.format === 'function') {
|
|
||||||
return this.format(value.replace(/ /g, ' '));
|
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onchange(event) {
|
|
||||||
const div = this.$refs.text;
|
|
||||||
const sel = window.getSelection();
|
|
||||||
if (sel.rangeCount > 0) {
|
|
||||||
this.selection.start = this.calculateOffset(div, sel.anchorNode, sel.anchorOffset);
|
|
||||||
this.selection.end = this.calculateOffset(div, sel.focusNode, sel.focusOffset);
|
|
||||||
this.selection.direction = sel.direction;
|
|
||||||
this.selection.type = sel.type;
|
|
||||||
}
|
|
||||||
this.$emit('input', event.target.innerText.replace(/ /g, ' ').replace(/\xA0/g, ' '));
|
|
||||||
},
|
|
||||||
calculateOffset(container, node, offset) {
|
|
||||||
let position = 0;
|
|
||||||
let found = false;
|
|
||||||
const walk = (elem) => {
|
|
||||||
if (elem === node) {
|
|
||||||
found = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (elem.nodeType === 3) {
|
|
||||||
position += elem.length;
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
||||||
walk(elem.childNodes[i]);
|
|
||||||
if (found) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
walk(container);
|
|
||||||
return position + offset;
|
|
||||||
},
|
|
||||||
findNode(container, offset) {
|
|
||||||
let position = 0;
|
|
||||||
let found = false;
|
|
||||||
let node = null;
|
|
||||||
const walk = (elem) => {
|
|
||||||
if (position + elem.length >= offset) {
|
|
||||||
found = true;
|
|
||||||
node = elem;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (elem.nodeType === 3) {
|
|
||||||
position += elem.length;
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
||||||
walk(elem.childNodes[i]);
|
|
||||||
if (found) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
walk(container);
|
|
||||||
return [node, offset - position]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
value() {
|
|
||||||
if (this.selection) {
|
|
||||||
const div = this.$refs.text;
|
|
||||||
div.innerHTML = this.rawhtml(this.value);
|
|
||||||
|
|
||||||
const range = document.createRange();
|
|
||||||
const sel = window.getSelection();
|
|
||||||
range.setStart(...this.findNode(div, this.selection.start));
|
|
||||||
range.setEnd(...this.findNode(div, this.selection.end));
|
|
||||||
|
|
||||||
sel.removeAllRanges();
|
|
||||||
sel.addRange(range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
const div = this.$refs.text;
|
|
||||||
div.innerHTML = this.rawhtml(this.value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
|
@ -1,4 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div class="form-group">
|
||||||
|
<label :for="label">{{ label }}</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<button
|
<button
|
||||||
|
@ -32,6 +34,7 @@
|
||||||
</div>
|
</div>
|
||||||
<Addon type="Combo Box" :is-valid="isValid"/>
|
<Addon type="Combo Box" :is-valid="isValid"/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {createApp} from 'vue'
|
import {createApp} from 'vue'
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import VueQrcode from '@chenfengyuan/vue-qrcode';
|
|
||||||
import store from './store';
|
import store from './store';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
|
|
||||||
|
@ -53,6 +52,5 @@ library.add(faPlus, faCheckCircle, faEdit, faTrash, faCat, faSyncAlt, faSort, fa
|
||||||
|
|
||||||
const app = createApp(App).use(store).use(router);
|
const app = createApp(App).use(store).use(router);
|
||||||
|
|
||||||
app.component(VueQrcode.name, VueQrcode);
|
|
||||||
app.component('font-awesome-icon', FontAwesomeIcon);
|
app.component('font-awesome-icon', FontAwesomeIcon);
|
||||||
app.mount('#app')
|
app.mount('#app')
|
|
@ -4,7 +4,6 @@ import store from '@/store';
|
||||||
import Items from './views/Items';
|
import Items from './views/Items';
|
||||||
import Boxes from './views/Boxes';
|
import Boxes from './views/Boxes';
|
||||||
import Files from './views/Files';
|
import Files from './views/Files';
|
||||||
import Error from './views/Error';
|
|
||||||
import HowTo from './views/HowTo';
|
import HowTo from './views/HowTo';
|
||||||
import Login from '@/views/Login.vue';
|
import Login from '@/views/Login.vue';
|
||||||
import Register from '@/views/Register.vue';
|
import Register from '@/views/Register.vue';
|
||||||
|
@ -14,12 +13,9 @@ import Ticket from "@/views/Ticket.vue";
|
||||||
import Admin from "@/views/admin/Admin.vue";
|
import Admin from "@/views/admin/Admin.vue";
|
||||||
import Empty from "@/views/Empty.vue";
|
import Empty from "@/views/Empty.vue";
|
||||||
import Events from "@/views/admin/Events.vue";
|
import Events from "@/views/admin/Events.vue";
|
||||||
import Settings from "@/views/admin/Settings.vue";
|
|
||||||
import AccessControl from "@/views/admin/AccessControl.vue";
|
import AccessControl from "@/views/admin/AccessControl.vue";
|
||||||
import {default as BoxesAdmin} from "@/views/admin/Boxes.vue"
|
import {default as BoxesAdmin} from "@/views/admin/Boxes.vue"
|
||||||
import Shipping from "@/views/admin/Shipping.vue";
|
import Shipping from "@/views/admin/Shipping.vue";
|
||||||
import Item from "@/views/Item.vue";
|
|
||||||
import Notifications from "@/views/admin/Notifications.vue";
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{path: '/', redirect: '/37C3/items', meta: {requiresAuth: false}},
|
{path: '/', redirect: '/37C3/items', meta: {requiresAuth: false}},
|
||||||
|
@ -31,7 +27,7 @@ const routes = [
|
||||||
{requiresAuth: true, requiresPermission: 'view_item'}
|
{requiresAuth: true, requiresPermission: 'view_item'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:event/item/:id/', name: 'item', component: Item, meta:
|
path: '/:event/item/:uid/', name: 'item', component: Items, meta:
|
||||||
{requiresAuth: true, requiresPermission: 'view_item'}
|
{requiresAuth: true, requiresPermission: 'view_item'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -62,10 +58,6 @@ const routes = [
|
||||||
path: 'events/', name: 'events', component: Events, meta:
|
path: 'events/', name: 'events', component: Events, meta:
|
||||||
{requiresAuth: true, requiresPermission: 'delete_event'}
|
{requiresAuth: true, requiresPermission: 'delete_event'}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: 'settings/', name: 'settings', component: Settings, meta:
|
|
||||||
{requiresAuth: true, requiresPermission: 'delete_event'}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '', name: 'admin', component: Dashboard, meta:
|
path: '', name: 'admin', component: Dashboard, meta:
|
||||||
{requiresAuth: true, requiresPermission: 'delete_event'}
|
{requiresAuth: true, requiresPermission: 'delete_event'}
|
||||||
|
@ -82,14 +74,9 @@ const routes = [
|
||||||
path: 'shipping/', name: 'shipping', component: Shipping, meta:
|
path: 'shipping/', name: 'shipping', component: Shipping, meta:
|
||||||
{requiresAuth: true, requiresPermission: 'delete_event'}
|
{requiresAuth: true, requiresPermission: 'delete_event'}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: 'notifications/', name: 'notifications', component: Notifications, meta:
|
|
||||||
{requiresAuth: true, requiresPermission: 'delete_event'}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{path: '/user', name: 'user', component: Empty, meta: {requiresAuth: true}},
|
{path: '/user', name: 'user', component: Empty, meta: {requiresAuth: true}},
|
||||||
//{path: '*', component: Error},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
@ -123,4 +110,3 @@ router.afterEach((to, from) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
|
120
web/src/store.js
120
web/src/store.js
|
@ -17,10 +17,7 @@ const store = createStore({
|
||||||
users: [],
|
users: [],
|
||||||
groups: [],
|
groups: [],
|
||||||
state_options: [],
|
state_options: [],
|
||||||
messageTemplates: [],
|
|
||||||
messageTemplateVariables: [],
|
|
||||||
shippingVouchers: [],
|
shippingVouchers: [],
|
||||||
userNotificationChannels: [],
|
|
||||||
|
|
||||||
loadedItems: {},
|
loadedItems: {},
|
||||||
loadedTickets: {},
|
loadedTickets: {},
|
||||||
|
@ -46,9 +43,7 @@ const store = createStore({
|
||||||
users: 0,
|
users: 0,
|
||||||
groups: 0,
|
groups: 0,
|
||||||
states: 0,
|
states: 0,
|
||||||
messageTemplates: 0,
|
|
||||||
shippingVouchers: 0,
|
shippingVouchers: 0,
|
||||||
userNotificationChannels: 0,
|
|
||||||
},
|
},
|
||||||
persistent_loaded: false,
|
persistent_loaded: false,
|
||||||
shared_loaded: false,
|
shared_loaded: false,
|
||||||
|
@ -56,7 +51,6 @@ const store = createStore({
|
||||||
|
|
||||||
showAddBoxModal: false,
|
showAddBoxModal: false,
|
||||||
showAddEventModal: false,
|
showAddEventModal: false,
|
||||||
test: ['foo', 'bar', 'baz'],
|
|
||||||
|
|
||||||
shippingVoucherTypes: {
|
shippingVoucherTypes: {
|
||||||
'2kg-de': '2kg Paket (DE)',
|
'2kg-de': '2kg Paket (DE)',
|
||||||
|
@ -151,34 +145,38 @@ const store = createStore({
|
||||||
setItems(state, {slug, items}) {
|
setItems(state, {slug, items}) {
|
||||||
state.loadedItems[slug] = items;
|
state.loadedItems[slug] = items;
|
||||||
state.loadedItems = {...state.loadedItems};
|
state.loadedItems = {...state.loadedItems};
|
||||||
|
console.log(state.loadedItems)
|
||||||
},
|
},
|
||||||
replaceItems(state, items) {
|
replaceItems(state, items) {
|
||||||
const groups = Object.groupBy(items, i => i.event ? i.event : 'none')
|
const groups = Object.groupBy(items, i => i.event ? i.event : 'none')
|
||||||
for (const [key, value] of Object.entries(groups)) state.loadedItems[key] = value;
|
for (const [key, value] of Object.entries(groups)) state.loadedItems[key] = value;
|
||||||
state.loadedItems = {...state.loadedItems};
|
state.loadedItems = {...state.loadedItems};
|
||||||
|
console.log(state.loadedItems)
|
||||||
},
|
},
|
||||||
updateItem(state, updatedItem) {
|
updateItem(state, updatedItem) {
|
||||||
const item = state.loadedItems[updatedItem.event ? updatedItem.event : 'none'].filter(
|
const item = state.loadedItems[updatedItem.event?updatedItem.event:'none'].filter(
|
||||||
({uid}) => uid === updatedItem.uid)[0];
|
({uid}) => uid === updatedItem.uid)[0];
|
||||||
Object.assign(item, updatedItem);
|
Object.assign(item, updatedItem);
|
||||||
},
|
},
|
||||||
removeItem(state, item) {
|
removeItem(state, item) {
|
||||||
state.loadedItems[item.event ? item.event : 'none'] = state.loadedItems[item.event].filter(it => it !== item);
|
state.loadedItems[item.event?item.event:'none'] = state.loadedItems[item.event].filter(it => it !== item);
|
||||||
},
|
},
|
||||||
appendItem(state, item) {
|
appendItem(state, item) {
|
||||||
state.loadedItems[item.event ? item.event : 'none'].push(item);
|
state.loadedItems[item.event?item.event:'none'].push(item);
|
||||||
},
|
},
|
||||||
setTickets(state, {slug, tickets}) {
|
setTickets(state, {slug, tickets}) {
|
||||||
state.loadedTickets[slug] = tickets;
|
state.loadedTickets[slug] = tickets;
|
||||||
state.loadedTickets = {...state.loadedTickets};
|
state.loadedTickets = {...state.loadedTickets};
|
||||||
|
console.log(state.loadedTickets)
|
||||||
},
|
},
|
||||||
replaceTickets(state, tickets) {
|
replaceTickets(state, tickets) {
|
||||||
const groups = Object.groupBy(tickets, t => t.event ? t.event : 'none')
|
const groups = Object.groupBy(tickets, t => t.event ? t.event : 'none')
|
||||||
for (const [key, value] of Object.entries(groups)) state.loadedTickets[key] = value;
|
for (const [key, value] of Object.entries(groups)) state.loadedTickets[key] = value;
|
||||||
state.loadedTickets = {...state.loadedTickets};
|
state.loadedTickets = {...state.loadedTickets};
|
||||||
|
console.log(state.loadedTickets)
|
||||||
},
|
},
|
||||||
updateTicket(state, updatedTicket) {
|
updateTicket(state, updatedTicket) {
|
||||||
const ticket = state.loadedTickets[updatedTicket.event ? updatedTicket.event : 'none'].filter(
|
const ticket = state.loadedTickets[updatedTicket.event?updatedTicket.event:'none'].filter(
|
||||||
({id}) => id === updatedTicket.id)[0];
|
({id}) => id === updatedTicket.id)[0];
|
||||||
Object.assign(ticket, updatedTicket);
|
Object.assign(ticket, updatedTicket);
|
||||||
state.loadedTickets = {...state.loadedTickets};
|
state.loadedTickets = {...state.loadedTickets};
|
||||||
|
@ -242,27 +240,13 @@ const store = createStore({
|
||||||
user.permissions = null;
|
user.permissions = null;
|
||||||
state.user = user;
|
state.user = user;
|
||||||
},
|
},
|
||||||
setTest(state, test) {
|
|
||||||
state.test = test;
|
|
||||||
},
|
|
||||||
setThumbnail(state, {url, data}) {
|
setThumbnail(state, {url, data}) {
|
||||||
state.thumbnailCache[url] = data;
|
state.thumbnailCache[url] = data;
|
||||||
},
|
},
|
||||||
setMessageTemplates(state, templates) {
|
|
||||||
state.messageTemplates = templates;
|
|
||||||
state.fetchedData = {...state.fetchedData, messageTemplates: Date.now()};
|
|
||||||
},
|
|
||||||
setMessageTemplateVariables(state, variables) {
|
|
||||||
state.messageTemplateVariables = variables;
|
|
||||||
},
|
|
||||||
setShippingVouchers(state, codes) {
|
setShippingVouchers(state, codes) {
|
||||||
state.shippingVouchers = codes;
|
state.shippingVouchers = codes;
|
||||||
state.fetchedData = {...state.fetchedData, shippingVouchers: Date.now()};
|
state.fetchedData = {...state.fetchedData, shippingVouchers: Date.now()};
|
||||||
},
|
},
|
||||||
setUserNotificationChannels(state, channels) {
|
|
||||||
state.userNotificationChannels = channels;
|
|
||||||
state.fetchedData = {...state.fetchedData, userNotificationChannels: Date.now()};
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async login({commit}, {username, password, remember}) {
|
async login({commit}, {username, password, remember}) {
|
||||||
|
@ -493,39 +477,6 @@ const store = createStore({
|
||||||
const {data, success} = await getters.session.patch(`/2/tickets/${id}/`, ticket);
|
const {data, success} = await getters.session.patch(`/2/tickets/${id}/`, ticket);
|
||||||
commit('updateTicket', data);
|
commit('updateTicket', data);
|
||||||
},
|
},
|
||||||
async fetchMessageTemplates({commit, state}) {
|
|
||||||
if (!state.user.token) return;
|
|
||||||
if (state.messageTemplates.length > 0) return;
|
|
||||||
const {data, success} = await http.get('/2/message_templates/', state.user.token);
|
|
||||||
if (data && success) {
|
|
||||||
commit('setMessageTemplates', data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async updateMessageTemplate({dispatch, state}, template) {
|
|
||||||
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
|
|
||||||
{'message': template.message}, state.user.token);
|
|
||||||
if (data && success) {
|
|
||||||
state.fetchedData.messageTemplates = 0;
|
|
||||||
dispatch('fetchMessageTemplates');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchMessageTemplateVariables({commit, state}) {
|
|
||||||
if (!state.user.token) return;
|
|
||||||
if (state.messageTemplateVariables.length > 0) return;
|
|
||||||
const {data, success} = await http.get('/2/message_template_variables/', state.user.token);
|
|
||||||
if (data && success) {
|
|
||||||
commit('setMessageTemplateVariables', data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async createMessageTemplate({dispatch, state}, template_name) {
|
|
||||||
const {data, success} = await http.post('/2/message_templates/', {
|
|
||||||
name: template_name,
|
|
||||||
message: '-'
|
|
||||||
}, state.user.token);
|
|
||||||
if (data && success) {
|
|
||||||
dispatch('fetchMessageTemplates');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchShippingVouchers({commit, state, getters}) {
|
async fetchShippingVouchers({commit, state, getters}) {
|
||||||
if (!state.user.token) return;
|
if (!state.user.token) return;
|
||||||
if (state.fetchedData.shippingVouchers > Date.now() - 1000 * 60 * 60 * 24) return;
|
if (state.fetchedData.shippingVouchers > Date.now() - 1000 * 60 * 60 * 24) return;
|
||||||
|
@ -549,64 +500,23 @@ const store = createStore({
|
||||||
state.fetchedData.tickets = 0;
|
state.fetchedData.tickets = 0;
|
||||||
await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]);
|
await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
async fetchUserNotificationChannels({commit, state}) {
|
|
||||||
if (!state.user.token) return;
|
|
||||||
if (state.fetchedData.userNotificationChannels > Date.now() - 1000 * 60 * 60 * 24) return;
|
|
||||||
const {data, success} = await http.get('/2/user_notification_channels/', state.user.token);
|
|
||||||
if (data && success) {
|
|
||||||
commit('setUserNotificationChannels', data);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
plugins: [persistentStatePlugin({ // TODO change remember to some kind of enable field
|
||||||
plugins: [
|
|
||||||
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
|
||||||
prefix: "lf_",
|
prefix: "lf_",
|
||||||
debug: false,
|
debug: false,
|
||||||
isLoadedKey: "persistent_loaded",
|
isLoadedKey: "persistent_loaded",
|
||||||
state: [
|
state: ["remember", "user", "events", "lastUsed",]
|
||||||
"remember",
|
}), sharedStatePlugin({
|
||||||
"user",
|
|
||||||
"events",
|
|
||||||
"lastUsed",
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
sharedStatePlugin({
|
|
||||||
debug: false,
|
debug: false,
|
||||||
isLoadedKey: "shared_loaded",
|
isLoadedKey: "shared_loaded",
|
||||||
clearingMutation: "logout",
|
clearingMutation: "logout",
|
||||||
afterInit: "afterSharedInit",
|
afterInit: "afterSharedInit",
|
||||||
state: [
|
state: ["test", "state_options", "fetchedData", "loadedItems", "users", "groups", "loadedBoxes", "loadedTickets", "shippingVouchers",],
|
||||||
"test",
|
watch: ["test", "state_options", "fetchedData", "loadedItems", "users", "groups", "loadedBoxes", "loadedTickets", "shippingVouchers",],
|
||||||
"state_options",
|
mutations: [//"replaceTickets",
|
||||||
"fetchedData",
|
|
||||||
"loadedItems",
|
|
||||||
"users",
|
|
||||||
"groups",
|
|
||||||
"loadedBoxes",
|
|
||||||
"loadedTickets",
|
|
||||||
"messageTemplates",
|
|
||||||
"messageTemplatesVariables",
|
|
||||||
"shippingVouchers",
|
|
||||||
],
|
|
||||||
watch: [
|
|
||||||
"test",
|
|
||||||
"state_options",
|
|
||||||
"fetchedData",
|
|
||||||
"loadedItems",
|
|
||||||
"users",
|
|
||||||
"groups",
|
|
||||||
"loadedBoxes",
|
|
||||||
"loadedTickets",
|
|
||||||
"messageTemplates",
|
|
||||||
"messageTemplatesVariables",
|
|
||||||
"shippingVouchers",
|
|
||||||
],
|
|
||||||
mutations: [
|
|
||||||
//"replaceTickets",
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
|
}),],
|
||||||
});
|
});
|
||||||
|
|
||||||
store.watch((state) => state.user, (user) => {
|
store.watch((state) => state.user, (user) => {
|
||||||
|
|
|
@ -1,134 +0,0 @@
|
||||||
<template>
|
|
||||||
<AsyncLoader :loaded="!!item.id">
|
|
||||||
<div class="container-fluid px-xl-5 mt-3">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xl-8 offset-xl-2">
|
|
||||||
<div class="card bg-dark text-light mb-2" id="filters">
|
|
||||||
<div class="card-header">
|
|
||||||
<h3>Item #{{ item.id }} - {{ item.description }}</h3>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{{ item }}
|
|
||||||
</div>
|
|
||||||
<ItemTimeline :timeline="item.timeline" @sendMail="handleMail" @addComment="handleComment"/>
|
|
||||||
<div class="card-footer d-flex justify-content-between">
|
|
||||||
<button class="btn btn-secondary mr-2" @click="$router.go(-1)">Back</button>
|
|
||||||
<div class="btn-group">
|
|
||||||
<button class="btn btn-outline-success"
|
|
||||||
@click.stop="confirm('return Item?') && markItemReturned(item)"
|
|
||||||
title="returned">
|
|
||||||
<font-awesome-icon icon="check"/>
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-outline-secondary" @click.stop="openEditingModalWith(item)"
|
|
||||||
title="edit">
|
|
||||||
<font-awesome-icon icon="edit"/>
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-outline-danger"
|
|
||||||
@click.stop="confirm('delete Item?') && deleteItem(item)"
|
|
||||||
title="delete">
|
|
||||||
<font-awesome-icon icon="trash"/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<InputCombo
|
|
||||||
label="box"
|
|
||||||
:model="item"
|
|
||||||
nameKey="box"
|
|
||||||
uniqueKey="cid"
|
|
||||||
:options="boxes"
|
|
||||||
/>
|
|
||||||
<div class="btn-group">
|
|
||||||
<select class="form-control" v-model="selected_state">
|
|
||||||
<option v-for="status in state_options" :value="status.value">{{
|
|
||||||
status.text
|
|
||||||
}}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
<button class="form-control btn btn-success"
|
|
||||||
@click="changeTicketStatus(item)"
|
|
||||||
:disabled="(selected_state == item.state)">
|
|
||||||
Change Status
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AsyncLoader>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {mapActions, mapGetters, mapState} from 'vuex';
|
|
||||||
import ItemTimeline from "@/components/ItemTimeline.vue";
|
|
||||||
import ClipboardButton from "@/components/inputs/ClipboardButton.vue";
|
|
||||||
import AsyncLoader from "@/components/AsyncLoader.vue";
|
|
||||||
import InputCombo from "@/components/inputs/InputCombo.vue";
|
|
||||||
import InputString from "@/components/inputs/InputString.vue";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Item',
|
|
||||||
components: {InputString, InputCombo, AsyncLoader, ClipboardButton, ItemTimeline},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
selected_state: null,
|
|
||||||
selected_assignee: null,
|
|
||||||
shipping_voucher_type: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState(['state_options', 'users']),
|
|
||||||
...mapGetters(['availableShippingVoucherTypes', 'getAllItems', 'route', 'getBoxes']),
|
|
||||||
item() {
|
|
||||||
const id = parseInt(this.route.params.id)
|
|
||||||
const ret = this.getAllItems.find(item => item.id === id);
|
|
||||||
return ret ? ret : {};
|
|
||||||
},
|
|
||||||
boxes() {
|
|
||||||
console.log(this.getBoxes);
|
|
||||||
return this.getBoxes.map(obj => ({cid: obj.cid, box: obj.name}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
...mapActions(['deleteItem', 'markItemReturned', 'sendMail', 'updateTicketPartial', 'postComment']),
|
|
||||||
...mapActions(['loadTickets', 'fetchTicketStates', 'loadUsers', 'scheduleAfterInit']),
|
|
||||||
...mapActions(['claimShippingVoucher', 'fetchShippingVouchers', 'loadEventItems', 'loadBoxes']),
|
|
||||||
handleMail(mail) {
|
|
||||||
this.sendMail({
|
|
||||||
id: this.item.id,
|
|
||||||
message: mail
|
|
||||||
})
|
|
||||||
},
|
|
||||||
handleComment(comment) {
|
|
||||||
this.postComment({
|
|
||||||
id: this.item.id,
|
|
||||||
message: comment
|
|
||||||
})
|
|
||||||
},
|
|
||||||
changeTicketStatus(item) {
|
|
||||||
item.state = this.selected_state;
|
|
||||||
this.updateTicketPartial({
|
|
||||||
id: item.id,
|
|
||||||
state: this.selected_state,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
//assignTicket(item) {
|
|
||||||
// item.assigned_to = this.selected_assignee;
|
|
||||||
// this.updateTicketPartial({
|
|
||||||
// id: item.id,
|
|
||||||
// assigned_to: this.selected_assignee
|
|
||||||
// })
|
|
||||||
//},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.scheduleAfterInit(() => [Promise.all([this.loadEventItems(), this.loadBoxes()]).then(() => {
|
|
||||||
this.selected_state = this.item.state;
|
|
||||||
this.selected_assignee = this.item.assigned_to
|
|
||||||
})]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
|
@ -20,7 +20,7 @@
|
||||||
:columns="['uid', 'description', 'box']"
|
:columns="['uid', 'description', 'box']"
|
||||||
:items="getEventItems"
|
:items="getEventItems"
|
||||||
:keyName="'uid'"
|
:keyName="'uid'"
|
||||||
@itemActivated="showItemDetail"
|
@itemActivated="openLightboxModalWith($event)"
|
||||||
>
|
>
|
||||||
<template #actions="{ item }">
|
<template #actions="{ item }">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
:items="getEventItems"
|
:items="getEventItems"
|
||||||
:keyName="'uid'"
|
:keyName="'uid'"
|
||||||
v-slot="{ item }"
|
v-slot="{ item }"
|
||||||
@itemActivated="showItemDetail"
|
@itemActivated="openLightboxModalWith($event)"
|
||||||
>
|
>
|
||||||
<AuthenticatedImage v-if="item.file" cached
|
<AuthenticatedImage v-if="item.file" cached
|
||||||
:src="`/media/2/256/${item.file}/`"
|
:src="`/media/2/256/${item.file}/`"
|
||||||
|
@ -88,7 +88,6 @@ import {mapActions, mapGetters, mapState} from 'vuex';
|
||||||
import Lightbox from '../components/Lightbox';
|
import Lightbox from '../components/Lightbox';
|
||||||
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
|
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
|
||||||
import AsyncLoader from "@/components/AsyncLoader.vue";
|
import AsyncLoader from "@/components/AsyncLoader.vue";
|
||||||
import router from "@/router";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Items',
|
name: 'Items',
|
||||||
|
@ -103,9 +102,6 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['deleteItem', 'markItemReturned', 'loadEventItems', 'updateItem', 'scheduleAfterInit']),
|
...mapActions(['deleteItem', 'markItemReturned', 'loadEventItems', 'updateItem', 'scheduleAfterInit']),
|
||||||
showItemDetail(item) {
|
|
||||||
router.push({name: 'item', params: {id: item.id}});
|
|
||||||
},
|
|
||||||
openLightboxModalWith(item) {
|
openLightboxModalWith(item) {
|
||||||
this.lightboxHash = item.file;
|
this.lightboxHash = item.file;
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
<div class="container-fluid px-xl-5 mt-3">
|
<div class="container-fluid px-xl-5 mt-3">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-8 offset-xl-2">
|
<div class="col-xl-8 offset-xl-2">
|
||||||
<SlotTable
|
<Table
|
||||||
:columns="['id', 'name', 'state', 'last_activity', 'assigned_to',
|
:columns="['id', 'name', 'state', 'last_activity', 'assigned_to',
|
||||||
...(getEventSlug==='all'?['event']:[]), 'actions', 'actions2']"
|
...(getEventSlug==='all'?['event']:[])]"
|
||||||
:items="getEventTickets.map(formatTicket)"
|
:items="getEventTickets.map(formatTicket)"
|
||||||
:keyName="'id'"
|
:keyName="'id'"
|
||||||
v-if="layout === 'table'"
|
v-if="layout === 'table'"
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</SlotTable>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<CollapsableCards v-if="layout === 'tasks'" :items="getEventTickets"
|
<CollapsableCards v-if="layout === 'tasks'" :items="getEventTickets"
|
||||||
|
@ -59,13 +59,13 @@ import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
import EditItem from '@/components/EditItem';
|
||||||
import {mapActions, mapGetters, mapState} from 'vuex';
|
import {mapActions, mapGetters, mapState} from 'vuex';
|
||||||
import Lightbox from '../components/Lightbox';
|
import Lightbox from '../components/Lightbox';
|
||||||
import SlotTable from "@/components/SlotTable.vue";
|
import Table from '@/components/Table';
|
||||||
import CollapsableCards from "@/components/CollapsableCards.vue";
|
import CollapsableCards from "@/components/CollapsableCards.vue";
|
||||||
import AsyncLoader from "@/components/AsyncLoader.vue";
|
import AsyncLoader from "@/components/AsyncLoader.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Tickets',
|
name: 'Tickets',
|
||||||
components: {AsyncLoader, Lightbox, SlotTable, Cards, Modal, EditItem, CollapsableCards},
|
components: {AsyncLoader, Lightbox, Table, Cards, Modal, EditItem, CollapsableCards},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['getEventTickets', 'isTicketsLoaded', 'stateInfo', 'getEventSlug', 'layout']),
|
...mapGetters(['getEventTickets', 'isTicketsLoaded', 'stateInfo', 'getEventSlug', 'layout']),
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,15 +8,9 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<router-link class="nav-link" :to="{name: 'admin'}" active-class="dummy" exact-active-class="active">Dashboard</router-link>
|
<router-link class="nav-link" :to="{name: 'admin'}" active-class="dummy" exact-active-class="active">Dashboard</router-link>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<router-link class="nav-link" :to="{name: 'settings'}" active-class="active">Settings</router-link>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<router-link class="nav-link" :to="{name: 'events'}" active-class="active">Events</router-link>
|
<router-link class="nav-link" :to="{name: 'events'}" active-class="active">Events</router-link>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<router-link class="nav-link" :to="{name: 'notifications'}" active-class="active">Notifications</router-link>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<router-link class="nav-link" :to="{name: 'shipping'}" active-class="active">Shipping</router-link>
|
<router-link class="nav-link" :to="{name: 'shipping'}" active-class="active">Shipping</router-link>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<button class="btn btn-primary" @click="addTest('test')">+</button>
|
|
||||||
</li>
|
|
||||||
<li v-for="(t, index) in test" :key="index">
|
|
||||||
{{ t }}
|
|
||||||
<button class="btn btn-link" @click="removeTest(index)">-</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<vue-qrcode :value="qr_url" tag="svg" :size="200" :options="{errorCorrectionLevel: 'H'}"></vue-qrcode>
|
|
||||||
<!--qr-code :text="" color="#000" bg-color="#fff" error-level="H" ></qr-code-->
|
|
||||||
<h3 class="text-center">Events</h3>
|
|
||||||
<!--p>{{ events }}</p-->
|
|
||||||
<span>{{ events.length }} loaded events</span>
|
|
||||||
<ul class="hidden">
|
|
||||||
<li v-for="event in events" :key="event.id">
|
|
||||||
{{ event.slug }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<h3 class="text-center">Items</h3>
|
|
||||||
<!--p>{{ loadedItems }}</p-->
|
|
||||||
<span>{{ loadedItems.length }} loaded items</span>
|
|
||||||
<ul class="hidden">
|
|
||||||
<li v-for="item in loadedItems" :key="item.id">
|
|
||||||
{{ item.description }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<h3 class="text-center">Boxes</h3>
|
|
||||||
<!--p>{{ loadedBoxes }}</p-->
|
|
||||||
<span>{{ loadedBoxes.length }} loaded boxes</span>
|
|
||||||
<ul class="hidden">
|
|
||||||
<li v-for="box in loadedBoxes" :key="box.id">
|
|
||||||
{{ box.name }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<h3 class="text-center">Issues</h3>
|
|
||||||
<!--p>{{ issues }}</p-->
|
|
||||||
<ul>
|
|
||||||
<li v-for="issue in tickets" :key="issue.id">
|
|
||||||
{{ issue.id }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {mapActions, mapMutations, mapState} from 'vuex';
|
|
||||||
import Table from '@/components/Table';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Debug',
|
|
||||||
components: {Table},
|
|
||||||
computed: {
|
|
||||||
...mapState(['events', 'loadedItems', 'loadedBoxes', 'tickets']),
|
|
||||||
...mapState(['events', 'loadedItems', 'loadedBoxes']),//, 'mails', 'issues', 'systemEvents']),
|
|
||||||
...mapState(['test']),
|
|
||||||
qr_url() {
|
|
||||||
return window.location.href;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
...mapActions(['changeEvent', 'loadTickets']),
|
|
||||||
|
|
||||||
...mapActions(['changeEvent']),//, 'loadMails', 'loadIssues', 'loadSystemEvents']),
|
|
||||||
...mapMutations(['setTest']),
|
|
||||||
addTest(test) {
|
|
||||||
const tests = [...this.test, test];
|
|
||||||
this.setTest(tests);
|
|
||||||
},
|
|
||||||
removeTest(index) {
|
|
||||||
const tests = [...this.test];
|
|
||||||
tests.splice(index, 1);
|
|
||||||
this.setTest(tests);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.loadTickets();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
</style>
|
|
|
@ -1,53 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<Table :items="userNotificationChannels.map(channel => ({...channel, username: channel.user.username || {}}))"
|
|
||||||
:columns="['id', 'username', 'channel_type', 'channel_target', 'event_filter', /*'active', 'created'*/]">
|
|
||||||
<template #actions="{ item }">
|
|
||||||
<div class="btn-group">
|
|
||||||
<button class="btn btn-danger" @click.stop="">
|
|
||||||
<font-awesome-icon icon="trash"/>
|
|
||||||
delete
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</Table>
|
|
||||||
<div class="card bg-dark">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="input-group">
|
|
||||||
<select class="form-control">
|
|
||||||
<option value="1">user</option>
|
|
||||||
<option value="2">admin</option>
|
|
||||||
</select>
|
|
||||||
<select class="form-control">
|
|
||||||
<option value="email">Email</option>
|
|
||||||
<option value="telegram">Telegram</option>
|
|
||||||
</select>
|
|
||||||
<input type="text" class="form-control" placeholder="channel_target">
|
|
||||||
<input type="text" class="form-control" value="*">
|
|
||||||
<div class="input-group-append">
|
|
||||||
<button class="btn btn-primary">Add</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {mapActions, mapState} from 'vuex';
|
|
||||||
import Table from '@/components/Table';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Notifications',
|
|
||||||
components: {Table},
|
|
||||||
computed: mapState(['userNotificationChannels']),
|
|
||||||
methods: mapActions(['fetchUserNotificationChannels']),
|
|
||||||
mounted() {
|
|
||||||
this.fetchUserNotificationChannels();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
|
@ -1,109 +0,0 @@
|
||||||
<template>
|
|
||||||
<h3 class="text-center">Available Message Template Variables</h3>
|
|
||||||
<p>
|
|
||||||
<span v-for="(variable, key) in messageTemplateVariables" :key="key" class="badge badge-primary"
|
|
||||||
style="margin: 5px;">
|
|
||||||
{{ variable }}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
<h3 class="text-center">Message Templates</h3>
|
|
||||||
<div v-for="template in messageTemplatesIntermediate" :key="template.id" class="card bg-dark"
|
|
||||||
style="margin-bottom: 10px;">
|
|
||||||
<div class="card-header">{{ template.name }}</div>
|
|
||||||
<FormatedText :value="template.message" :format="formatText" class="card-body"
|
|
||||||
@input="changeMessageTemplate(template.id, $event)"/>
|
|
||||||
<div class="card-body">
|
|
||||||
<button class="btn btn-primary" @click="resetMessageTemplate(template.id)"
|
|
||||||
:disabled="messageTemplates.find(t => t.id === template.id).message === template.message">Reset
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-success" @click="saveMessageTemplate(template.id)"
|
|
||||||
:disabled="messageTemplates.find(t => t.id === template.id).message === template.message">Save
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card bg-dark">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" class="form-control" v-model="newTemplateName" placeholder="New Template Name">
|
|
||||||
<button class="btn btn-success input-group-btn" @click="createMessageTemplateAndReset()"
|
|
||||||
ref="createButton">Create
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {mapActions, mapState} from 'vuex';
|
|
||||||
import Table from '@/components/Table';
|
|
||||||
import FormatedText from "@/components/inputs/FormatedText.vue";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Settings',
|
|
||||||
components: {FormatedText, Table},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
messageTemplatesIntermediate: [],
|
|
||||||
newTemplateName: '',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: mapState(['messageTemplates', 'messageTemplateVariables']),
|
|
||||||
methods: {
|
|
||||||
...mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables', 'updateMessageTemplate', 'createMessageTemplate']),
|
|
||||||
formatText(value) {
|
|
||||||
return value.replace(/{{(.+?)}}/g, (match, key) => {
|
|
||||||
return `<span class="text-primary">{{${key}}}</span>`;
|
|
||||||
}).replace(/\n/g, '<br>').replace(/\t/g, ' ');
|
|
||||||
},
|
|
||||||
changeMessageTemplate(id, message) {
|
|
||||||
console.log(id, message);
|
|
||||||
this.messageTemplatesIntermediate.forEach(template => {
|
|
||||||
if (template.id === id) {
|
|
||||||
template.message = message;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveMessageTemplate(id) {
|
|
||||||
this.updateMessageTemplate(this.messageTemplatesIntermediate.find(template => template.id === id));
|
|
||||||
},
|
|
||||||
resetMessageTemplate(id) {
|
|
||||||
this.messageTemplatesIntermediate.find(template => template.id === id).message =
|
|
||||||
this.messageTemplates.find(template => template.id === id).message;
|
|
||||||
},
|
|
||||||
async createMessageTemplateAndReset() {
|
|
||||||
this.$refs.createButton.disabled = true;
|
|
||||||
await this.createMessageTemplate(this.newTemplateName);
|
|
||||||
this.newTemplateName = '';
|
|
||||||
this.$refs.createButton.disabled = false;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.fetchMessageTemplates().then(() => {
|
|
||||||
this.messageTemplatesIntermediate = JSON.parse(JSON.stringify(this.messageTemplates));
|
|
||||||
});
|
|
||||||
this.fetchMessageTemplateVariables();
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
messageTemplates() {
|
|
||||||
for (const template of this.messageTemplates) {
|
|
||||||
if (!this.messageTemplatesIntermediate.find(t => t.id === template.id)) {
|
|
||||||
this.messageTemplatesIntermediate.push(JSON.parse(JSON.stringify(template)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const template of this.messageTemplatesIntermediate) {
|
|
||||||
if (!this.messageTemplates.find(t => t.id === template.id)) {
|
|
||||||
this.messageTemplatesIntermediate = this.messageTemplatesIntermediate.filter(t => t.id !== template.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
pre {
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-wrap: break-word;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
</style>
|
|
Loading…
Reference in a new issue