Various fixes

This commit is contained in:
Antoine Nguyen
2025-06-13 16:51:12 +02:00
parent d2c44b1c39
commit a651695086
28 changed files with 270 additions and 704 deletions
@@ -8,36 +8,37 @@
<label class="m-label">{{ $gettext('Name') }}</label>
<v-text-field
v-model="form.name"
dense
variant="outlined"
density="compact"
:rules="[rules.required]"
/>
<label class="m-label">{{ $gettext('Choose a domain') }}</label>
<v-select
v-model="form.target"
:items="Object.values(domainsStore.domains)"
:items="domains"
item-title="name"
item-value="pk"
:rules="[rules.required]"
single-line
dense
variant="outlined"
density="compact"
/>
<v-switch v-model="form.enabled" label="Enabled" color="primary" />
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn @click="emit('close')">
<v-btn :loading="working" @click="emit('close')">
{{ $gettext('Close') }}
</v-btn>
<v-btn
v-if="domainAlias && domainAlias.pk"
color="error"
:loading="working"
@click="deleteAlias"
>
{{ $gettext('Delete') }}
</v-btn>
<v-btn color="primary" type="submit">
<v-btn color="primary" type="submit" :loading="working">
{{ submitLabel }}
</v-btn>
</v-card-actions>
@@ -47,21 +48,23 @@
<script setup lang="js">
import { useGettext } from 'vue3-gettext'
import { useDomainsStore } from '@/stores'
import { computed, ref, onMounted } from 'vue'
import { useBusStore } from '@/stores'
import rules from '@/plugins/rules.js'
import domainsApi from '@/api/domains'
const { $gettext } = useGettext()
const domainsStore = useDomainsStore()
const emit = defineEmits(['close'])
const { displayNotification } = useBusStore()
const props = defineProps({
domainAlias: { type: Object, default: () => null },
})
const domains = ref([])
const form = ref({ enabled: true })
const working = ref(false)
const vFormRef = ref()
const submitLabel = computed(() => {
@@ -74,8 +77,15 @@ const title = computed(() =>
: $gettext('Add a new domain alias')
)
function deleteAlias() {
domainsStore.deleteAlias(props.domainAlias).then(() => emit('close'))
async function deleteAlias() {
working.value = true
try {
await domainsApi.deleteDomainAlias(props.domainAlias.pk)
displayNotification({ msg: $gettext('Domain alias deleted') })
emit('close')
} finally {
working.value = false
}
}
async function submit() {
@@ -83,24 +93,26 @@ async function submit() {
if (!valid) {
return
}
working.value = true
try {
if (!form.value.pk) {
// Create
domainsStore.createAlias(form.value).then(() => {
emit('close')
})
await domainsApi.createDomainAlias(form.value)
displayNotification({ msg: $gettext('Domain alias created') })
} else {
// Update
const data = JSON.parse(JSON.stringify(form.value))
domainsStore.updateAlias(data).then(() => emit('close'))
await domainsApi.updateDomainAlias(props.domainAlias.pk, data)
displayNotification({ msg: $gettext('Domain alias updated') })
}
} catch (error) {
//TODO
console.error(error)
emit('close')
} finally {
working.value = false
}
}
onMounted(() => {
domainsApi.getDomains().then((resp) => {
domains.value = resp.data
})
if (props.domainAlias) {
form.value = JSON.parse(JSON.stringify(props.domainAlias))
}
@@ -69,7 +69,8 @@
</template>
<script setup lang="js">
import ParametersApi from '@/api/parameters.js'
import domainsApi from '@/api/domains'
import ParametersApi from '@/api/parameters'
import CreationForm from '@/components/tools/CreationForm.vue'
import DomainGeneralForm from './form_steps/DomainGeneralForm.vue'
import DomainDNSForm from './form_steps/DomainDNSForm.vue'
@@ -78,15 +79,14 @@ import DomainOptionsForm from './form_steps/DomainOptionsForm.vue'
import DomainTransportForm from './form_steps/DomainTransportForm.vue'
import { useGettext } from 'vue3-gettext'
import { ref, computed, onMounted } from 'vue'
import { useBusStore, useDomainsStore } from '@/stores'
import { useBusStore } from '@/stores'
import { useRouter } from 'vue-router'
const { $gettext } = useGettext()
const busStore = useBusStore()
const domainsStore = useDomainsStore()
const router = useRouter()
const emit = defineEmits(['close'])
const emit = defineEmits(['close', 'created'])
const defaultDomain = {
name: '',
@@ -123,6 +123,7 @@ onMounted(() => {
const createAdmin = ref(false)
// Reference to steps components
const form = ref()
const general = ref()
const dns = ref()
const limitations = ref()
@@ -298,7 +299,7 @@ function updateCreateAdmin(value) {
createAdmin.value = value
}
function submit() {
async function submit() {
const data = JSON.parse(JSON.stringify(domain.value))
if (!createAdmin.value) {
delete data.domain_admin
@@ -311,11 +312,14 @@ function submit() {
} else {
delete data.transport
}
domainsStore.createDomain(data).then((resp) => {
try {
const resp = await domainsApi.createDomain(data)
router.push({ name: 'DomainDetail', params: { id: resp.data.pk } })
busStore.displayNotification({ msg: $gettext('Domain created') })
close()
})
} finally {
form.value.working = false
}
}
</script>
@@ -1,5 +1,5 @@
<template>
<LoadingData v-if="!domainsStore.domainsLoaded || working" />
<LoadingData v-if="working" />
<div v-else>
<v-expansion-panels v-model="panel" :multiple="formErrors">
<v-expansion-panel eager value="generalForm">
@@ -181,13 +181,13 @@ import parametersApi from '@/api/parameters'
import ResourcesForm from '@/components/tools/ResourcesForm.vue'
import { computed, ref, onMounted } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useAuthStore, useDomainsStore } from '@/stores'
import { useAuthStore } from '@/stores'
import { useRouter } from 'vue-router'
import domainsApi from '@/api/domains'
const router = useRouter()
const { $gettext } = useGettext()
const authStore = useAuthStore()
const domainsStore = useDomainsStore()
const props = defineProps({ domain: { type: Object, default: null } })
@@ -253,8 +253,13 @@ async function save() {
if (data.type === 'relaydomain') {
transportForm.value.checkSettingTypes(data)
}
domainsStore.updateDomain(data).then(() => {
router.go(-1)
if (data.message_limit === '') {
data.message_limit = null
}
await domainsApi.updateDomain(editedDomain.value.pk, data)
router.push({
name: 'DomainDetail',
params: { id: editedDomain.value.pk },
})
} finally {
working.value = false
@@ -4,12 +4,12 @@
v-model="selected"
:expanded="expanded"
:headers="domainHeaders"
:items="Object.values(domains)"
:items="domains"
item-value="name"
:search="search"
show-select
expand-on-click
:loading="!domainsLoaded"
:loading="loading"
>
<template #top>
<v-toolbar color="white" flat>
@@ -19,7 +19,6 @@
:placeholder="$gettext('Search')"
variant="outlined"
single-line
flat
hide-details
density="compact"
class="flex-grow-0 w-33 mr-4"
@@ -149,7 +148,7 @@
<a href="#" class="mr-2" @click="editDomainAlias(item, alias)">{{
alias.name
}}</a>
<v-chip variant="elevated" size="x-small" color="success"
<v-chip variant="flat" size="x-small" color="success"
>DNS OK</v-chip
>
</span>
@@ -181,7 +180,7 @@
</template>
<script setup lang="js">
import { useAuthStore, useBusStore, useDomainsStore } from '@/stores'
import { useBusStore } from '@/stores'
import { useGettext } from 'vue3-gettext'
import { useRouter } from 'vue-router'
import { usePermissions } from '@/composables/permissions'
@@ -190,18 +189,15 @@ import ConfirmDialog from '@/components/tools/ConfirmDialog.vue'
import DNSStatusChip from './DNSStatusChip.vue'
import DomainAliasForm from './DomainAliasForm.vue'
import MenuItems from '@/components/tools/MenuItems.vue'
import domainsApi from '@/api/domains'
import { computed, ref, onMounted } from 'vue'
import { ref, onMounted } from 'vue'
const { $gettext } = useGettext()
const router = useRouter()
const { canSetRole } = usePermissions()
const busStore = useBusStore()
const domainStore = useDomainsStore()
const domains = computed(() => domainStore.domains)
const domainsLoaded = computed(() => domainStore.domainsLoaded)
const aliases = computed(() => domainStore.domainAliases)
const domainHeaders = [
{ title: $gettext('Name'), key: 'name' },
@@ -224,8 +220,11 @@ if (canSetRole.value) {
})
}
const aliases = ref({})
const confirm = ref()
const domains = ref([])
const keepDomainFolder = ref(false)
const loading = ref(false)
const selectedDomain = ref(null)
const selectedDomainAlias = ref(null)
const showAdminList = ref(false)
@@ -234,8 +233,15 @@ const search = ref('')
const selected = ref([])
const expanded = ref([])
function reloadDomains() {
domainStore.getDomains()
async function reloadDomains() {
aliases.value = {}
loading.value = true
try {
const resp = await domainsApi.getDomains()
domains.value = resp.data
} finally {
loading.value = false
}
}
function closeDomainAliasForm() {
@@ -260,10 +266,10 @@ async function deleteDomain(domain) {
return
}
const data = { keep_folder: keepDomainFolder.value }
domainStore.deleteDomain({ id: domain.pk, data }).then(() => {
busStore.displayNotification({ msg: $gettext('Domain deleted') })
keepDomainFolder.value = false
})
await domainsApi.deleteDomain(domain.pk, data)
reloadDomains()
busStore.displayNotification({ msg: $gettext('Domain deleted') })
keepDomainFolder.value = false
}
function editDomain(domain) {
@@ -282,7 +288,8 @@ function loadAliases(item, internalItem, isItemExpanded, toggleExpand) {
toggleExpand(internalItem)
return
}
domainStore.getAliases(item.name).then(() => {
domainsApi.getDomainAliases(item.name).then((resp) => {
aliases.value[item.name] = resp.data
toggleExpand(internalItem)
})
}
@@ -325,6 +332,10 @@ function getDomainMenuItems(domain) {
onMounted(() => {
reloadDomains()
})
defineExpose({
reloadDomains,
})
</script>
<style scoped>
@@ -35,6 +35,7 @@
'Number of messages this domain can send per day. Leave empty for no limit.'
)
"
type="number"
persistent-hint
variant="outlined"
:rules="[rules.numericOrNull]"
@@ -70,15 +70,14 @@ import AccountMailboxForm from './form_steps/AccountMailboxForm.vue'
import AccountAliasForm from './form_steps/AccountAliasForm.vue'
import { useGettext } from 'vue3-gettext'
import { ref, computed, onMounted } from 'vue'
import { useBusStore, useDomainsStore, useIdentitiesStore } from '@/stores'
import { ref, computed } from 'vue'
import { useBusStore, useDomainsStore } from '@/stores'
import { usePermissions } from '@/composables/permissions'
const { $gettext } = useGettext()
const { canSetRole } = usePermissions()
const busStore = useBusStore()
const domainsStore = useDomainsStore()
const identitiesStore = useIdentitiesStore()
const emit = defineEmits(['close', 'created'])
const needsMailbox = computed(
@@ -196,6 +195,7 @@ const account = ref({
})
// Form refs
const form = ref()
const role = ref()
const identification = ref()
const mailbox = ref()
@@ -255,20 +255,21 @@ function close() {
emit('close')
}
function submit() {
async function submit() {
const data = preparePayload({ ...account.value })
data.password = data.new_password
delete data.new_password
delete data.password_confirmation
identitiesStore.createIdentity('account', data).then(() => {
try {
await accountsApi.create(data)
emit('created')
close()
})
} finally {
form.value.working = false
}
}
onMounted(() => {
domainsStore.getDomains()
})
domainsStore.getDomains()
</script>
<style lang="scss">
@@ -1,5 +1,5 @@
<template>
<LoadingData v-if="!accountsStore.accountsLoaded || working" />
<LoadingData v-if="working" />
<div v-else>
<v-expansion-panels v-model="panel" :multiple="formErrors">
<v-expansion-panel v-if="canSetRole" eager value="roleForm">
@@ -12,7 +12,7 @@
<v-fade-transition leave-absolute>
<span v-if="expanded"></span>
<v-row v-else no-gutters style="width: 100%">
<v-col cols="6">
<v-col v-if="roleForm" cols="6">
{{ roleForm.roleLabel }}
</v-col>
</v-row>
@@ -30,7 +30,7 @@
<v-col cols="4">
{{ $gettext('Identification') }}
</v-col>
<v-col cols="8" class="text-secondary">
<v-col cols="8" class="">
<v-fade-transition leave-absolute>
<span v-if="expanded"></span>
<v-row v-else no-gutters style="width: 100%">
@@ -68,7 +68,7 @@
<v-col cols="4">
{{ $gettext('Mailbox') }}
</v-col>
<v-col cols="8" class="text-secondary">
<v-col cols="8" class="">
<v-fade-transition leave-absolute>
<span v-if="expanded"></span>
<v-row v-else no-gutters style="width: 100%">
@@ -115,14 +115,13 @@
<v-col cols="4">
{{ $gettext('Alias') }}
</v-col>
<v-col cols="8" class="text-secondary">
<v-col cols="8" class="">
<v-fade-transition leave-absolute>
<span v-if="expanded"></span>
<v-row v-else no-gutters style="width: 100%">
<template v-if="editedAccount.aliases">
<v-col cols="6">
<div class="mr-2">
{{ $gettext('Aliases:') }}
{{ $gettext('Number of associated alias:') }}
{{ editedAccount.aliases.length }}
</div>
@@ -143,7 +142,7 @@
<v-col cols="4">
{{ $gettext('Resources') }}
</v-col>
<v-col cols="8" class="text-secondary">
<v-col cols="8" class="">
<v-fade-transition leave-absolute>
<span v-if="expanded"></span>
<v-row v-else no-gutters style="width: 100%">
@@ -155,14 +154,12 @@
>
<v-col cols="6">
<div class="mr-2">
{{ $gettext('Mailbox:') }}
{{ $gettext('Number of allowed mailboxes:') }}
{{ editedAccount.resources[0].max_value }}
</div>
</v-col>
<v-col cols="6">
<div class="mr-2">
{{ $gettext('Mailbox aliases:') }}
{{ $gettext('Number of allowed mailbox aliases:') }}
{{ editedAccount.resources[1].max_value }}
</div>
@@ -182,12 +179,13 @@
</v-expansion-panel>
</v-expansion-panels>
<div class="mt-4 d-flex justify-end">
<v-btn :loading="working" @click="$router.go(-1)">
<v-btn :loading="working" variant="outlined" @click="$router.go(-1)">
{{ $gettext('Cancel') }}
</v-btn>
<v-btn
class="ml-4"
color="primary darken-1"
variant="outlined"
:loading="working"
@click="save"
>
@@ -198,13 +196,14 @@
</template>
<script setup lang="js">
import { useAccountsStore, useAuthStore, useIdentitiesStore } from '@/stores'
import { useAuthStore } from '@/stores'
import AccountGeneralForm from './form_steps/AccountGeneralForm.vue'
import AccountMailboxForm from './form_steps/AccountMailboxForm.vue'
import AccountAliasForm from './form_steps/AccountAliasForm.vue'
import AccountRoleForm from './form_steps/AccountRoleForm.vue'
import ResourcesForm from '@/components/tools/ResourcesForm.vue'
import LoadingData from '@/components/tools/LoadingData.vue'
import accountsApi from '@/api/accounts.js'
import parametersApi from '@/api/parameters'
import { ref, computed, onMounted, watch } from 'vue'
import { useGettext } from 'vue3-gettext'
@@ -212,9 +211,7 @@ import { useRoute, useRouter } from 'vue-router'
import { usePermissions } from '@/composables/permissions'
const { $gettext } = useGettext()
const accountsStore = useAccountsStore()
const authStore = useAuthStore()
const identitiesStore = useIdentitiesStore()
const route = useRoute()
const router = useRouter()
const { canSetRole } = usePermissions()
@@ -309,11 +306,10 @@ async function save() {
data.role = 'SimpleUsers'
}
}
identitiesStore.updateIdentity('account', data).then(() => {
router.push({
name: 'AccountDetail',
params: { id: route.params.id },
})
await accountsApi.patch(editedAccount.value.pk, data)
router.push({
name: 'AccountDetail',
params: { id: route.params.id },
})
} finally {
working.value = false
@@ -321,9 +317,10 @@ async function save() {
}
onMounted(() => {
accountsStore
.getAccount(route.params.id)
.then((response) => (editedAccount.value = { ...response.data }))
accountsApi.get(route.params.id).then((response) => {
editedAccount.value = response.data
working.value = false
})
if (canSetRole.value) {
parametersApi.getGlobalApplication('limits').then((response) => {
@@ -20,7 +20,7 @@
</template>
<script setup lang="js">
import { useBusStore, useIdentitiesStore } from '@/stores'
import { useBusStore } from '@/stores'
import { ref, computed } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useRouter } from 'vue-router'
@@ -33,12 +33,12 @@ import CreationForm from '@/components/tools/CreationForm.vue'
const { $gettext } = useGettext()
const busStore = useBusStore()
const identitiesStore = useIdentitiesStore()
const router = useRouter()
const emit = defineEmits(['close', 'created'])
//Forms refs
const form = ref()
const general = ref()
const recipients = ref()
@@ -139,13 +139,17 @@ function validateAlias() {
return validation
}
function submit() {
async function submit() {
if (alias.value.domain !== undefined) {
delete alias.value.domain
}
identitiesStore.createIdentity('alias', alias.value).then(() => {
try {
await aliasesApi.create(alias.value)
emit('created')
close()
})
} finally {
form.value.working = false
}
}
</script>
@@ -1,5 +1,5 @@
<template>
<LoadingData v-if="!aliasesStore.aliasesLoaded || working" />
<LoadingData v-if="working" />
<div v-else>
<v-expansion-panels v-model="panel" :multiple="formErrors">
<v-expansion-panel eager value="generalForm">
@@ -81,24 +81,22 @@
</template>
<script setup lang="js">
import { useIdentitiesStore, useAliasesStore } from '@/stores'
import AliasGeneralForm from './form_steps/AliasGeneralForm.vue'
import AliasRecipientForm from './form_steps/AliasRecipientForm'
import LoadingData from '@/components/tools/LoadingData.vue'
import { useGettext } from 'vue3-gettext'
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import aliasesApi from '@/api/aliases'
const { $gettext } = useGettext()
const identitiesStore = useIdentitiesStore()
const aliasesStore = useAliasesStore()
const route = useRoute()
const router = useRouter()
const editedAlias = ref({ pk: route.params.id })
const panel = ref(0)
const working = ref(false)
const working = ref(true)
const formErrors = ref(false)
// refs
@@ -126,20 +124,21 @@ async function save() {
working.value = true
identitiesStore
.updateIdentity('alias', editedAlias.value)
.then(() =>
router.push({
name: 'AliasDetail',
params: { id: route.params.id },
})
)
.finally(() => (working.value = false))
try {
await aliasesApi.patch(route.params.id, editedAlias.value)
router.push({
name: 'AliasDetail',
params: { id: route.params.id },
})
} finally {
working.value = false
}
}
onMounted(() => {
aliasesStore.getAlias(route.params.id).then((response) => {
editedAlias.value = { ...response.data }
aliasesApi.get(route.params.id).then((response) => {
editedAlias.value = response.data
working.value = false
})
})
</script>
@@ -5,7 +5,7 @@
:headers="headers"
:items="identities"
:search="search"
:loading="!identitiesLoaded"
:loading="loading"
item-value="identity"
class="elevation-0"
show-select
@@ -77,7 +77,7 @@
item.possible_actions.length !== 0
"
>
<v-icon size="2.5em" color="blue">mdi-circle-small</v-icon>
<v-icon size="large" color="blue">mdi-circle-small</v-icon>
</template>
<v-menu location="bottom">
<template #activator="{ props }">
@@ -107,13 +107,14 @@
<script setup lang="js">
import { ref, computed, onMounted } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useIdentitiesStore } from '@/stores'
import MenuItems from '@/components/tools/MenuItems.vue'
import ConfirmDialog from '@/components/tools/ConfirmDialog.vue'
import { useRouter } from 'vue-router'
import accountsApi from '@/api/accounts'
import aliasesApi from '@/api/aliases'
import identitiesApi from '@/api/identities'
const { $gettext } = useGettext()
const identitiesStore = useIdentitiesStore()
const router = useRouter()
const headers = ref([
@@ -128,18 +129,23 @@ const headers = ref([
},
])
const identities = computed(() => identitiesStore.identities)
const identitiesLoaded = computed(() => identitiesStore.identitiesLoaded)
const identities = ref([])
const loading = ref(false)
const search = ref('')
const selected = ref([])
const keepAccountFolder = ref(false)
const confirmAlias = ref()
const confirmAccount = ref()
function fetchIdentities() {
identitiesStore.getIdentities().then(() => {
async function fetchIdentities() {
loading.value = true
try {
const resp = await identitiesApi.getAll()
identities.value = resp.data
selected.value = []
})
} finally {
loading.value = false
}
}
function getMenuItems(item) {
@@ -214,13 +220,14 @@ async function deleteAccount(account) {
if (!result) {
return
}
identitiesStore
.deleteIdentity(account.type, account.pk, {
keepdir: keepAccountFolder.value,
})
.then(() => {
keepAccountFolder.value = false
})
loading.value = false
try {
await accountsApi.delete(account.pk, { keepdir: keepAccountFolder.value })
fetchIdentities()
} finally {
loading.value = false
}
}
function editAlias() {}
@@ -240,12 +247,20 @@ async function deleteAlias(alias) {
if (!result) {
return
}
identitiesStore.deleteIdentity(alias.type, alias.pk)
loading.value = false
try {
await aliasesApi.delete(alias.pk)
fetchIdentities()
} finally {
loading.value = false
}
}
onMounted(() => {
if (identities.value.length < 1) {
fetchIdentities()
}
fetchIdentities()
})
defineExpose({
fetchIdentities,
})
</script>
@@ -53,8 +53,11 @@ import rules from '@/plugins/rules'
const { $gettext } = useGettext()
const emit = defineEmits(['update:modelValue'])
const props = defineProps({ modelValue: { type: Object, default: null } })
const domainsStore = useDomainsStore()
const domains = computed(() => domainsStore.domains)
const vFormRef = ref()
const form = ref({
mailbox: {},
@@ -94,7 +97,9 @@ watch(
const domainQuota = computed(() => {
const email = form.value.mailbox.full_address
if (email && email.indexOf('@') !== -1) {
const domain = domainsStore.getDomainByName(email.split('@')[1])
const domain = domains.value.find(
(item) => item.name === email.split('@')[1]
)
if (domain) {
return parseInt(domain.default_mailbox_quota)
}
@@ -21,7 +21,7 @@
<label class="m-label">{{ $gettext('Domain') }}</label>
<v-select
v-model="alias.domain"
:items="Object.values(domains)"
:items="domains"
item-title="name"
return-object
variant="outlined"
@@ -69,16 +69,14 @@
import aliasesApi from '@/api/aliases'
import EmailField from '@/components/tools/EmailField'
import { ref, computed } from 'vue'
import { useDomainsStore } from '@/stores'
import rules from '@/plugins/rules'
import domainsApi from '@/api/domains'
const domainsStore = useDomainsStore()
const props = defineProps({ modelValue: { type: Object, default: null } })
const alias = computed(() => props.modelValue)
const domains = computed(() => domainsStore.domains)
const domains = ref([])
const vFormRef = ref()
function copyAlias() {
@@ -94,5 +92,9 @@ async function updateAddress() {
})
}
domainsApi.getDomains().then((resp) => {
domains.value = resp.data
})
defineExpose({ vFormRef })
</script>
@@ -164,6 +164,10 @@ function create() {
working.value = true
emit('create')
}
defineExpose({
working,
})
</script>
<style lang="scss">