Add rules for rendering settings. Do not render :proxy_remote setting if :uploader is set to Local

This commit is contained in:
Angelina Filippova 2020-12-28 02:41:37 +03:00
parent 0e36395a3e
commit 31863b7c49
2 changed files with 37 additions and 0 deletions

View file

@ -7,6 +7,7 @@
<div v-if="settingGroup.key === 'Pleroma.Emails.Mailer'"> <div v-if="settingGroup.key === 'Pleroma.Emails.Mailer'">
<div v-for="setting in settingGroup.children.filter(setting => !setting.group)" :key="setting.key"> <div v-for="setting in settingGroup.children.filter(setting => !setting.group)" :key="setting.key">
<inputs <inputs
v-if="followsRules(setting.key, settingGroup.key, state)"
:setting-group="settingGroup" :setting-group="settingGroup"
:setting="setting" :setting="setting"
:data="data"/> :data="data"/>
@ -15,6 +16,7 @@
v-for="setting in emailAdapterChildren" v-for="setting in emailAdapterChildren"
:key="setting.key"> :key="setting.key">
<inputs <inputs
v-if="followsRules(setting.key, settingGroup.key, state)"
:setting-group="settingGroup" :setting-group="settingGroup"
:setting="setting" :setting="setting"
:data="data"/> :data="data"/>
@ -24,6 +26,7 @@
<div v-for="setting in settingGroup.children" :key="setting.key"> <div v-for="setting in settingGroup.children" :key="setting.key">
<div v-if="!compound(setting)"> <div v-if="!compound(setting)">
<inputs <inputs
v-if="followsRules(setting.key, settingGroup.key, state)"
:setting-group="settingGroup" :setting-group="settingGroup"
:setting="setting" :setting="setting"
:data="data" :data="data"
@ -33,6 +36,7 @@
<el-divider v-if="divideSetting(setting.key)" class="divider"/> <el-divider v-if="divideSetting(setting.key)" class="divider"/>
<div v-if="!setting.children"> <div v-if="!setting.children">
<inputs <inputs
v-if="followsRules(setting.key, settingGroup.key, state)"
:setting-group="settingGroup" :setting-group="settingGroup"
:setting="setting" :setting="setting"
:data="data[setting.key]" :data="data[setting.key]"
@ -73,6 +77,7 @@ import Inputs from './Inputs'
import i18n from '@/lang' import i18n from '@/lang'
import _ from 'lodash' import _ from 'lodash'
import marked from 'marked' import marked from 'marked'
import { settingFollowsRules } from '../rules'
export default { export default {
name: 'Setting', name: 'Setting',
@ -109,6 +114,9 @@ export default {
}, },
loading() { loading() {
return this.$store.state.settings.loading return this.$store.state.settings.loading
},
state() {
return this.$store.state.settings.settings
} }
}, },
methods: { methods: {
@ -127,6 +135,9 @@ export default {
divideSetting(key) { divideSetting(key) {
return [':sslopts', ':tlsopts', ':adapter', ':poll_limits', ':queues', ':styling', ':invalidation', ':multi_factor_authentication'].includes(key) return [':sslopts', ':tlsopts', ':adapter', ':poll_limits', ':queues', ':styling', ':invalidation', ':multi_factor_authentication'].includes(key)
}, },
followsRules(setting, settingGroup, state) {
return settingFollowsRules(setting, settingGroup, state)
},
getFormattedDescription(desc) { getFormattedDescription(desc) {
return marked(desc) return marked(desc)
}, },

View file

@ -0,0 +1,26 @@
const rules = [{
name: 'renderIfNotEqual',
key: ':proxy_remote',
groupKey: 'Pleroma.Upload',
group: ':pleroma',
targetKey: ':uploader',
targetGroup: 'Pleroma.Upload',
notEqual: 'Pleroma.Uploaders.Local'
}]
const renderIfNotEqual = (state, { group, groupKey, targetKey, notEqual }) => {
return state[group][groupKey][targetKey] !== notEqual
}
const rulesMap = {
renderIfNotEqual
}
export const settingFollowsRules = (settingKey, settingGroupKey, state) => {
const rule = rules.find(rule => rule.groupKey === settingGroupKey && rule.key === settingKey)
if (!rule) return true
const ruleFn = rulesMap[rule.name]
if (!ruleFn) return true
return ruleFn(state, rule)
}