Merge pull request #362 from YunoHost/fix-quota-edit

[fix] Empty quota doesn't work
This commit is contained in:
Alexandre Aubin 2021-05-23 23:37:50 +02:00 committed by GitHub
commit 36d6ee67c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -139,7 +139,7 @@ export default {
form: { form: {
fullname: { firstname: '', lastname: '' }, fullname: { firstname: '', lastname: '' },
mail: { localPart: '', separator: '@', domain: '' }, mail: { localPart: '', separator: '@', domain: '' },
mailbox_quota: 0, mailbox_quota: '',
mail_aliases: [], mail_aliases: [],
mail_forward: [], mail_forward: [],
password: '', password: '',
@ -183,8 +183,7 @@ export default {
example: this.$i18n.t('mailbox_quota_example'), example: this.$i18n.t('mailbox_quota_example'),
props: { props: {
id: 'mailbox-quota', id: 'mailbox-quota',
placeholder: this.$i18n.t('mailbox_quota_placeholder'), placeholder: this.$i18n.t('mailbox_quota_placeholder')
type: 'number'
} }
}, },
@ -228,7 +227,7 @@ export default {
mail: { mail: {
localPart: { required, email: emailLocalPart } localPart: { required, email: emailLocalPart }
}, },
mailbox_quota: { number: required, integer, minValue: minValue(0) }, mailbox_quota: { integer, minValue: minValue(0) },
mail_aliases: { mail_aliases: {
$each: { $each: {
localPart: { required, email: emailLocalPart } localPart: { required, email: emailLocalPart }
@ -259,8 +258,11 @@ export default {
if (user['mail-forward']) { if (user['mail-forward']) {
this.form.mail_forward = user['mail-forward'].slice() // Copy value this.form.mail_forward = user['mail-forward'].slice() // Copy value
} }
if (user['mailbox-quota'].limit !== 'No quota') { // mailbox-quota could be 'No quota' or 'Pas de quota'...
if (parseInt(user['mailbox-quota'].limit) > 0) {
this.form.mailbox_quota = sizeToM(user['mailbox-quota'].limit) this.form.mailbox_quota = sizeToM(user['mailbox-quota'].limit)
} else {
this.form.mailbox_quota = ''
} }
}, },
@ -268,7 +270,9 @@ export default {
const formData = formatFormData(this.form, { flatten: true }) const formData = formatFormData(this.form, { flatten: true })
const user = this.user(this.name) const user = this.user(this.name)
const data = {} const data = {}
if (!Object.prototype.hasOwnProperty.call(formData, 'mailbox_quota')) {
formData.mailbox_quota = ''
}
for (const key of ['mail_aliases', 'mail_forward']) { for (const key of ['mail_aliases', 'mail_forward']) {
const dashedKey = key.replace('_', '-') const dashedKey = key.replace('_', '-')
const newKey = key.replace('_', '').replace('es', '') const newKey = key.replace('_', '').replace('es', '')
@ -280,9 +284,9 @@ export default {
for (const key in formData) { for (const key in formData) {
if (key === 'mailbox_quota') { if (key === 'mailbox_quota') {
const quota = parseInt(formData[key]) !== 0 ? formData[key] + 'M' : 'No quota' const quota = parseInt(formData[key]) > 0 ? formData[key] + 'M' : 'No quota'
if (quota !== user['mailbox-quota'].limit) { if (parseInt(quota) !== parseInt(user['mailbox-quota'].limit)) {
data[key] = quota === 'No quota' ? 0 : quota data[key] = quota === 'No quota' ? '0' : quota
} }
} else if (!key.includes('mail_') && formData[key] !== user[key]) { } else if (!key.includes('mail_') && formData[key] !== user[key]) {
data[key] = formData[key] data[key] = formData[key]