diff --git a/components/admin/Plugin.vue b/components/admin/Plugin.vue index 6d8a1ff0..966830dc 100644 --- a/components/admin/Plugin.vue +++ b/components/admin/Plugin.vue @@ -22,13 +22,14 @@ v-container v-select(v-if='setting.type === "LIST"' v-model='selectedPlugin.settingsValue[name]' :items='setting.items' :label='setting.description') v-switch(:label="$t('common.enable')" inset color='primary' v-model='selectedPlugin.settingsValue["enable"]') v-card-actions + v-btn(@click='testPlugin' outlined color='primary') {{ $t('common.test') }} v-spacer - v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.cancel') }} + v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.close') }} v-btn(@click='saveSettings' outlined color='primary' :loading='loading' :disable='!valid || loading') {{ $t('common.save') }} v-card-text - v-card(v-for='plugin in plugins' :key='plugin.name' max-width="400" elevation='10') + v-card(v-for='plugin in plugins' :key='plugin.name' max-width="400" outlined) v-card-title {{ plugin.name }} v-card-text p {{ plugin.description }} @@ -67,15 +68,19 @@ export default { ...mapActions(['setSetting']), async saveSettings() { this.loading = true - this.setSetting({ + await this.setSetting({ key: 'plugin_' + this.selectedPlugin.name, value: this.selectedPlugin.settingsValue }) this.loading = false this.dialog = false }, - async toggleEnable(plugin) { - await this.$axios.$put(`/plugin/${plugin.name}`) + async testPlugin() { + await this.saveSettings() + this.$axios.$post(`/plugin/test/${this.selectedPlugin.name}`) + }, + toggleEnable(plugin) { + this.$axios.$put(`/plugin/${plugin.name}`) }, setOptions(plugin) { this.selectedPlugin = plugin diff --git a/server/api/controller/plugins.js b/server/api/controller/plugins.js index 9a7e8c50..5d182613 100644 --- a/server/api/controller/plugins.js +++ b/server/api/controller/plugins.js @@ -32,6 +32,23 @@ const pluginController = { res.json() }, + async testPlugin (req, res) { + const pluginName = req.params.plugin + const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName) + if (!plugin) { + log.warn(`Plugin ${pluginName} not found`) + return res.sendStatus(404) + } + + if (typeof plugin.onTest !== 'function') { + log.warn(`Plugin ${pluginName} does not expose an 'onTest' function`) + return res.sendStatus(404) + } + + await plugin.onTest() + res.sendStatus(200) + }, + unloadPlugin(pluginName) { const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName) const settings = settingsController.settings['plugin_' + pluginName] diff --git a/server/api/index.js b/server/api/index.js index 01095006..ca6739b1 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -219,6 +219,7 @@ module.exports = () => { // - PLUGINS api.get('/plugins', isAdmin, pluginController.getAll) + api.post('/plugin/test/:plugin', isAdmin, pluginController.testPlugin) api.put('/plugin/:plugin', isAdmin, pluginController.togglePlugin) // OAUTH