forked from AkkomaGang/admin-fe
Remove partial update check
This commit is contained in:
parent
3cc934efdc
commit
b36e8693b5
3 changed files with 3 additions and 78 deletions
|
@ -9,28 +9,6 @@ export const getBooleanValue = value => {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
export const checkPartialUpdate = (settings, updatedSettings, description) => {
|
|
||||||
return Object.keys(updatedSettings).reduce((acc, group) => {
|
|
||||||
acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => {
|
|
||||||
if (!partialUpdate(group, key)) {
|
|
||||||
const updated = Object.keys(settings[group][key]).reduce((acc, settingName) => {
|
|
||||||
const setting = description
|
|
||||||
.find(element => element.group === group && element.key === key).children
|
|
||||||
.find(child => child.key === settingName)
|
|
||||||
const type = setting ? setting.type : ''
|
|
||||||
acc[settingName] = [type, settings[group][key][settingName]]
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
acc[key] = updated
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
acc[key] = updatedSettings[group][key]
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCurrentValue = (type, value, path) => {
|
const getCurrentValue = (type, value, path) => {
|
||||||
if (type === 'state') {
|
if (type === 'state') {
|
||||||
return _.get(value, path)
|
return _.get(value, path)
|
||||||
|
@ -154,10 +132,6 @@ const parseProxyUrl = value => {
|
||||||
return { socks5: false, host: null, port: null }
|
return { socks5: false, host: null, port: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
const partialUpdate = (group, key) => {
|
|
||||||
return !(group === ':auto_linker' && key === ':opts')
|
|
||||||
}
|
|
||||||
|
|
||||||
export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => {
|
export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => {
|
||||||
const [{ key, type }, ...otherParents] = parents
|
const [{ key, type }, ...otherParents] = parents
|
||||||
const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)]
|
const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { fetchDescription, fetchSettings, removeSettings, updateSettings } from '@/api/settings'
|
import { fetchDescription, fetchSettings, removeSettings, updateSettings } from '@/api/settings'
|
||||||
import { checkPartialUpdate, formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
|
import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
const settings = {
|
const settings = {
|
||||||
|
@ -101,9 +101,8 @@ const settings = {
|
||||||
commit('SET_ACTIVE_TAB', tab)
|
commit('SET_ACTIVE_TAB', tab)
|
||||||
},
|
},
|
||||||
async SubmitChanges({ getters, commit, state }) {
|
async SubmitChanges({ getters, commit, state }) {
|
||||||
const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description)
|
const configs = Object.keys(state.updatedSettings).reduce((acc, group) => {
|
||||||
const configs = Object.keys(updatedData).reduce((acc, group) => {
|
return [...acc, ...wrapUpdatedSettings(group, state.updatedSettings[group], state.settings)]
|
||||||
return [...acc, ...wrapUpdatedSettings(group, updatedData[group], state.settings)]
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
await updateSettings(configs, getters.authHost, getters.token)
|
await updateSettings(configs, getters.authHost, getters.token)
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
import { checkPartialUpdate } from '@/store/modules/normalizers'
|
|
||||||
import _ from 'lodash'
|
|
||||||
|
|
||||||
describe('Partial update', () => {
|
|
||||||
it('partial update for settings that do not allow partial update', () => {
|
|
||||||
const settings = { ':auto_linker': { ':opts':
|
|
||||||
{ ':strip_prefix': true, ':new_window': false, ':rel': 'ugc', ':truncate': 3 }
|
|
||||||
}}
|
|
||||||
const updatedSettings = { ':auto_linker': { ':opts': { ':new_window': false }}}
|
|
||||||
const description = [{
|
|
||||||
children: [
|
|
||||||
{ key: ':strip_prefix', type: 'boolean' },
|
|
||||||
{ key: ':truncate', type: ['integer', false] },
|
|
||||||
{ key: ':new_window', type: 'boolean' }],
|
|
||||||
description: 'Configuration for the auto_linker library',
|
|
||||||
group: ':auto_linker',
|
|
||||||
key: ':opts',
|
|
||||||
label: 'Opts',
|
|
||||||
type: 'group'
|
|
||||||
}]
|
|
||||||
|
|
||||||
const expectedData = { ':auto_linker': { ':opts': {
|
|
||||||
':strip_prefix': ['boolean', true],
|
|
||||||
':new_window': ['boolean', false],
|
|
||||||
':rel': ['', 'ugc'],
|
|
||||||
':truncate': [['integer', false], 3]
|
|
||||||
}}}
|
|
||||||
const updatedData = checkPartialUpdate(settings, updatedSettings, description)
|
|
||||||
expect(_.isEqual(updatedData, expectedData)).toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('partial update for settings that allow partial update', () => {
|
|
||||||
const settings = { ':pleroma': { 'Pleroma.Captcha': { ':enabled': true, ':seconds_valid': 70, ':method': 'Pleroma.Captcha.Kocaptcha' }}}
|
|
||||||
const updatedSettings = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}}
|
|
||||||
const description = [{
|
|
||||||
children: [],
|
|
||||||
description: 'Captcha-related settings',
|
|
||||||
group: ':pleroma',
|
|
||||||
key: 'Pleroma.Captcha',
|
|
||||||
label: 'Pleroma.Captcha',
|
|
||||||
type: 'group'
|
|
||||||
}]
|
|
||||||
|
|
||||||
const expectedData = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}}
|
|
||||||
const updatedData = checkPartialUpdate(settings, updatedSettings, description)
|
|
||||||
expect(_.isEqual(updatedData, expectedData)).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
Loading…
Reference in a new issue