From 30f4e9777b157fe7023a9cf02c7d53737d2e2974 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Mon, 19 Sep 2022 17:02:28 +0300 Subject: upd syslog and smtp --- src/store/modules/Settings/SmtpStore.js | 74 ++++++++++++++++++++++++++++--- src/store/modules/Settings/SyslogStore.js | 36 +++++++++++++++ 2 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 src/store/modules/Settings/SyslogStore.js (limited to 'src/store/modules/Settings') diff --git a/src/store/modules/Settings/SmtpStore.js b/src/store/modules/Settings/SmtpStore.js index 88fad25c..195f245a 100644 --- a/src/store/modules/Settings/SmtpStore.js +++ b/src/store/modules/Settings/SmtpStore.js @@ -3,22 +3,72 @@ import i18n from '@/i18n'; const SmtpStore = { namespaced: true, - state: { smtp: {} }, - getters: { smtpSettings: (state) => state.smtp }, + state: { + settings: {}, + subscribers: [], + }, + getters: { + settings: (state) => state.settings, + subscribers: (state) => state.subscribers, + }, mutations: { - saveSmtpSettings: (state, data) => (state.smtp = data), + saveSettings: (state, data) => (state.settings = data), + setSubscribers: (state, data) => (state.subscribers = data), }, actions: { - async setSmtpSettings({ commit }, payload) { - let url = `/redfish/v1/Smtp/ChangeParameters`; + async deleteSubscriber({ dispatch }, email) { + return await api + .get(`/redfish/v1/Smtp/DeleteMails&${email}`) + .then(async () => { + await dispatch('getSubscribers'); + return i18n.t('pageTransfer.smtp.deleteSubscriberSuсcess'); + }) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageTransfer.smtp.deleteSubscriberError')); + }); + }, + + async addSubscriber({ dispatch }, payload) { + return await api + .get(`/redfish/v1/Smtp/AddMails&${payload.email}`) + .then(async () => { + await dispatch('getSubscribers'); + return i18n.t('pageTransfer.smtp.saveSubscriberSuсcess'); + }) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageTransfer.smtp.saveSubscriberError')); + }); + }, + + async getSubscribers({ commit }) { + return await api + .get('/redfish/v1/Smtp/GetMails') + .then(({ data: { mails = [] } = {} }) => + mails.map((host) => { + return { + host, + }; + }) + ) + .then((subscribers) => commit('setSubscribers', subscribers)) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageUserManagement.toast.errorLoadUsers')); + }); + }, + + async setSettings({ dispatch }, payload) { + let url = `/redfish/v1/Smtp/SetSettings`; for (let key in payload) { url += `&${key}=${payload[key]}`; } return await api .get(url) - .then(() => { - commit('saveSmtpSettings', payload); + .then(async () => { + await dispatch('getSettings'); return i18n.t('pageTransfer.saveSmtpSuсcess'); }) .catch((error) => { @@ -26,6 +76,16 @@ const SmtpStore = { throw new Error(i18n.t('pageTransfer.saveSmtpError')); }); }, + + async getSettings({ commit }) { + return await api + .get('/redfish/v1/Smtp/GetSettings') + .then(({ data = {} }) => { + commit('saveSettings', data); + }) + .catch((error) => console.log(error)); + }, + async sendTestMessage(_, payload) { let url = `/redfish/v1/Smtp/SendMail`; for (let key in payload) { diff --git a/src/store/modules/Settings/SyslogStore.js b/src/store/modules/Settings/SyslogStore.js new file mode 100644 index 00000000..f0b0eb59 --- /dev/null +++ b/src/store/modules/Settings/SyslogStore.js @@ -0,0 +1,36 @@ +import api from '@/store/api'; +import i18n from '@/i18n'; + +const SyslogStore = { + namespaced: true, + state: { settings: {} }, + getters: { settings: (state) => state.settings }, + mutations: { + saveSettings: (state, data) => (state.settings = data), + }, + actions: { + async saveSettings({ dispatch }, payload) { + return await api + .post('/redfish/v1/Syslog/Actions/Syslog.UpdateConfig', payload) + .then(async () => { + await dispatch('getSettings'); + return i18n.t('pageTransfer.syslog.saveSettingsSuсcess'); + }) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageTransfer.syslog.saveSettingsError')); + }); + }, + + async getSettings({ commit }) { + return await api + .get('/redfish/v1/Syslog') + .then(({ data: { Configuration = {} } = {} }) => { + commit('saveSettings', Configuration); + }) + .catch((error) => console.log(error)); + }, + }, +}; + +export default SyslogStore; -- cgit v1.2.3