mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Few fixes
This commit is contained in:
+2
-2
@@ -3,7 +3,7 @@ version: '3'
|
||||
services:
|
||||
api:
|
||||
container_name: modoboa_api
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile.dev
|
||||
@@ -24,7 +24,7 @@ services:
|
||||
|
||||
front:
|
||||
container_name: modoboa_front
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile.front.dev
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
<validation-observer ref="observer">
|
||||
<validation-provider
|
||||
v-slot="{ errors }"
|
||||
rules="required"
|
||||
rules=""
|
||||
vid="initialdomain"
|
||||
>
|
||||
<v-text-field
|
||||
ref="initialdomainField"
|
||||
v-model="domain.initialdomain"
|
||||
:error-messages="errors"
|
||||
:placeholder="'provider.domain' | translate"
|
||||
:placeholder="'Name of the domain to migrate' | translate"
|
||||
outlined
|
||||
dense
|
||||
@input="update"
|
||||
@@ -18,14 +18,16 @@
|
||||
</validation-provider>
|
||||
<validation-provider
|
||||
v-slot="{ errors }"
|
||||
rules="required"
|
||||
rules=""
|
||||
vid="new_domain"
|
||||
>
|
||||
<v-text-field
|
||||
ref="newdomainField"
|
||||
<v-autocomplete
|
||||
v-model="domain.new_domain"
|
||||
:error-messages="errors"
|
||||
:placeholder="'local.domain' | translate"
|
||||
:label="'Local domain (optional)'|translate"
|
||||
:items="localDomains"
|
||||
item-text="name"
|
||||
return-object
|
||||
outlined
|
||||
dense
|
||||
@input="update"
|
||||
@@ -47,17 +49,17 @@
|
||||
@click:close="removeDomain(index)"
|
||||
>
|
||||
<template v-if="domain.new_domain">
|
||||
{{domain.name}} --> {{domain.new_domain}}
|
||||
{{domain.name}} --> {{domain.new_domain.name}}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{domain.name}} --> {{domain.name}}
|
||||
{{domain.name}}
|
||||
</template>
|
||||
</v-chip>
|
||||
</validation-observer>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import domainsApi from '@/api/domains'
|
||||
import providerApi from '@/api/imap_migration/providers'
|
||||
|
||||
export default {
|
||||
@@ -68,7 +70,8 @@ export default {
|
||||
domain: {
|
||||
initialdomain: '',
|
||||
new_domain: ''
|
||||
}
|
||||
},
|
||||
localDomains: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -94,8 +97,11 @@ export default {
|
||||
new_domain: this.domain.new_domain
|
||||
})
|
||||
this.$emit('input', this.domains)
|
||||
this.$refs.initialdomainField.reset()
|
||||
this.$refs.newdomainField.reset()
|
||||
this.$refs.observer.reset()
|
||||
this.domain = {
|
||||
initialdomain: '',
|
||||
new_domain: ''
|
||||
}
|
||||
}
|
||||
}).catch(error => {
|
||||
this.$refs.observer.setErrors(error.response.data)
|
||||
@@ -115,6 +121,11 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
domainsApi.getDomains().then(resp => {
|
||||
this.localDomains = resp.data
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
value: {
|
||||
handler: function (newValue) {
|
||||
|
||||
@@ -33,12 +33,15 @@ export default {
|
||||
ProviderGeneralForm
|
||||
},
|
||||
computed: {
|
||||
formatAssociatedDomains () {
|
||||
let associatedDomains = ''
|
||||
associatedDomainsSummary () {
|
||||
const result = []
|
||||
for (const domain of this.provider.domains) {
|
||||
associatedDomains += `${domain.name} => ${domain.new_domain}, `
|
||||
const value = domain.new_domain ? `${domain.name} => ${domain.new_domain.name}` : domain.name
|
||||
result.push(
|
||||
{ key: '', value }
|
||||
)
|
||||
}
|
||||
return associatedDomains
|
||||
return result
|
||||
},
|
||||
summarySections () {
|
||||
const result = [
|
||||
@@ -53,9 +56,7 @@ export default {
|
||||
},
|
||||
{
|
||||
title: this.$gettext('Associated domains'),
|
||||
items: [
|
||||
{ key: this.$gettext('Perform a connection check'), value: this.formatAssociatedDomains }
|
||||
]
|
||||
items: this.associatedDomainsSummary
|
||||
}
|
||||
]
|
||||
return result
|
||||
@@ -103,9 +104,19 @@ export default {
|
||||
|
||||
},
|
||||
submit () {
|
||||
const data = JSON.parse(JSON.stringify(this.provider))
|
||||
console.log(this.provider)
|
||||
this.$store.dispatch('providers/createProvider', data).then(resp => {
|
||||
const data = { ...this.provider }
|
||||
data.domains = []
|
||||
for (const domain of this.provider.domains) {
|
||||
if (domain.new_domain) {
|
||||
data.domains.push({
|
||||
name: domain.name,
|
||||
new_domain: domain.new_domain.pk
|
||||
})
|
||||
} else {
|
||||
data.domains.push(domain)
|
||||
}
|
||||
}
|
||||
this.$store.dispatch('providers/createProvider', data).then(() => {
|
||||
bus.$emit('notification', { msg: this.$gettext('Provider created') })
|
||||
this.close()
|
||||
})
|
||||
|
||||
@@ -107,9 +107,22 @@ export default {
|
||||
}
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(JSON.stringify(this.editedProvider))
|
||||
await providers.patch(this.editedProvider.id, data).then(resp => {
|
||||
const data = { ...this.editedProvider }
|
||||
data.domains = []
|
||||
for (const domain of this.provider.domains) {
|
||||
if (domain.new_domain) {
|
||||
data.domains.push({
|
||||
name: domain.name,
|
||||
new_domain: domain.new_domain.pk || domain.new_domain.id
|
||||
})
|
||||
} else {
|
||||
data.domains.push(domain)
|
||||
}
|
||||
}
|
||||
await providers.patchProvider(this.editedProvider.id, data).then(() => {
|
||||
bus.$emit('notification', { msg: this.$gettext('Provider updated') })
|
||||
this.$store.dispatch('providers/getProviders')
|
||||
this.$router.push({ name: 'ProvidersList' })
|
||||
})
|
||||
} catch (error) {
|
||||
if (this.$refs.generalForm) {
|
||||
|
||||
@@ -124,9 +124,13 @@ export default {
|
||||
this.$emit('input', this.form)
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.form = { ...this.value }
|
||||
console.error(this.value)
|
||||
watch: {
|
||||
value: {
|
||||
handler (newValue) {
|
||||
this.form = { ...newValue }
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
:key="index"
|
||||
>
|
||||
<template v-if="domain.new_domain">
|
||||
{{domain.name}} --> {{domain.new_domain}}
|
||||
{{domain.name}} --> {{domain.new_domain.name}}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{domain.name}} --> {{domain.name}}
|
||||
|
||||
@@ -205,7 +205,7 @@ export default {
|
||||
children: [
|
||||
{
|
||||
text: this.$gettext('Email providers'),
|
||||
to: { name: 'ProvdiersList' },
|
||||
to: { name: 'ProvidersList' },
|
||||
roles: ['SuperAdmins', 'Resellers']
|
||||
},
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ const routes = [
|
||||
},
|
||||
{
|
||||
path: '/imap_migration/providers',
|
||||
name: 'ProvdiersList',
|
||||
name: 'ProvidersList',
|
||||
component: () => import('../views/imap_migration/Providers.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
|
||||
@@ -116,9 +116,6 @@ class DomainAliasSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = admin_models.DomainAlias
|
||||
fields = ("pk", "name", "target", "enabled", )
|
||||
expandable_fields = {
|
||||
"target": DomainSerializer
|
||||
}
|
||||
|
||||
def validate_target(self, value):
|
||||
"""Check target domain."""
|
||||
|
||||
@@ -13,11 +13,7 @@ class EmailProviderDomainSerializer(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField(required=False)
|
||||
|
||||
class Meta:
|
||||
extra_kwargs = {
|
||||
"name": {
|
||||
"validators": []
|
||||
}
|
||||
}
|
||||
depth = 1
|
||||
fields = ("id", "name", "new_domain")
|
||||
model = models.EmailProviderDomain
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
"""APIv2 serializers."""
|
||||
"""API v2 serializers."""
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from modoboa.admin.models.domain import Domain
|
||||
|
||||
|
||||
@@ -37,13 +39,14 @@ class CheckAssociatedDomainSerializer(serializers.Serializer):
|
||||
"""A serializer for checking associated domains."""
|
||||
|
||||
initialdomain = serializers.CharField()
|
||||
new_domain = serializers.CharField()
|
||||
|
||||
def validate(self, data):
|
||||
if data["initialdomain"] != data["new_domain"]:
|
||||
if not Domain.objects.filter(name=data["initialdomain"]):
|
||||
raise ValidationError({"new_domain": [
|
||||
_("You must create the local domain first.")]
|
||||
})
|
||||
return data
|
||||
new_domain = serializers.PrimaryKeyRelatedField(
|
||||
read_only=True, required=False)
|
||||
|
||||
def validate_new_domain(self, value):
|
||||
domain_ids = (
|
||||
Domain.objects.get_for_admin(self.context["request"].user)
|
||||
.values_list("id", flat=True)
|
||||
)
|
||||
if value not in domain_ids:
|
||||
raise serializers.ValidationError(_("Access denied"))
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user