Skip to content

Commit e43942b

Browse files
authored
Merge pull request #35 from NethServer/dev6896
Plugin validation in the UI NethServer/dev#6896
2 parents 32e793d + cb7aa37 commit e43942b

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

ui/public/i18n/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"upload_max_filesize_invalid_type": "Must be an integer",
3737
"configuring": "Configuring",
3838
"instance_configuration": "Configure Roundcube",
39-
"placeholder_plugins": "Plugins list (comma separated: plugin1,plugin2,plugin3)",
39+
"plugins_list": "Plugins list (one plugin per line)",
40+
"invalid_plugin": "Invalid plugin name: {plugin}",
4041
"choose_mail_server": "Select a domain",
4142
"choose_the_mail_server_to_use": "Choose the domain suffix used for both identifying and initializing the user account and their mail address preferences",
4243
"mail_server_is_not_valid": "This mail server cannot be used by Roundcube webmail",

ui/src/views/Settings.vue

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,20 @@
9898
<cv-accordion-item :open="toggleAccordion[0]">
9999
<template slot="title">{{ $t("settings.advanced") }}</template>
100100
<template slot="content">
101-
<cv-text-input
101+
<cv-text-area
102102
:label="$t('settings.plugins')"
103-
:placeholder="$t('settings.placeholder_plugins')"
104103
v-model.trim="plugins"
105-
class="mg-bottom"
106-
:invalid-message="$t(error.plugins)"
104+
:invalid-message="error.plugins"
105+
:helper-text="$t('settings.plugins_list')"
106+
:value="plugins"
107+
class="maxwidth textarea mg-left"
108+
ref="plugins"
109+
:placeholder="$t('settings.plugins_list')"
107110
:disabled="
108111
loading.getConfiguration || loading.configureModule
109112
"
110-
ref="plugins"
111113
>
112-
</cv-text-input>
114+
</cv-text-area>
113115
<cv-text-input
114116
:label="$t('settings.upload_max_filesize')"
115117
placeholder="5"
@@ -304,10 +306,14 @@ export default {
304306
});
305307
306308
this.mail_server_URL = config.mail_server_URL;
307-
this.plugins = config.plugins;
309+
this.plugins = config.plugins.split(",").join("\n");
308310
this.loading.getConfiguration = false;
309311
this.focusElement("host");
310312
},
313+
isValidPlugin(plugin) {
314+
const re = /^[a-zA-Z0-9-_]+$/;
315+
return re.test(plugin);
316+
},
311317
validateConfigureModule() {
312318
this.clearErrors(this);
313319
@@ -328,6 +334,24 @@ export default {
328334
}
329335
isValidationOk = false;
330336
}
337+
if (this.plugins) {
338+
// test if the plugins list is valid
339+
const plugins_list = this.plugins.split("\n");
340+
for (const plugin of plugins_list) {
341+
if (!this.isValidPlugin(plugin.trim())){
342+
this.toggleAccordion[0] = true;
343+
// set i18n error message and return plugin in object
344+
this.error.plugins = this.$t("settings.invalid_plugin", {
345+
plugin: plugin,
346+
});
347+
isValidationOk = false;
348+
if (isValidationOk) {
349+
this.focusElement("plugins");
350+
}
351+
break;
352+
}
353+
}
354+
}
331355
return isValidationOk;
332356
},
333357
configureModuleValidationFailed(validationErrors) {
@@ -386,7 +410,7 @@ export default {
386410
http2https: this.isHttpToHttpsEnabled,
387411
mail_server: mail_server_tmp,
388412
mail_domain: mail_domain_tmp,
389-
plugins: this.plugins,
413+
plugins: this.plugins.split("\n").join(",").trim().toLowerCase(),
390414
upload_max_filesize: parseInt(this.upload_max_filesize),
391415
},
392416
extra: {

0 commit comments

Comments
 (0)