Skip to content

Commit

Permalink
Merge pull request #35 from NethServer/dev6896
Browse files Browse the repository at this point in the history
Plugin validation in the UI NethServer/dev#6896
  • Loading branch information
stephdl authored Mar 21, 2024
2 parents 32e793d + cb7aa37 commit e43942b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ui/public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"upload_max_filesize_invalid_type": "Must be an integer",
"configuring": "Configuring",
"instance_configuration": "Configure Roundcube",
"placeholder_plugins": "Plugins list (comma separated: plugin1,plugin2,plugin3)",
"plugins_list": "Plugins list (one plugin per line)",
"invalid_plugin": "Invalid plugin name: {plugin}",
"choose_mail_server": "Select a domain",
"choose_the_mail_server_to_use": "Choose the domain suffix used for both identifying and initializing the user account and their mail address preferences",
"mail_server_is_not_valid": "This mail server cannot be used by Roundcube webmail",
Expand Down
40 changes: 32 additions & 8 deletions ui/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,20 @@
<cv-accordion-item :open="toggleAccordion[0]">
<template slot="title">{{ $t("settings.advanced") }}</template>
<template slot="content">
<cv-text-input
<cv-text-area
:label="$t('settings.plugins')"
:placeholder="$t('settings.placeholder_plugins')"
v-model.trim="plugins"
class="mg-bottom"
:invalid-message="$t(error.plugins)"
:invalid-message="error.plugins"
:helper-text="$t('settings.plugins_list')"
:value="plugins"
class="maxwidth textarea mg-left"
ref="plugins"
:placeholder="$t('settings.plugins_list')"
:disabled="
loading.getConfiguration || loading.configureModule
"
ref="plugins"
>
</cv-text-input>
</cv-text-area>
<cv-text-input
:label="$t('settings.upload_max_filesize')"
placeholder="5"
Expand Down Expand Up @@ -304,10 +306,14 @@ export default {
});

this.mail_server_URL = config.mail_server_URL;
this.plugins = config.plugins;
this.plugins = config.plugins.split(",").join("\n");
this.loading.getConfiguration = false;
this.focusElement("host");
},
isValidPlugin(plugin) {
const re = /^[a-zA-Z0-9-_]+$/;
return re.test(plugin);
},
validateConfigureModule() {
this.clearErrors(this);

Expand All @@ -328,6 +334,24 @@ export default {
}
isValidationOk = false;
}
if (this.plugins) {
// test if the plugins list is valid
const plugins_list = this.plugins.split("\n");
for (const plugin of plugins_list) {
if (!this.isValidPlugin(plugin.trim())){
this.toggleAccordion[0] = true;
// set i18n error message and return plugin in object
this.error.plugins = this.$t("settings.invalid_plugin", {
plugin: plugin,
});
isValidationOk = false;
if (isValidationOk) {
this.focusElement("plugins");
}
break;
}
}
}
return isValidationOk;
},
configureModuleValidationFailed(validationErrors) {
Expand Down Expand Up @@ -386,7 +410,7 @@ export default {
http2https: this.isHttpToHttpsEnabled,
mail_server: mail_server_tmp,
mail_domain: mail_domain_tmp,
plugins: this.plugins,
plugins: this.plugins.split("\n").join(",").trim().toLowerCase(),
upload_max_filesize: parseInt(this.upload_max_filesize),
},
extra: {
Expand Down

0 comments on commit e43942b

Please sign in to comment.