mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-26 11:14:23 +01:00
Various fixes
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useBusStore } from './bus.store'
|
||||
|
||||
import accountsApi from '@/api/accounts'
|
||||
import gettext from '@/plugins/gettext'
|
||||
|
||||
export const useAccountsStore = defineStore('accounts', () => {
|
||||
const busStore = useBusStore()
|
||||
|
||||
const { $gettext } = gettext
|
||||
|
||||
const accounts = ref({})
|
||||
const accountsLoaded = ref(false)
|
||||
|
||||
async function $reset() {
|
||||
accounts.value = {}
|
||||
accountsLoaded.value = false
|
||||
}
|
||||
|
||||
async function getAll() {
|
||||
accounts.value = {}
|
||||
return accountsApi.getAll().then((response) => {
|
||||
for (const account of response.data) {
|
||||
accounts.value[account.pk] = account
|
||||
}
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function getAccount(pk) {
|
||||
accountsLoaded.value = false
|
||||
return accountsApi
|
||||
.get(pk)
|
||||
.then((response) => {
|
||||
accounts.value[pk] = response.data
|
||||
return response
|
||||
})
|
||||
.finally(() => {
|
||||
accountsLoaded.value = true
|
||||
})
|
||||
}
|
||||
|
||||
async function updateAccount(data) {
|
||||
return accountsApi.patch(data.pk, data).then((response) => {
|
||||
accounts.value[data.pk] = response.data
|
||||
busStore.displayNotification({ msg: $gettext('Account updated') })
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function createAccount(data) {
|
||||
return accountsApi.create(data).then((response) => {
|
||||
accounts.value[response.data.pk] = response.data
|
||||
busStore.displayNotification({ msg: $gettext('Account created') })
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteAccount(pk, options) {
|
||||
accountsLoaded.value = false
|
||||
return accountsApi
|
||||
.delete(pk, options)
|
||||
.then((response) => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Account successfully deleted'),
|
||||
})
|
||||
return response
|
||||
})
|
||||
.finally(() => (accountsLoaded.value = true))
|
||||
}
|
||||
return {
|
||||
accounts,
|
||||
accountsLoaded,
|
||||
getAll,
|
||||
getAccount,
|
||||
updateAccount,
|
||||
createAccount,
|
||||
deleteAccount,
|
||||
$reset,
|
||||
}
|
||||
})
|
||||
@@ -1,94 +0,0 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import aliasesApi from '@/api/aliases'
|
||||
import { useBusStore } from './bus.store'
|
||||
|
||||
import gettext from '@/plugins/gettext'
|
||||
|
||||
export const useAliasesStore = defineStore('aliases', () => {
|
||||
const busStore = useBusStore()
|
||||
const { $gettext } = gettext
|
||||
|
||||
const aliases = ref({})
|
||||
const aliasesLoaded = ref(false)
|
||||
|
||||
async function $reset() {
|
||||
aliases.value = {}
|
||||
aliasesLoaded.value = false
|
||||
}
|
||||
|
||||
async function getAll() {
|
||||
aliasesLoaded.value = false
|
||||
return aliasesApi
|
||||
.getAll()
|
||||
.then((response) => {
|
||||
aliases.value = {}
|
||||
for (const account of response.data) {
|
||||
aliases.value[account.pk] = account
|
||||
}
|
||||
return response
|
||||
})
|
||||
.finally(() => (aliasesLoaded.value = true))
|
||||
}
|
||||
|
||||
async function getAlias(pk) {
|
||||
aliasesLoaded.value = false
|
||||
return aliasesApi
|
||||
.get(pk)
|
||||
.then((response) => {
|
||||
aliases.value[pk] = response.data
|
||||
return response
|
||||
})
|
||||
.finally(() => (aliasesLoaded.value = true))
|
||||
}
|
||||
|
||||
async function createAlias(data) {
|
||||
aliasesLoaded.value = false
|
||||
return aliasesApi
|
||||
.create(data)
|
||||
.then((response) => {
|
||||
aliases.value[response.data.pk] = response.data
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Alias successfully created'),
|
||||
})
|
||||
return response
|
||||
})
|
||||
.finally(() => (aliasesLoaded.value = true))
|
||||
}
|
||||
|
||||
async function deleteAlias(pk) {
|
||||
aliasesLoaded.value = false
|
||||
return aliasesApi
|
||||
.delete(pk)
|
||||
.then((response) => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Alias successfully deleted'),
|
||||
})
|
||||
return response
|
||||
})
|
||||
.finally(() => (aliasesLoaded.value = true))
|
||||
}
|
||||
|
||||
async function updateAlias(data) {
|
||||
aliasesLoaded.value = false
|
||||
return aliasesApi
|
||||
.patch(data.pk, data)
|
||||
.then((response) => {
|
||||
aliases.value[data.pk] = response.data
|
||||
busStore.displayNotification({ msg: $gettext('Alias updated') })
|
||||
return response
|
||||
})
|
||||
.finally(() => (aliasesLoaded.value = true))
|
||||
}
|
||||
|
||||
return {
|
||||
aliases,
|
||||
aliasesLoaded,
|
||||
getAll,
|
||||
getAlias,
|
||||
createAlias,
|
||||
deleteAlias,
|
||||
updateAlias,
|
||||
$reset,
|
||||
}
|
||||
})
|
||||
@@ -1,155 +1,31 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { useBusStore } from './bus.store'
|
||||
import { ref } from 'vue'
|
||||
import gettext from '@/plugins/gettext'
|
||||
|
||||
import domainApi from '@/api/domains'
|
||||
|
||||
export const useDomainsStore = defineStore('domains', () => {
|
||||
const busStore = useBusStore()
|
||||
const { $gettext } = gettext
|
||||
const domainsLoaded = ref(false)
|
||||
const domains = ref({})
|
||||
const domainAliases = ref({})
|
||||
|
||||
async function $reset() {
|
||||
domainsLoaded.value = false
|
||||
domains.value = {}
|
||||
domainAliases.value = {}
|
||||
}
|
||||
|
||||
async function getDomains() {
|
||||
domainsLoaded.value = false
|
||||
return domainApi.getDomains().then((response) => {
|
||||
domains.value = {}
|
||||
const _domains = {}
|
||||
response.data.forEach(function (domain) {
|
||||
_domains[domain.pk] = domain
|
||||
})
|
||||
domains.value = _domains
|
||||
domainsLoaded.value = true
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function getDomain(pk) {
|
||||
domainsLoaded.value = false
|
||||
return domainApi.getDomain(pk).then((response) => {
|
||||
domains.value[pk] = response.data
|
||||
domainsLoaded.value = true
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
function getDomainByName(name) {
|
||||
for (const domain of Object.values(domains.value)) {
|
||||
if (domain.name === name) {
|
||||
return domain
|
||||
}
|
||||
try {
|
||||
const resp = await domainApi.getDomains()
|
||||
domains.value = resp.data
|
||||
} finally {
|
||||
domainsLoaded.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createDomain(data) {
|
||||
return domainApi.createDomain(data).then((response) => {
|
||||
domains.value[response.data.pk] = response.data
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function updateDomain(data) {
|
||||
return domainApi.updateDomain(data.pk, data).then((response) => {
|
||||
domains.value[data.pk] = response.data
|
||||
busStore.displayNotification({ msg: $gettext('Domain updated') })
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteDomain({ id, data }) {
|
||||
return domainApi.deleteDomain(id, data).then((response) => {
|
||||
delete domains.value[id]
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function getAliases(name) {
|
||||
return domainApi.getDomainAliases(name).then((response) => {
|
||||
domainAliases.value[name] = response.data
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function _filterAlias(domainName, pk) {
|
||||
if (domainAliases.value[domainName] !== undefined) {
|
||||
return domainAliases.value[domainName].filter((al) => al.pk != pk)
|
||||
}
|
||||
}
|
||||
|
||||
async function createAlias(data) {
|
||||
return domainApi.createDomainAlias(data).then((response) => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Domain alias created'),
|
||||
})
|
||||
if (domains.value[data.target] != null) {
|
||||
const domain = domains.value[data.target]
|
||||
if (domainAliases.value[domain.name] !== undefined) {
|
||||
domainAliases.value[domain.name].push(response.data)
|
||||
} else {
|
||||
domainAliases.value[domain.name] = response.data
|
||||
}
|
||||
domain.domainalias_count++
|
||||
}
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteAlias(alias) {
|
||||
const domain = domains.value[alias.target]
|
||||
const apiRequest = domainApi.deleteDomainAlias(alias.pk)
|
||||
const filter = _filterAlias(domain.name, alias.pk)
|
||||
Promise.all([filter, apiRequest]).then((results) => {
|
||||
const newList = results[0]
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Domain alias deleted'),
|
||||
})
|
||||
if (newList != null) {
|
||||
domainAliases.value[domain.name] = newList
|
||||
}
|
||||
domain.domainalias_count--
|
||||
})
|
||||
}
|
||||
|
||||
async function updateAlias(data) {
|
||||
const domain = domains.value[data.target]
|
||||
const filter = _filterAlias(domain.name, data.pk)
|
||||
const apiRequest = domainApi.updateDomainAlias(data.pk, data)
|
||||
Promise.all([filter, apiRequest]).then((results) => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Domain alias updated'),
|
||||
})
|
||||
const newList = results[0]
|
||||
const response = results[1]
|
||||
if (newList != null) {
|
||||
domainAliases.value[domain.name] = newList
|
||||
domainAliases.value[domain.name].push(response.data)
|
||||
} else {
|
||||
domainAliases.value[domain.name] = response.data
|
||||
}
|
||||
})
|
||||
}
|
||||
return {
|
||||
domainsLoaded,
|
||||
domains,
|
||||
domainAliases,
|
||||
getDomain,
|
||||
getDomainByName,
|
||||
getDomains,
|
||||
createDomain,
|
||||
updateDomain,
|
||||
deleteDomain,
|
||||
createAlias,
|
||||
getAliases,
|
||||
deleteAlias,
|
||||
updateAlias,
|
||||
$reset,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useAccountsStore } from './accounts.store'
|
||||
import { useAliasesStore } from './aliases.store'
|
||||
|
||||
import identitiesApi from '@/api/identities'
|
||||
|
||||
import gettext from '@/plugins/gettext'
|
||||
|
||||
export const useIdentitiesStore = defineStore('identities', () => {
|
||||
const aliasesStore = useAliasesStore()
|
||||
const accountsStore = useAccountsStore()
|
||||
|
||||
const { $gettext } = gettext
|
||||
|
||||
const identitiesLoaded = ref(false)
|
||||
const identities = ref([])
|
||||
|
||||
async function $reset() {
|
||||
identitiesLoaded.value = false
|
||||
identities.value = []
|
||||
}
|
||||
|
||||
async function _getIndexByPk(type, pk) {
|
||||
for (let i = 0; i < identities.value.length; i++) {
|
||||
if (identities.value[i].pk === pk && identities.value[i].type === type) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function _deleteIdByPkAndType(type, pk) {
|
||||
_getIndexByPk(type, pk).then((index) => {
|
||||
if (index !== null) {
|
||||
identities.value.splice(index, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function getIdentities() {
|
||||
identitiesLoaded.value = false
|
||||
return identitiesApi.getAll().then((response) => {
|
||||
identities.value = response.data
|
||||
identitiesLoaded.value = true
|
||||
return response
|
||||
})
|
||||
}
|
||||
|
||||
async function _accountToId(data, update = false) {
|
||||
const account = data
|
||||
let indexSearcher = null
|
||||
if (update) {
|
||||
indexSearcher = _getIndexByPk('account', data.pk)
|
||||
}
|
||||
let name_or_rcpt = '---'
|
||||
if (account.first_name !== '') {
|
||||
name_or_rcpt = account.first_name
|
||||
}
|
||||
if (account.last_name !== '') {
|
||||
name_or_rcpt =
|
||||
name_or_rcpt === ''
|
||||
? account.last_name
|
||||
: `${name_or_rcpt} ${account.last_name}`
|
||||
}
|
||||
const newIdentity = {
|
||||
pk: account.pk,
|
||||
type: account.type,
|
||||
identity: account.username,
|
||||
name_or_rcpt: name_or_rcpt,
|
||||
tags: [
|
||||
{ name: 'account', label: $gettext('account'), type: 'idt' },
|
||||
{
|
||||
name: account.role,
|
||||
label: $gettext(account.role),
|
||||
type: 'grp',
|
||||
},
|
||||
],
|
||||
possible_actions: [],
|
||||
}
|
||||
|
||||
if (update) {
|
||||
indexSearcher.then((index) => {
|
||||
identities.value[index] = newIdentity
|
||||
return
|
||||
})
|
||||
}
|
||||
identities.value.push(newIdentity)
|
||||
}
|
||||
|
||||
async function _aliasToId(data, update = false) {
|
||||
let indexSearcher = null
|
||||
const alias = data
|
||||
if (update) {
|
||||
indexSearcher = _getIndexByPk('alias', data.pk)
|
||||
}
|
||||
const name_or_rcpt =
|
||||
alias.recipients.length > 1
|
||||
? `${alias.recipients[0]}, ...`
|
||||
: alias.recipients[0]
|
||||
const newIdentity = {
|
||||
pk: alias.pk,
|
||||
type: alias.type,
|
||||
identity: alias.address,
|
||||
name_or_rcpt: name_or_rcpt,
|
||||
tags: [{ name: 'alias', label: $gettext('alias'), type: 'idt' }],
|
||||
possible_actions: [],
|
||||
}
|
||||
if (update) {
|
||||
indexSearcher.then((index) => {
|
||||
identities.value[index] = newIdentity
|
||||
return
|
||||
})
|
||||
}
|
||||
identities.value.push(newIdentity)
|
||||
}
|
||||
|
||||
async function createIdentity(type, data) {
|
||||
identitiesLoaded.value = false
|
||||
if (type === 'alias') {
|
||||
return aliasesStore.createAlias(data).then((response) => {
|
||||
_aliasToId(response.data)
|
||||
identitiesLoaded.value = true
|
||||
return response
|
||||
})
|
||||
} else if (type === 'account') {
|
||||
return accountsStore.createAccount(data).then((response) => {
|
||||
_accountToId(response.data)
|
||||
identitiesLoaded.value = true
|
||||
return response
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function updateIdentity(type, data) {
|
||||
identitiesLoaded.value = false
|
||||
if (type === 'alias') {
|
||||
return aliasesStore
|
||||
.updateAlias(data)
|
||||
.then((response) => {
|
||||
_aliasToId(response.data, true)
|
||||
return response
|
||||
})
|
||||
.finally(() => (identitiesLoaded.value = true))
|
||||
} else if (type === 'account') {
|
||||
return accountsStore
|
||||
.updateAccount(data)
|
||||
.then((response) => {
|
||||
_accountToId(response.data, true)
|
||||
return response
|
||||
})
|
||||
.finally(() => (identitiesLoaded.value = true))
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteIdentity(type, pk, options) {
|
||||
identitiesLoaded.value = false
|
||||
if (type === 'alias') {
|
||||
return aliasesStore.deleteAlias(pk).then((response) => {
|
||||
_deleteIdByPkAndType(type, pk)
|
||||
identitiesLoaded.value = true
|
||||
return response
|
||||
})
|
||||
} else if (type === 'account') {
|
||||
return accountsStore.deleteAccount(pk, options).then((response) => {
|
||||
_deleteIdByPkAndType(type, pk)
|
||||
identitiesLoaded.value = true
|
||||
return response
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
identities,
|
||||
getIdentities,
|
||||
identitiesLoaded,
|
||||
deleteIdentity,
|
||||
createIdentity,
|
||||
updateIdentity,
|
||||
$reset,
|
||||
}
|
||||
})
|
||||
@@ -5,9 +5,6 @@ export * from './auth.store'
|
||||
export * from './bus.store'
|
||||
export * from './layout.store'
|
||||
export * from './domains.store'
|
||||
export * from './accounts.store'
|
||||
export * from './aliases.store'
|
||||
export * from './identities.store'
|
||||
export * from './parameters.store'
|
||||
export * from './providers.store'
|
||||
export * from './contacts.store'
|
||||
|
||||
Reference in New Issue
Block a user