2025-03-14 18:48:13 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
2025-10-21 14:30:25 +02:00
|
|
|
import { ref, useTemplateRef, computed, inject } from 'vue';
|
2025-07-10 11:55:11 +02:00
|
|
|
import { Dialog, Button, TextInput, FormGroup, Checkbox, InputGroup, SingleSelect } from '@cloudron/pankow';
|
|
|
|
|
import { prettyDecimalSize } from '@cloudron/pankow/utils';
|
2025-03-14 18:48:13 +01:00
|
|
|
import MailboxesModel from '../models/MailboxesModel.js';
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits([ 'success' ]);
|
2025-09-25 08:56:35 +02:00
|
|
|
const props = defineProps([ 'apps', 'users', 'groups', 'domains' ]);
|
2025-03-14 18:48:13 +01:00
|
|
|
|
|
|
|
|
const mailboxesModel = MailboxesModel.create();
|
|
|
|
|
|
2025-10-21 14:30:25 +02:00
|
|
|
const dashboardDomain = inject('dashboardDomain');
|
2025-03-14 18:48:13 +01:00
|
|
|
const dialog = useTemplateRef('dialog');
|
|
|
|
|
const busy = ref(false);
|
|
|
|
|
const formError = ref('');
|
|
|
|
|
const name = ref('');
|
|
|
|
|
const domain = ref('');
|
|
|
|
|
const mailbox = ref(null);
|
|
|
|
|
const aliases = ref([]);
|
|
|
|
|
const ownerId = ref('');
|
2025-10-07 17:20:00 +02:00
|
|
|
const usersAndGroupsAndApps = ref([]);
|
2025-03-14 18:48:13 +01:00
|
|
|
const storageQuotaEnabled = ref(false);
|
|
|
|
|
const storageQuotaTicks = [ 500*1000*1000, 5*1000*1000*1000, 15*1000*1000*1000, 50*1000*1000*1000, 100*1000*1000*1000 ];
|
2025-06-13 17:41:34 +02:00
|
|
|
const storageQuota = ref(5*1000*1000*1000);
|
2025-03-14 18:48:13 +01:00
|
|
|
const active = ref(false);
|
|
|
|
|
const enablePop3 = ref(false);
|
2025-09-30 16:01:11 +02:00
|
|
|
const domainList = ref([]);
|
2025-03-14 18:48:13 +01:00
|
|
|
|
2025-09-30 17:27:53 +02:00
|
|
|
const domainHasIncomingEnabled = computed(() => {
|
|
|
|
|
const selected = domainList.value.find(d => d.domain === domain.value);
|
|
|
|
|
return selected ? selected.enabled : false;
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
function onAddAlias() {
|
|
|
|
|
aliases.value.push({
|
|
|
|
|
name: '',
|
2025-12-01 14:26:16 +01:00
|
|
|
domain: domain.value,
|
|
|
|
|
label: '@' + domain.value,
|
2025-03-14 18:48:13 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function onRemoveAlias(index) {
|
|
|
|
|
aliases.value.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-01 14:21:45 +01:00
|
|
|
const form = useTemplateRef('form');
|
|
|
|
|
const isFormValid = ref(false);
|
|
|
|
|
function validateForm() {
|
|
|
|
|
isFormValid.value = form.value && form.value.checkValidity();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
async function onSubmit() {
|
2025-12-01 14:21:45 +01:00
|
|
|
if (!form.value.reportValidity()) return;
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
busy.value = true;
|
|
|
|
|
formError.value = '';
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
ownerId: ownerId.value,
|
|
|
|
|
ownerType: ownerId.value.indexOf('gid-') === 0 ? 'group' : 'user',
|
|
|
|
|
active: active.value,
|
|
|
|
|
enablePop3: enablePop3.value,
|
|
|
|
|
storageQuota: storageQuotaEnabled.value ? parseInt(storageQuota.value) : 0,
|
|
|
|
|
messagesQuota: 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (mailbox.value) {
|
|
|
|
|
let [error] = await mailboxesModel.update(domain.value, name.value, data);
|
|
|
|
|
if (error) {
|
|
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[error] = await mailboxesModel.setAliases(domain.value, name.value, aliases.value);
|
|
|
|
|
if (error) {
|
|
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const [error] = await mailboxesModel.add(domain.value, name.value, data);
|
|
|
|
|
if (error) {
|
|
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit('success');
|
|
|
|
|
dialog.value.close();
|
|
|
|
|
busy.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
async open(m = null) {
|
2025-10-08 12:38:19 +02:00
|
|
|
m = m ? JSON.parse(JSON.stringify(m)) : null; // make a copy
|
2025-03-14 18:48:13 +01:00
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = '';
|
|
|
|
|
mailbox.value = m;
|
|
|
|
|
|
|
|
|
|
name.value = m ? m.name : '';
|
2025-10-21 14:30:25 +02:00
|
|
|
domain.value = m ? m.domain : dashboardDomain.value;
|
2025-03-14 18:48:13 +01:00
|
|
|
ownerId.value = m ? m.ownerId : '';
|
2025-10-08 12:38:19 +02:00
|
|
|
aliases.value = m ? m.aliases : [];
|
2025-03-14 18:48:13 +01:00
|
|
|
active.value = m ? m.active : true;
|
|
|
|
|
enablePop3.value = m ? m.enablePop3 : false;
|
2025-06-13 17:44:11 +02:00
|
|
|
storageQuotaEnabled.value = m && m.storageQuota ? true : false;
|
|
|
|
|
storageQuota.value = m ? m.storageQuota : 5*1000*1000*1000;
|
2025-10-14 15:48:22 +02:00
|
|
|
usersAndGroupsAndApps.value = [];
|
|
|
|
|
|
|
|
|
|
if (props.users.length) usersAndGroupsAndApps.value.push({ separator: true, label: 'Users' });
|
|
|
|
|
usersAndGroupsAndApps.value = usersAndGroupsAndApps.value.concat(props.users);
|
|
|
|
|
|
|
|
|
|
if (props.groups.length) usersAndGroupsAndApps.value.push({ separator: true, label: 'Groups' });
|
|
|
|
|
usersAndGroupsAndApps.value = usersAndGroupsAndApps.value.concat(props.groups);
|
|
|
|
|
|
|
|
|
|
if (props.apps.length) usersAndGroupsAndApps.value.push({ separator: true, label: 'Apps' });
|
|
|
|
|
usersAndGroupsAndApps.value = usersAndGroupsAndApps.value.concat(props.apps);
|
2025-03-14 18:48:13 +01:00
|
|
|
|
|
|
|
|
// unify on .name for multiselect
|
2025-10-14 15:48:22 +02:00
|
|
|
usersAndGroupsAndApps.value.forEach(item => {
|
|
|
|
|
if (item.appIds) {
|
|
|
|
|
item.icon = 'fa-solid fa-users';
|
|
|
|
|
} else if (item.username) {
|
|
|
|
|
item.icon = 'fa-solid fa-user';
|
|
|
|
|
item.name = item.username;
|
|
|
|
|
} else {
|
|
|
|
|
item.icon = 'fa-solid fa-cube';
|
|
|
|
|
item.name = item.label || item.fqdn;
|
|
|
|
|
}
|
2025-03-14 18:48:13 +01:00
|
|
|
});
|
|
|
|
|
|
2025-09-30 16:01:11 +02:00
|
|
|
domainList.value = props.domains.map(d => {
|
|
|
|
|
return {
|
|
|
|
|
domain: d.domain,
|
|
|
|
|
label: '@' + d.domain,
|
2025-09-30 17:27:53 +02:00
|
|
|
enabled: !!d.enabled,
|
2025-09-30 16:01:11 +02:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
dialog.value.open();
|
2025-12-01 14:21:45 +01:00
|
|
|
|
|
|
|
|
setTimeout(validateForm, 100); // update state of the confirm button
|
2025-03-14 18:48:13 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Dialog ref="dialog"
|
2025-11-11 21:15:15 +01:00
|
|
|
:title="mailbox ? $t('email.editMailboxDialog.title') : $t('email.addMailboxDialog.title')"
|
2025-03-14 18:48:13 +01:00
|
|
|
:confirm-label="$t(mailbox ? 'main.dialog.save' : 'email.incoming.mailboxes.addAction')"
|
|
|
|
|
:confirm-busy="busy"
|
2025-12-01 14:21:45 +01:00
|
|
|
:confirm-active="!busy && isFormValid"
|
2025-03-14 18:48:13 +01:00
|
|
|
reject-style="secondary"
|
2025-09-24 16:56:10 +02:00
|
|
|
:reject-label="$t('main.dialog.cancel')"
|
|
|
|
|
:reject-active="!busy"
|
2025-03-14 18:48:13 +01:00
|
|
|
@confirm="onSubmit()"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
2025-12-01 14:21:45 +01:00
|
|
|
<form @submit.prevent="onSubmit()" novalidate autocomplete="off" ref="form" @input="validateForm()">
|
2025-03-14 18:48:13 +01:00
|
|
|
<fieldset :disabled="busy">
|
|
|
|
|
<input type="submit" style="display: none;" :disabled="!name || !domain"/>
|
|
|
|
|
|
2025-11-11 21:15:15 +01:00
|
|
|
<FormGroup>
|
2025-03-14 18:48:13 +01:00
|
|
|
<label for="nameInput">{{ $t('email.addMailboxDialog.name') }}</label>
|
|
|
|
|
<InputGroup>
|
2025-12-01 14:21:45 +01:00
|
|
|
<TextInput id="nameInput" style="flex-grow: 1;" v-model="name" :readonly="mailbox ? true : undefined" :required="!mailbox"/>
|
|
|
|
|
<SingleSelect v-model="domain" :options="domainList" option-key="domain" option-label="label" :disabled="!!mailbox" :required="!mailbox"/>
|
2025-03-14 18:48:13 +01:00
|
|
|
</InputGroup>
|
2025-09-30 17:27:53 +02:00
|
|
|
<div class="warning-label" v-if="!domainHasIncomingEnabled">{{ $t('email.addMailboxDialog.incomingDisabledWarning') }}</div>
|
2025-06-13 22:02:08 +02:00
|
|
|
<div class="error-label" v-if="formError">{{ formError }}</div>
|
2025-03-14 18:48:13 +01:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-02 10:37:01 +02:00
|
|
|
<FormGroup>
|
2025-03-14 18:48:13 +01:00
|
|
|
<label>{{ $t('email.editMailboxDialog.owner') }}</label>
|
2025-12-01 14:21:45 +01:00
|
|
|
<SingleSelect v-model="ownerId" :options="usersAndGroupsAndApps" :searchThreshold="10" option-key="id" option-label="name" required/>
|
2025-03-14 18:48:13 +01:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-06-13 17:39:14 +02:00
|
|
|
<Checkbox v-if="mailbox" v-model="active" :label="$t('email.updateMailboxDialog.activeCheckbox')"/>
|
2025-03-14 18:48:13 +01:00
|
|
|
|
2025-05-07 12:23:05 +02:00
|
|
|
<Checkbox v-model="enablePop3" :label="$t('email.updateMailboxDialog.enablePop3')"/>
|
2025-03-14 18:48:13 +01:00
|
|
|
|
2025-05-07 12:23:05 +02:00
|
|
|
<Checkbox v-model="storageQuotaEnabled" :label="$t('email.editMailboxDialog.enableStorageQuota') + (storageQuotaEnabled ? ` : ${prettyDecimalSize(storageQuota)}` : '')"/>
|
2025-10-01 03:47:49 +02:00
|
|
|
<div>
|
2025-05-07 12:23:05 +02:00
|
|
|
<input style="width: 100%;" type="range" id="storageQuota" :disabled="!storageQuotaEnabled" v-model="storageQuota" step="500000000" :min="storageQuotaTicks[0]" :max="storageQuotaTicks[storageQuotaTicks.length-1]" list="storageQuotaTicks" />
|
2025-03-14 18:48:13 +01:00
|
|
|
<datalist id="storageQuotaTicks">
|
|
|
|
|
<option v-for="quota in storageQuotaTicks" :value="quota" :key="quota"></option>
|
|
|
|
|
</datalist>
|
2025-05-07 12:23:05 +02:00
|
|
|
</div>
|
2025-03-14 18:48:13 +01:00
|
|
|
|
|
|
|
|
<!-- we only show this on edit for now as it is a separate REST call which may fail after the mailbox was added -->
|
|
|
|
|
<FormGroup v-if="mailbox">
|
|
|
|
|
<label>{{ $t('email.editMailboxDialog.aliases') }}</label>
|
2025-09-24 07:34:14 +02:00
|
|
|
<div v-for="(alias, index) in aliases" :key="alias" style="margin: 5px 0;">
|
2025-03-14 18:48:13 +01:00
|
|
|
<InputGroup>
|
|
|
|
|
<TextInput style="flex-grow: 1;" v-model="alias.name"/>
|
2025-09-30 16:01:11 +02:00
|
|
|
<SingleSelect v-model="alias.domain" :options="domainList" option-key="domain" option-label="label" />
|
2025-03-14 18:48:13 +01:00
|
|
|
<Button tool danger icon="fa-solid fa-trash-alt" @click="onRemoveAlias(index)"/>
|
|
|
|
|
</InputGroup>
|
|
|
|
|
</div>
|
2025-09-24 07:34:14 +02:00
|
|
|
<div style="margin-top: 5px"></div>
|
2025-03-14 18:48:13 +01:00
|
|
|
<div v-if="aliases.length === 0">
|
2025-12-01 14:26:16 +01:00
|
|
|
{{ $t('email.editMailboxDialog.noAliases') }} <span class="actionable" @click="onAddAlias">{{ $t('email.editMailboxDialog.addAliasAction') }}</span>
|
2025-03-14 18:48:13 +01:00
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<div class="actionable" @click="onAddAlias($event)">{{ $t('email.editMailboxDialog.addAnotherAliasAction') }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</template>
|