use standalone mail server #108
19 changed files with 321 additions and 121 deletions
|
@ -35,7 +35,7 @@ jobs:
|
||||||
|
|
||||||
- name: Populate relevant files
|
- name: Populate relevant files
|
||||||
run: |
|
run: |
|
||||||
mkdir ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.C3LF_SSH_TESTING }}" > ~/.ssh/id_ed25519
|
echo "${{ secrets.C3LF_SSH_TESTING }}" > ~/.ssh/id_ed25519
|
||||||
chmod 0600 ~/.ssh/id_ed25519
|
chmod 0600 ~/.ssh/id_ed25519
|
||||||
ls -lah ~/.ssh
|
ls -lah ~/.ssh
|
||||||
|
@ -43,7 +43,7 @@ jobs:
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add ~/.ssh/id_ed25519
|
ssh-add ~/.ssh/id_ed25519
|
||||||
echo "andromeda.lab.or.it ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXPoO0PE+B9PYwbGaLo98zhbmjAkp6eBtVeZe43v/+T" >> ~/.ssh/known_hosts
|
echo "andromeda.lab.or.it ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXPoO0PE+B9PYwbGaLo98zhbmjAkp6eBtVeZe43v/+T" >> ~/.ssh/known_hosts
|
||||||
mkdir /etc/ansible
|
mkdir -p /etc/ansible
|
||||||
echo "${{ secrets.C3LF_INVENTORY_TESTING }}" > /etc/ansible/hosts
|
echo "${{ secrets.C3LF_INVENTORY_TESTING }}" > /etc/ansible/hosts
|
||||||
|
|
||||||
- name: Check ansible version
|
- name: Check ansible version
|
||||||
|
|
35
core/core/metrics.py
Normal file
35
core/core/metrics.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
from django.apps import apps
|
||||||
|
from prometheus_client.core import CounterMetricFamily, REGISTRY
|
||||||
|
from django.db.models import Case, Value, When, BooleanField, Count
|
||||||
|
from inventory.models import Item
|
||||||
|
|
||||||
|
class ItemCountCollector(object):
|
||||||
|
|
||||||
|
def collect(self):
|
||||||
|
counter = CounterMetricFamily("item_count", "Current number of items", labels=['event', 'returned_state'])
|
||||||
|
|
||||||
|
yield counter
|
||||||
|
|
||||||
|
if not apps.models_ready or not apps.apps_ready:
|
||||||
|
return
|
||||||
|
|
||||||
|
queryset = (
|
||||||
|
Item.all_objects
|
||||||
|
.annotate(
|
||||||
|
returned=Case(
|
||||||
|
When(returned_at__isnull=False, then=Value(False)),
|
||||||
|
default=Value(True),
|
||||||
|
output_field=BooleanField()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.values('event__slug', 'returned', 'event_id')
|
||||||
|
.annotate(amount=Count('id'))
|
||||||
|
.order_by('event__slug', 'returned') # Optional: order by slug and returned
|
||||||
|
)
|
||||||
|
|
||||||
|
for e in queryset:
|
||||||
|
counter.add_metric([e["event__slug"].lower(), str(e["returned"])], e["amount"])
|
||||||
|
|
||||||
|
yield counter
|
||||||
|
|
||||||
|
REGISTRY.register(ItemCountCollector())
|
|
@ -124,19 +124,12 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'core.wsgi.application'
|
ASGI_APPLICATION = 'core.asgi.application'
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||||
|
|
||||||
if 'test' in sys.argv:
|
if os.getenv('DB_HOST') is not None:
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': ':memory:',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
@ -149,6 +142,20 @@ else:
|
||||||
'charset': 'utf8mb4',
|
'charset': 'utf8mb4',
|
||||||
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
elif os.getenv('DB_FILE') is not None:
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': os.getenv('DB_FILE', 'local.db'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': ':memory:',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ from django.urls import path, include
|
||||||
|
|
||||||
from .version import get_info
|
from .version import get_info
|
||||||
|
|
||||||
|
from .metrics import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('djangoadmin/', admin.site.urls),
|
path('djangoadmin/', admin.site.urls),
|
||||||
path('api/2/', include('inventory.api_v2')),
|
path('api/2/', include('inventory.api_v2')),
|
||||||
|
|
|
@ -345,6 +345,13 @@
|
||||||
notify:
|
notify:
|
||||||
- restart postfix
|
- restart postfix
|
||||||
|
|
||||||
|
- name: configure rspamd dkim
|
||||||
|
template:
|
||||||
|
src: templates/rspamd-dkim.cf.j2
|
||||||
|
dest: /etc/rspamd/local.d/dkim_signing.conf
|
||||||
|
notify:
|
||||||
|
- restart rspamd
|
||||||
|
|
||||||
- name: configure rspamd
|
- name: configure rspamd
|
||||||
copy:
|
copy:
|
||||||
content: |
|
content: |
|
||||||
|
|
|
@ -32,12 +32,11 @@ smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
||||||
|
|
||||||
|
|
||||||
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
|
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
|
||||||
myhostname = polaris.c3lf.de
|
myhostname = polaris.lab.or.it
|
||||||
alias_maps = hash:/etc/aliases
|
alias_maps = hash:/etc/aliases
|
||||||
alias_database = hash:/etc/aliases
|
alias_database = hash:/etc/aliases
|
||||||
myorigin = /etc/mailname
|
myorigin = /etc/mailname
|
||||||
mydestination = $myhostname, , localhost
|
mydestination = $myhostname, , localhost
|
||||||
relayhost = firefly.lab.or.it
|
|
||||||
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
||||||
mailbox_size_limit = 0
|
mailbox_size_limit = 0
|
||||||
recipient_delimiter = +
|
recipient_delimiter = +
|
||||||
|
|
79
deploy/ansible/playbooks/templates/rspamd-dkim.cf.j2
Normal file
79
deploy/ansible/playbooks/templates/rspamd-dkim.cf.j2
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
# local.d/dkim_signing.conf
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
|
||||||
|
# If false, messages with empty envelope from are not signed
|
||||||
|
allow_envfrom_empty = true;
|
||||||
|
|
||||||
|
# If true, envelope/header domain mismatch is ignored
|
||||||
|
allow_hdrfrom_mismatch = false;
|
||||||
|
|
||||||
|
# If true, multiple from headers are allowed (but only first is used)
|
||||||
|
allow_hdrfrom_multiple = false;
|
||||||
|
|
||||||
|
# If true, username does not need to contain matching domain
|
||||||
|
allow_username_mismatch = false;
|
||||||
|
|
||||||
|
# Default path to key, can include '$domain' and '$selector' variables
|
||||||
|
path = "/var/lib/rspamd/dkim/$domain.$selector.key";
|
||||||
|
|
||||||
|
# Default selector to use
|
||||||
|
selector = "dkim";
|
||||||
|
|
||||||
|
# If false, messages from authenticated users are not selected for signing
|
||||||
|
sign_authenticated = true;
|
||||||
|
|
||||||
|
# If false, messages from local networks are not selected for signing
|
||||||
|
sign_local = true;
|
||||||
|
|
||||||
|
# Map file of IP addresses/subnets to consider for signing
|
||||||
|
# sign_networks = "/some/file"; # or url
|
||||||
|
|
||||||
|
# Symbol to add when message is signed
|
||||||
|
symbol = "DKIM_SIGNED";
|
||||||
|
|
||||||
|
# Whether to fallback to global config
|
||||||
|
try_fallback = true;
|
||||||
|
|
||||||
|
# Domain to use for DKIM signing: can be "header" (MIME From), "envelope" (SMTP From), "recipient" (SMTP To), "auth" (SMTP username) or directly specified domain name
|
||||||
|
use_domain = "header";
|
||||||
|
|
||||||
|
# Domain to use for DKIM signing when sender is in sign_networks ("header"/"envelope"/"auth")
|
||||||
|
#use_domain_sign_networks = "header";
|
||||||
|
|
||||||
|
# Domain to use for DKIM signing when sender is a local IP ("header"/"envelope"/"auth")
|
||||||
|
#use_domain_sign_local = "header";
|
||||||
|
|
||||||
|
# Whether to normalise domains to eSLD
|
||||||
|
use_esld = true;
|
||||||
|
|
||||||
|
# Whether to get keys from Redis
|
||||||
|
use_redis = false;
|
||||||
|
|
||||||
|
# Hash for DKIM keys in Redis
|
||||||
|
key_prefix = "DKIM_KEYS";
|
||||||
|
|
||||||
|
# map of domains -> names of selectors (since rspamd 1.5.3)
|
||||||
|
#selector_map = "/etc/rspamd/dkim_selectors.map";
|
||||||
|
|
||||||
|
# map of domains -> paths to keys (since rspamd 1.5.3)
|
||||||
|
#path_map = "/etc/rspamd/dkim_paths.map";
|
||||||
|
|
||||||
|
# If `true` get pubkey from DNS record and check if it matches private key
|
||||||
|
check_pubkey = false;
|
||||||
|
# Set to `false` if you want to skip signing if public and private keys mismatch
|
||||||
|
allow_pubkey_mismatch = true;
|
||||||
|
|
||||||
|
# Domain specific settings
|
||||||
|
domain {
|
||||||
|
# Domain name is used as key
|
||||||
|
c3lf.de {
|
||||||
|
|
||||||
|
# Private key path
|
||||||
|
path = "/var/lib/rspamd/dkim/{{ mail_domain }}.key";
|
||||||
|
|
||||||
|
# Selector
|
||||||
|
selector = "{{ mail_domain }}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,20 +3,15 @@ services:
|
||||||
build:
|
build:
|
||||||
context: ../../core
|
context: ../../core
|
||||||
dockerfile: ../deploy/dev/Dockerfile.backend
|
dockerfile: ../deploy/dev/Dockerfile.backend
|
||||||
command: bash -c 'python manage.py migrate && python manage.py runserver 0.0.0.0:8000'
|
command: bash -c 'python manage.py migrate && python testdata.py && python manage.py runserver 0.0.0.0:8000'
|
||||||
environment:
|
environment:
|
||||||
- HTTP_HOST=core
|
- HTTP_HOST=core
|
||||||
- DB_HOST=db
|
- DB_FILE=dev.db
|
||||||
- DB_PORT=3306
|
|
||||||
- DB_NAME=system3
|
|
||||||
- DB_USER=system3
|
|
||||||
- DB_PASSWORD=system3
|
|
||||||
volumes:
|
volumes:
|
||||||
- ../../core:/code
|
- ../../core:/code
|
||||||
|
- ../testdata.py:/code/testdata.py
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
|
@ -31,18 +26,3 @@ services:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
- core
|
- core
|
||||||
|
|
||||||
db:
|
|
||||||
image: mariadb
|
|
||||||
environment:
|
|
||||||
MARIADB_RANDOM_ROOT_PASSWORD: true
|
|
||||||
MARIADB_DATABASE: system3
|
|
||||||
MARIADB_USER: system3
|
|
||||||
MARIADB_PASSWORD: system3
|
|
||||||
volumes:
|
|
||||||
- mariadb_data:/var/lib/mysql
|
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mariadb_data:
|
|
88
deploy/testdata.py
Normal file
88
deploy/testdata.py
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
from authentication.models import ExtendedUser, EventPermission
|
||||||
|
from inventory.models import Event
|
||||||
|
from django.contrib.auth.models import Permission, Group
|
||||||
|
permissions = ['add_item', 'view_item', 'view_file', 'delete_item', 'change_item']
|
||||||
|
if not ExtendedUser.objects.filter(username='admin').exists():
|
||||||
|
admin = ExtendedUser.objects.create_superuser('admin', 'admin@example.com', 'admin')
|
||||||
|
admin.set_password('admin')
|
||||||
|
admin.user_permissions.add(*Permission.objects.all())
|
||||||
|
admin.save()
|
||||||
|
|
||||||
|
if not ExtendedUser.objects.filter(username='testuser').exists():
|
||||||
|
testuser = ExtendedUser.objects.create_user('testuser', 'testuser@example.com', 'testuser')
|
||||||
|
testuser.set_password('testuser')
|
||||||
|
testuser.user_permissions.add(*Permission.objects.all())
|
||||||
|
testuser.save()
|
||||||
|
|
||||||
|
team = Group.objects.get(name='Team')
|
||||||
|
team.permissions.add(
|
||||||
|
*Permission.objects.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not ExtendedUser.objects.filter(username='testuser2').exists():
|
||||||
|
testuser2 = ExtendedUser.objects.create_user('testuser2', 'testuser2@example.com', 'testuser2')
|
||||||
|
testuser2.set_password('testuser2')
|
||||||
|
testuser2.groups.add(team)
|
||||||
|
testuser2.save()
|
||||||
|
|
||||||
|
event1 = Event.objects.get_or_create(id=1, name='first test event', slug='TEST1',
|
||||||
|
start='2023-12-18 00:00:00.000000', end='2023-12-27 00:00:00.000000',
|
||||||
|
pre_start='2023-12-31 00:00:00.000000', post_end='2024-01-04 00:00:00.000000')[
|
||||||
|
0]
|
||||||
|
|
||||||
|
event2 = Event.objects.get_or_create(id=2, name='second test event', slug='TEST2',
|
||||||
|
start='2024-12-18 00:00:00.000000', end='2024-12-27 00:00:00.000000',
|
||||||
|
pre_start='2024-12-31 00:00:00.000000', post_end='2025-01-04 00:00:00.000000')[
|
||||||
|
0]
|
||||||
|
|
||||||
|
# for permission in permissions:
|
||||||
|
# EventPermission.objects.create(event=event_37c3, user=foo,
|
||||||
|
# permission=Permission.objects.get(codename=permission))
|
||||||
|
|
||||||
|
from tickets.models import IssueThread
|
||||||
|
|
||||||
|
from mail.models import Email
|
||||||
|
|
||||||
|
issue_thread = IssueThread.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
name="test",
|
||||||
|
event=Event.objects.get(slug='TEST1')
|
||||||
|
)[0]
|
||||||
|
mail1 = Email.objects.get_or_create(
|
||||||
|
id=1,
|
||||||
|
subject='test subject',
|
||||||
|
body='test',
|
||||||
|
sender='test1@test',
|
||||||
|
recipient='test2@test',
|
||||||
|
issue_thread=issue_thread,
|
||||||
|
)[0]
|
||||||
|
mail1_reply = Email.objects.get_or_create(
|
||||||
|
id=2,
|
||||||
|
subject='Message received',
|
||||||
|
body='Thank you for your message.',
|
||||||
|
sender='test2@test',
|
||||||
|
recipient='test1@test',
|
||||||
|
in_reply_to=mail1.reference,
|
||||||
|
issue_thread=issue_thread,
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||||
|
import django
|
||||||
|
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
|
call_command('migrate')
|
||||||
|
|
||||||
|
setup()
|
||||||
|
print('testdata initialised')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -20,7 +20,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: ../../core
|
context: ../../core
|
||||||
dockerfile: ../deploy/testing/Dockerfile.backend
|
dockerfile: ../deploy/testing/Dockerfile.backend
|
||||||
command: bash -c 'python manage.py migrate && python /code/server.py'
|
command: bash -c 'python manage.py migrate && python testdata.py && python /code/server.py'
|
||||||
environment:
|
environment:
|
||||||
- HTTP_HOST=core
|
- HTTP_HOST=core
|
||||||
- REDIS_HOST=redis
|
- REDIS_HOST=redis
|
||||||
|
@ -29,13 +29,16 @@ services:
|
||||||
- DB_NAME=system3
|
- DB_NAME=system3
|
||||||
- DB_USER=system3
|
- DB_USER=system3
|
||||||
- DB_PASSWORD=system3
|
- DB_PASSWORD=system3
|
||||||
|
- MAIL_DOMAIN=mail:1025
|
||||||
volumes:
|
volumes:
|
||||||
- ../../core:/code
|
- ../../core:/code
|
||||||
|
- ../testdata.py:/code/testdata.py
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- redis
|
- redis
|
||||||
|
- mail
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
|
@ -51,5 +54,19 @@ services:
|
||||||
depends_on:
|
depends_on:
|
||||||
- core
|
- core
|
||||||
|
|
||||||
|
mail:
|
||||||
|
image: docker.io/axllent/mailpit
|
||||||
|
volumes:
|
||||||
|
- mailpit_data:/data
|
||||||
|
ports:
|
||||||
|
- 8025:8025
|
||||||
|
- 1025:1025
|
||||||
|
environment:
|
||||||
|
MP_MAX_MESSAGES: 5000
|
||||||
|
MP_DATABASE: /data/mailpit.db
|
||||||
|
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
||||||
|
MP_SMTP_AUTH_ALLOW_INSECURE: 1
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mariadb_data:
|
mariadb_data:
|
||||||
|
mailpit_data:
|
||||||
|
|
0
web/node_modules/.forgit_fordocker
generated
vendored
Normal file
0
web/node_modules/.forgit_fordocker
generated
vendored
Normal file
|
@ -2,7 +2,29 @@
|
||||||
<div>
|
<div>
|
||||||
<Modal v-if="isModal" title="Add Item" @close="$emit('close')">
|
<Modal v-if="isModal" title="Add Item" @close="$emit('close')">
|
||||||
<template #body>
|
<template #body>
|
||||||
<EditItem :item="item"/>
|
<div>
|
||||||
|
<InputPhoto
|
||||||
|
:model="item"
|
||||||
|
field="file"
|
||||||
|
:on-capture="storeImage"
|
||||||
|
/>
|
||||||
|
<InputString
|
||||||
|
label="description"
|
||||||
|
:model="item"
|
||||||
|
field="description"
|
||||||
|
:validation-fn="str => str && str.length > 0"
|
||||||
|
/>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="box">box</label>
|
||||||
|
<InputCombo
|
||||||
|
label="box"
|
||||||
|
:model="item"
|
||||||
|
nameKey="box"
|
||||||
|
uniqueKey="cid"
|
||||||
|
:options="boxes"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #buttons>
|
<template #buttons>
|
||||||
<button type="button" class="btn btn-secondary" @click="$emit('close')">Cancel</button>
|
<button type="button" class="btn btn-secondary" @click="$emit('close')">Cancel</button>
|
||||||
|
@ -13,33 +35,40 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {mapActions, mapGetters, mapState} from "vuex";
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
import InputCombo from "@/components/inputs/InputCombo.vue";
|
||||||
import {mapActions, mapState} from "vuex";
|
import InputPhoto from "@/components/inputs/InputPhoto.vue";
|
||||||
|
import InputString from "@/components/inputs/InputString.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AddItemModal',
|
name: 'AddItemModal',
|
||||||
components: {Modal, EditItem},
|
components: {InputString, InputPhoto, InputCombo, Modal},
|
||||||
props: ['isModal'],
|
props: ['isModal'],
|
||||||
data: () => ({
|
data: () => ({
|
||||||
item: {}
|
item: {}
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['lastUsed'])
|
...mapState(['lastUsed']),
|
||||||
|
...mapGetters(['getBoxes']),
|
||||||
|
boxes({getBoxes}) {
|
||||||
|
return getBoxes.map(obj => ({cid: obj.id, box: obj.name}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['postItem', 'loadBoxes', 'scheduleAfterInit']),
|
...mapActions(['postItem', 'loadBoxes', 'scheduleAfterInit']),
|
||||||
saveNewItem() {
|
async saveNewItem() {
|
||||||
this.postItem(this.item).then(() => {
|
await this.postItem(this.item);
|
||||||
this.$emit('close');
|
this.$emit('close');
|
||||||
});
|
},
|
||||||
|
storeImage(image) {
|
||||||
|
this.item.dataImage = image;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.item = {box: this.lastUsed.box || '', cid: this.lastUsed.cid || ''};
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.scheduleAfterInit(() => [this.loadBoxes()]);
|
this.scheduleAfterInit(() => [this.loadBoxes().then(() => {
|
||||||
|
this.item = {box: this.lastUsed.box || '', cid: this.lastUsed.cid || ''};
|
||||||
|
})])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -19,11 +19,10 @@
|
||||||
<script>
|
<script>
|
||||||
import {mapActions} from 'vuex';
|
import {mapActions} from 'vuex';
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AddTicketModal',
|
name: 'AddTicketModal',
|
||||||
components: {Modal, EditItem},
|
components: {Modal},
|
||||||
props: ['isModal'],
|
props: ['isModal'],
|
||||||
data: () => ({
|
data: () => ({
|
||||||
ticket: {
|
ticket: {
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<h6>Editing Item <span class="badge badge-secondary">#{{ item.uid }}</span></h6>
|
|
||||||
<InputPhoto
|
|
||||||
:model="item"
|
|
||||||
field="file"
|
|
||||||
:on-capture="storeImage"
|
|
||||||
/>
|
|
||||||
<InputString
|
|
||||||
label="description"
|
|
||||||
:model="item"
|
|
||||||
field="description"
|
|
||||||
:validation-fn="str => str && str.length > 0"
|
|
||||||
/>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="box">box</label>
|
|
||||||
<InputCombo
|
|
||||||
label="box"
|
|
||||||
:model="item"
|
|
||||||
nameKey="box"
|
|
||||||
uniqueKey="cid"
|
|
||||||
:options="boxes"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import InputString from './inputs/InputString';
|
|
||||||
import InputCombo from './inputs/InputCombo';
|
|
||||||
import {mapGetters} from 'vuex';
|
|
||||||
import InputPhoto from './inputs/InputPhoto';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'EditItem',
|
|
||||||
components: {InputPhoto, InputCombo, InputString},
|
|
||||||
props: ['item'],
|
|
||||||
computed: {
|
|
||||||
...mapGetters(['getBoxes']),
|
|
||||||
boxes({getBoxes}) {
|
|
||||||
return getBoxes.map(obj => ({cid: obj.cid, box: obj.name}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
storeImage(image) {
|
|
||||||
this.item.dataImage = image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
|
@ -43,11 +43,11 @@ export default {
|
||||||
props: ['label', 'model', 'nameKey', 'uniqueKey', 'options', 'onOptionAdd'],
|
props: ['label', 'model', 'nameKey', 'uniqueKey', 'options', 'onOptionAdd'],
|
||||||
data: ({options, model, nameKey, uniqueKey}) => ({
|
data: ({options, model, nameKey, uniqueKey}) => ({
|
||||||
internalName: model[nameKey],
|
internalName: model[nameKey],
|
||||||
selectedOption: options.filter(e => e[uniqueKey] == model[uniqueKey])[0],
|
selectedOption: options.filter(e => e[uniqueKey] === model[uniqueKey])[0],
|
||||||
addingOption: false
|
addingOption: false
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
isValid: ({options, nameKey, internalName}) => options.some(e => e[nameKey] == internalName),
|
isValid: ({options, nameKey, internalName}) => options.some(e => e[nameKey] === internalName),
|
||||||
sortedOptions: ({
|
sortedOptions: ({
|
||||||
options,
|
options,
|
||||||
nameKey
|
nameKey
|
||||||
|
@ -56,7 +56,7 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
internalName(newValue) {
|
internalName(newValue) {
|
||||||
if (this.isValid) {
|
if (this.isValid) {
|
||||||
if (!this.selectedOption || newValue != this.selectedOption[this.nameKey]) {
|
if (!this.selectedOption || newValue !== this.selectedOption[this.nameKey]) {
|
||||||
this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0];
|
this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0];
|
||||||
}
|
}
|
||||||
this.model[this.nameKey] = this.selectedOption[this.nameKey];
|
this.model[this.nameKey] = this.selectedOption[this.nameKey];
|
||||||
|
|
|
@ -443,7 +443,8 @@ const store = createStore({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async postManualTicket({commit, dispatch, state, getters}, {sender, message, title,}) {
|
async postManualTicket({commit, dispatch, state, getters}, {sender, message, title,}) {
|
||||||
const {data, success} = await getters.session.post(`/2/tickets/manual/`, {
|
const slug = getters.getEventSlug;
|
||||||
|
const {data, success} = await getters.session.post(`/2/${slug !== 'all' ? slug : 'none'}/tickets/manual/`, {
|
||||||
name: title, sender, body: message, recipient: 'mail@c3lf.de'
|
name: title, sender, body: message, recipient: 'mail@c3lf.de'
|
||||||
});
|
});
|
||||||
await dispatch('loadTickets');
|
await dispatch('loadTickets');
|
||||||
|
@ -456,7 +457,10 @@ const store = createStore({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async postItemComment({commit, dispatch, state, getters}, {id, message}) {
|
async postItemComment({commit, dispatch, state, getters}, {id, message}) {
|
||||||
const {data, success} = await getters.session.post(`/2/${getters.getEventSlug}/item/${id}/comment/`, {comment: message});
|
const {
|
||||||
|
data,
|
||||||
|
success
|
||||||
|
} = await getters.session.post(`/2/${getters.getEventSlug}/item/${id}/comment/`, {comment: message});
|
||||||
if (data && success) {
|
if (data && success) {
|
||||||
state.fetchedData.items = 0;
|
state.fetchedData.items = 0;
|
||||||
await dispatch('loadEventItems');
|
await dispatch('loadEventItems');
|
||||||
|
|
|
@ -112,14 +112,12 @@ import InputString from "@/components/inputs/InputString.vue";
|
||||||
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
|
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
|
||||||
import InputPhoto from "@/components/inputs/InputPhoto.vue";
|
import InputPhoto from "@/components/inputs/InputPhoto.vue";
|
||||||
import Modal from "@/components/Modal.vue";
|
import Modal from "@/components/Modal.vue";
|
||||||
import EditItem from "@/components/EditItem.vue";
|
|
||||||
import AsyncButton from "@/components/inputs/AsyncButton.vue";
|
import AsyncButton from "@/components/inputs/AsyncButton.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Item',
|
name: 'Item',
|
||||||
components: {
|
components: {
|
||||||
AsyncButton,
|
AsyncButton,
|
||||||
EditItem,
|
|
||||||
Modal, InputPhoto, AuthenticatedImage, InputString, InputCombo, AsyncLoader, ClipboardButton, Timeline
|
Modal, InputPhoto, AuthenticatedImage, InputString, InputCombo, AsyncLoader, ClipboardButton, Timeline
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
|
@ -67,11 +67,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {mapActions, mapGetters, mapMutations, mapState} from 'vuex';
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
import Cards from '@/components/Cards';
|
import Cards from '@/components/Cards';
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
|
||||||
import {mapActions, mapGetters, mapMutations} from 'vuex';
|
|
||||||
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";
|
import router from "@/router";
|
||||||
|
@ -82,9 +81,9 @@ export default {
|
||||||
lightboxHash: null,
|
lightboxHash: null,
|
||||||
editingItem: null,
|
editingItem: null,
|
||||||
}),
|
}),
|
||||||
components: {AsyncLoader, AuthenticatedImage, Table, Cards, Modal, EditItem},
|
components: {AsyncLoader, AuthenticatedImage, Table, Cards, Modal},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['getEventItems', 'isItemsLoaded', 'layout']),
|
...mapGetters(['getEventItems', 'isItemsLoaded', 'layout', 'getEventSlug']),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['deleteItem', 'markItemReturned', 'loadEventItems', 'updateItem', 'scheduleAfterInit']),
|
...mapActions(['deleteItem', 'markItemReturned', 'loadEventItems', 'updateItem', 'scheduleAfterInit']),
|
||||||
|
@ -96,6 +95,11 @@ export default {
|
||||||
return window.confirm(message);
|
return window.confirm(message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
getEventSlug() {
|
||||||
|
this.scheduleAfterInit(() => [this.loadEventItems()]);
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.scheduleAfterInit(() => [this.loadEventItems()]);
|
this.scheduleAfterInit(() => [this.loadEventItems()]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<AsyncLoader :loaded="events.length > 0">
|
<AsyncLoader :loaded="events.length > 0">
|
||||||
<ExpandableTable v-if="!!events" :columns="['slug', 'name']" :items="events" :keyName="'slug'">
|
<ExpandableTable v-if="!!events" :columns="['slug', 'name']" :items="events.map((e,i)=>({idx: i, ...e}))"
|
||||||
|
:keyName="'slug'">
|
||||||
<template v-slot:header_actions>
|
<template v-slot:header_actions>
|
||||||
<button class="btn btn-success" @click.prevent="openAddEventModal">
|
<button class="btn btn-success" @click.prevent="openAddEventModal">
|
||||||
<font-awesome-icon icon="plus"/>
|
<font-awesome-icon icon="plus"/>
|
||||||
|
@ -43,7 +44,7 @@
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label class="mr-3">Addresses: </label>
|
<label class="mr-3">Addresses: </label>
|
||||||
<div v-for="(address, a_id) in item.addresses" class="btn-group btn-group-sm mr-3"
|
<div v-for="(address, a_id) in item.addresses" class="btn-group btn-group-sm mr-3"
|
||||||
@click.stop="deleteAddress(id, a_id)">
|
@click.stop="deleteAddress(item.idx, a_id)">
|
||||||
<button class="btn btn-secondary" disabled style="opacity: 1">
|
<button class="btn btn-secondary" disabled style="opacity: 1">
|
||||||
{{ address }}
|
{{ address }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -52,8 +53,9 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group btn-group-sm">
|
<div class="btn-group btn-group-sm">
|
||||||
<input type="text" v-model="new_address[id]">
|
<input type="text" v-model="new_address[item.idx]">
|
||||||
<button class="btn btn-secondary" @click.stop="addAddress(id)" style="white-space: nowrap;">
|
<button class="btn btn-secondary" @click.stop="addAddress(item.idx)"
|
||||||
|
style="white-space: nowrap;">
|
||||||
<font-awesome-icon icon="envelope"/> add
|
<font-awesome-icon icon="envelope"/> add
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -88,11 +90,11 @@ export default {
|
||||||
if (!this.events[id].addresses.includes(a))
|
if (!this.events[id].addresses.includes(a))
|
||||||
this.events[id].addresses.push(a)
|
this.events[id].addresses.push(a)
|
||||||
this.new_address[id] = ""
|
this.new_address[id] = ""
|
||||||
this.updateEvent({id: this.events[id].eid, partial_event: {addresses: this.events[id].addresses}});
|
this.updateEvent({id: this.events[id].id, partial_event: {addresses: this.events[id].addresses}});
|
||||||
},
|
},
|
||||||
deleteAddress(id, a_id) {
|
deleteAddress(id, a_id) {
|
||||||
this.events[id].addresses = this.events[id].addresses.filter((e, i) => i !== a_id);
|
this.events[id].addresses = this.events[id].addresses.filter((e, i) => i !== a_id);
|
||||||
this.updateEvent({id: this.events[id].eid, partial_event: {addresses: this.events[id].addresses}});
|
this.updateEvent({id: this.events[id].id, partial_event: {addresses: this.events[id].addresses}});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue