From 00dce737aea4d609e62a93a58e8a204d38d30e90 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Thu, 26 Dec 2019 20:50:56 +0300 Subject: [PATCH] Fix deleting settings when changing between mailer adapters --- src/api/settings.js | 10 ++++++++++ src/store/modules/settings.js | 18 +++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/api/settings.js b/src/api/settings.js index 24f40367..c1bbb182 100644 --- a/src/api/settings.js +++ b/src/api/settings.js @@ -30,6 +30,16 @@ export async function updateSettings(configs, authHost, token) { }) } +export async function removeSettings(configs, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/config`, + method: 'post', + headers: authHeaders(token), + data: { configs } + }) +} + export async function uploadMedia(file, authHost, token) { const formData = new FormData() formData.append('file', file) diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 68bed86c..f7d1df79 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,4 +1,4 @@ -import { fetchDescription, fetchSettings, updateSettings, uploadMedia } from '@/api/settings' +import { fetchDescription, fetchSettings, removeSettings, updateSettings, uploadMedia } from '@/api/settings' import { parseNonTuples, parseTuples, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers' const settings = { @@ -27,9 +27,6 @@ const settings = { CLEAR_UPDATED_SETTINGS: (state) => { state.updatedSettings = {} }, - REWRITE_CONFIG: (state, { tab, data }) => { - state.settings[tab] = data - }, SET_DESCRIPTION: (state, data) => { state.description = data }, @@ -69,8 +66,8 @@ const settings = { commit('SET_SETTINGS', response.data.configs) commit('SET_LOADING', false) }, - RewriteConfig({ commit }, { tab, data }) { - commit('REWRITE_CONFIG', { tab, data }) + async RemoveSetting({ getters }, configs) { + await removeSettings(configs, getters.authHost, getters.token) }, async SubmitChanges({ getters, commit, state }) { const updatedData = Object.keys(state.updatedSettings).reduce((acc, group) => { @@ -103,7 +100,14 @@ const settings = { ? commit('UPDATE_SETTINGS', { group, key, input, value, type }) : commit('UPDATE_SETTINGS', { group, key: input, input: '_value', value, type }) }, - UpdateState({ commit }, { group, key, input, value }) { + UpdateState({ commit, dispatch, state }, { group, key, input, value }) { + if (key === 'Pleroma.Emails.Mailer' && input === ':adapter') { + const subkeys = Object.keys(state.settings[group][key]).filter(el => el !== ':adapter') + const emailsValue = subkeys.map(el => { + return { 'tuple': [el, state.settings[group][key][el]] } + }) + dispatch('RemoveSetting', [{ group, key, value: emailsValue, delete: true, subkeys }]) + } key ? commit('UPDATE_STATE', { group, key, input, value }) : commit('UPDATE_STATE', { group, key: input, input: 'value', value })