mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-02 12:13:54 +01:00
Import / export features
This commit is contained in:
@@ -46,5 +46,15 @@ export default {
|
||||
},
|
||||
deleteDomainAlias (aliasId) {
|
||||
return repository.delete(`/${domainAliasResource}/${aliasId}/`)
|
||||
},
|
||||
exportAll () {
|
||||
return repository.get(`/${domainResource}/export/`)
|
||||
},
|
||||
importFromCSV (data) {
|
||||
return repository.post(`/${domainResource}/import/`, data, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,15 @@ const resource = 'identities'
|
||||
export default {
|
||||
getAll () {
|
||||
return repository.get(`${resource}/`)
|
||||
},
|
||||
exportAll () {
|
||||
return repository.get(`/${resource}/export/`)
|
||||
},
|
||||
importFromCSV (data) {
|
||||
return repository.post(`/${resource}/import/`, data, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ title }}</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-alert
|
||||
text
|
||||
type="info"
|
||||
>
|
||||
<translate tag="p">Provide a CSV file where lines respect one of the following formats:</translate>
|
||||
<slot name="help" />
|
||||
<translate tag="p">The first element of each line is mandatory and must be equal to one of the previous values.</translate>
|
||||
<translate tag="p">You can use a different character as separator.</translate>
|
||||
</v-alert>
|
||||
<validation-observer ref="observer">
|
||||
<validation-provider
|
||||
v-slot="{ errors }"
|
||||
name="name"
|
||||
rules="required"
|
||||
>
|
||||
<label class="m-label"><translate>Select file</translate></label>
|
||||
<v-file-input
|
||||
v-model="form.sourcefile"
|
||||
accept="text/csv"
|
||||
:error-messages="errors"
|
||||
truncate-length="15"
|
||||
outlined
|
||||
/>
|
||||
</validation-provider>
|
||||
<label class="m-label"><translate>Separator</translate></label>
|
||||
<v-text-field
|
||||
v-model="form.sepchar"
|
||||
:error-messages="errors"
|
||||
outlined
|
||||
/>
|
||||
<v-switch
|
||||
v-model="form.continue_if_exists"
|
||||
:label="'Continue on error'|translate"
|
||||
color="primary"
|
||||
/>
|
||||
</validation-observer>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn
|
||||
@click="close"
|
||||
>
|
||||
<translate>Close</translate>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
color="primary"
|
||||
@click="submit"
|
||||
>
|
||||
<translate>Import</translate>
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
helpText: String,
|
||||
title: String
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
form: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
close () {
|
||||
this.form = {}
|
||||
this.$refs.observer.reset()
|
||||
this.$emit('close')
|
||||
},
|
||||
async submit () {
|
||||
const valid = await this.$refs.observer.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
const data = new FormData()
|
||||
data.append('sourcefile', this.form.sourcefile)
|
||||
if (this.form.sepchar) {
|
||||
data.append('sepchar', this.form.sepchar)
|
||||
}
|
||||
if (this.form.continue_if_exists) {
|
||||
data.append('continue_if_exists', this.form.continue_if_exists)
|
||||
}
|
||||
this.$emit('submit', data)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { bus } from '@/main'
|
||||
|
||||
export const importExportMixin = {
|
||||
methods: {
|
||||
exportContent (content, name) {
|
||||
const blob = new Blob([content], { type: 'text/csv' })
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(blob)
|
||||
link.download = `modoboa-${name}.csv`
|
||||
link.click()
|
||||
URL.revokeObjectURL(link.href)
|
||||
},
|
||||
importContent (api, data) {
|
||||
api.importFromCSV(data).then(resp => {
|
||||
if (resp.data.status) {
|
||||
bus.$emit('notification', { msg: resp.data.message })
|
||||
this.$refs.importForm.close()
|
||||
} else {
|
||||
bus.$emit('notification', { msg: resp.data.message, type: 'error' })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,18 @@
|
||||
<v-toolbar flat>
|
||||
<v-toolbar-title><translate>Domains</translate></v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-btn class="mr-2">
|
||||
<v-btn
|
||||
class="mr-2"
|
||||
:title="'Import domains and aliases from CSV file'|translate"
|
||||
@click="showImportForm = true"
|
||||
>
|
||||
<v-icon>mdi-file-import-outline</v-icon>
|
||||
</v-btn>
|
||||
<v-btn class="mr-2">
|
||||
<v-btn
|
||||
class="mr-2"
|
||||
:title="'Export domains and aliases to CSV'|translate"
|
||||
@click="exportDomains"
|
||||
>
|
||||
<v-icon>mdi-file-export-outline</v-icon>
|
||||
</v-btn>
|
||||
<v-menu offset-y>
|
||||
@@ -41,28 +49,60 @@
|
||||
max-width="800px">
|
||||
<domain-alias-form @close="showAliasForm = false" />
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showImportForm"
|
||||
persistent
|
||||
max-width="800px">
|
||||
<import-form
|
||||
ref="importForm"
|
||||
:title="'Import domains'|translate"
|
||||
@submit="importDomains"
|
||||
@close="showImportForm = false"
|
||||
>
|
||||
<template v-slot:help>
|
||||
<ul>
|
||||
<li><em>domain; name; quota; default mailbox quota; enabled</em></li>
|
||||
<li><em>domainalias; name; targeted domain; enabled</em></li>
|
||||
<li><em>relaydomain; name; target host; target port; service; enabled; verify recipients</em></li>
|
||||
</ul>
|
||||
</template>
|
||||
</import-form>
|
||||
</v-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import domains from '@/api/domains'
|
||||
import DomainAliasForm from '@/components/domains/DomainAliasForm'
|
||||
import DomainCreationForm from '@/components/domains/DomainCreationForm'
|
||||
import DomainList from '@/components/domains/DomainList'
|
||||
import { importExportMixin } from '@/mixins/importExport'
|
||||
import ImportForm from '@/components/tools/ImportForm'
|
||||
|
||||
export default {
|
||||
mixins: [importExportMixin],
|
||||
components: {
|
||||
DomainAliasForm,
|
||||
DomainCreationForm,
|
||||
DomainList
|
||||
DomainList,
|
||||
ImportForm
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
showAliasForm: false,
|
||||
showDomainWizard: false
|
||||
showDomainWizard: false,
|
||||
showImportForm: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
exportDomains () {
|
||||
domains.exportAll().then(resp => {
|
||||
this.exportContent(resp.data, 'domains')
|
||||
})
|
||||
},
|
||||
importDomains (data) {
|
||||
this.importContent(domains, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
<v-toolbar flat>
|
||||
<v-toolbar-title><translate>Identities</translate></v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-btn class="mr-2">
|
||||
<v-btn
|
||||
class="mr-2"
|
||||
:title="'Import accounts and aliases from CSV file'|translate"
|
||||
@click="showImportForm = true"
|
||||
>
|
||||
<v-icon>mdi-file-import-outline</v-icon>
|
||||
</v-btn>
|
||||
<v-btn class="mr-2">
|
||||
<v-btn
|
||||
class="mr-2"
|
||||
:title="'Export accounts and aliases to CSV'|translate"
|
||||
@click="exportIdentities"
|
||||
>
|
||||
<v-icon>mdi-file-export-outline</v-icon>
|
||||
</v-btn>
|
||||
<v-menu offset-y>
|
||||
@@ -37,7 +45,7 @@
|
||||
>
|
||||
<account-creation-form @close="closeCreationWizard" @created="updateIdentities" />
|
||||
</v-dialog>
|
||||
<v-dialog
|
||||
<v-dialog
|
||||
v-model="showAliasCreationWizard"
|
||||
fullscreen
|
||||
scrollable
|
||||
@@ -46,24 +54,47 @@
|
||||
>
|
||||
<alias-creation-form @close="closeAliasWizard" @created="updateIdentities" />
|
||||
</v-dialog>
|
||||
<v-dialog v-model="showImportForm"
|
||||
persistent
|
||||
max-width="800px">
|
||||
<import-form
|
||||
ref="importForm"
|
||||
:title="'Import identities'|translate"
|
||||
@submit="importIdentities"
|
||||
@close="showImportForm = false"
|
||||
>
|
||||
<template v-slot:help>
|
||||
<ul>
|
||||
<li><em>account; loginname; password; first name; last name; enabled; group; address; quota; [, domain, ...]</em></li>
|
||||
<li><em>alias; address; enabled; recipient; recipient; ...</em></li>
|
||||
</ul>
|
||||
</template>
|
||||
</import-form>
|
||||
</v-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AccountCreationForm from '@/components/identities/AccountCreationForm'
|
||||
import AliasCreationForm from '@/components/identities/AliasCreationForm'
|
||||
import identities from '@/api/identities'
|
||||
import IdentityList from '@/components/identities/IdentityList'
|
||||
import { importExportMixin } from '@/mixins/importExport'
|
||||
import ImportForm from '@/components/tools/ImportForm'
|
||||
|
||||
export default {
|
||||
mixins: [importExportMixin],
|
||||
components: {
|
||||
AccountCreationForm,
|
||||
AliasCreationForm,
|
||||
IdentityList
|
||||
IdentityList,
|
||||
ImportForm
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
showAliasCreationWizard: false,
|
||||
showCreationWizard: false
|
||||
showCreationWizard: false,
|
||||
showImportForm: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -75,6 +106,14 @@ export default {
|
||||
},
|
||||
updateIdentities () {
|
||||
this.$refs.identities.fetchIdentities()
|
||||
},
|
||||
exportIdentities () {
|
||||
identities.exportAll().then(resp => {
|
||||
this.exportContent(resp.data, 'identities')
|
||||
})
|
||||
},
|
||||
importIdentities (data) {
|
||||
this.importContent(identities, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user