adds a way to test plugins settings from admin

This commit is contained in:
lesion 2023-05-04 23:53:52 +02:00
parent d1c48f770e
commit 2f3868354b
No known key found for this signature in database
GPG key ID: 352918250B012177
3 changed files with 28 additions and 5 deletions

View file

@ -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

View file

@ -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]

View file

@ -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