forked from AkkomaGang/admin-fe
Merge branch 'feature/hide-proxy-remote' into 'develop'
Ability to set rules and conditions for rendering settings See merge request pleroma/admin-fe!190
This commit is contained in:
commit
87e1ee4e21
4 changed files with 73 additions and 1 deletions
|
@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Filter users by actor type: Person, Bot or Application
|
||||
- Add ability to configure Media Preview Proxy, User Backup, Websocket based federation and Pleroma.Web.Endpoint.MetricsExporter settings
|
||||
- Mobile and Tablet UI for Single Report show page
|
||||
|
||||
- Ability to set rules and conditions for rendering settings (e.g. `:proxy_remote` setting is hidden if `:uploader` setting is set to `Pleroma.Uploaders.Local`)
|
||||
### Changed
|
||||
|
||||
- **Breaking**: AdminAPI changed User field `confirmation_pending` to `is_confirmed`
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<div v-if="settingGroup.key === 'Pleroma.Emails.Mailer'">
|
||||
<div v-for="setting in settingGroup.children.filter(setting => !setting.group)" :key="setting.key">
|
||||
<inputs
|
||||
v-if="followsRules(setting.key, settingGroup.key, state)"
|
||||
:setting-group="settingGroup"
|
||||
:setting="setting"
|
||||
:data="data"/>
|
||||
|
@ -15,6 +16,7 @@
|
|||
v-for="setting in emailAdapterChildren"
|
||||
:key="setting.key">
|
||||
<inputs
|
||||
v-if="followsRules(setting.key, settingGroup.key, state)"
|
||||
:setting-group="settingGroup"
|
||||
:setting="setting"
|
||||
:data="data"/>
|
||||
|
@ -24,6 +26,7 @@
|
|||
<div v-for="setting in settingGroup.children" :key="setting.key">
|
||||
<div v-if="!compound(setting)">
|
||||
<inputs
|
||||
v-if="followsRules(setting.key, settingGroup.key, state)"
|
||||
:setting-group="settingGroup"
|
||||
:setting="setting"
|
||||
:data="data"
|
||||
|
@ -33,6 +36,7 @@
|
|||
<el-divider v-if="divideSetting(setting.key)" class="divider"/>
|
||||
<div v-if="!setting.children">
|
||||
<inputs
|
||||
v-if="followsRules(setting.key, settingGroup.key, state)"
|
||||
:setting-group="settingGroup"
|
||||
:setting="setting"
|
||||
:data="data[setting.key]"
|
||||
|
@ -73,6 +77,7 @@ import Inputs from './Inputs'
|
|||
import i18n from '@/lang'
|
||||
import _ from 'lodash'
|
||||
import marked from 'marked'
|
||||
import { settingFollowsRules } from '../rules'
|
||||
|
||||
export default {
|
||||
name: 'Setting',
|
||||
|
@ -109,6 +114,9 @@ export default {
|
|||
},
|
||||
loading() {
|
||||
return this.$store.state.settings.loading
|
||||
},
|
||||
state() {
|
||||
return this.$store.state.settings.settings
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -127,6 +135,9 @@ export default {
|
|||
divideSetting(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) {
|
||||
return marked(desc)
|
||||
},
|
||||
|
|
26
src/views/settings/rules.js
Normal file
26
src/views/settings/rules.js
Normal 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)
|
||||
}
|
35
test/views/settings/settingFollowsRules.test.js
Normal file
35
test/views/settings/settingFollowsRules.test.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { settingFollowsRules } from '@/views/settings/rules'
|
||||
|
||||
describe('Check if settings follow rules', () => {
|
||||
it('does not render :proxy_remote when local :uploader is selected', () => {
|
||||
const state = { ':pleroma': { 'Pleroma.Upload': { ':uploader': 'Pleroma.Uploaders.Local' }}}
|
||||
|
||||
expect(settingFollowsRules(':proxy_remote', 'Pleroma.Upload', state)).toBeFalsy()
|
||||
})
|
||||
|
||||
it('render :proxy_remote when local :uploader is not selected', () => {
|
||||
const state = { ':pleroma': { 'Pleroma.Upload': { ':uploader': 'Pleroma.Uploaders.S3' }}}
|
||||
|
||||
expect(settingFollowsRules(':proxy_remote', 'Pleroma.Upload', state)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('render setting when there is no rule', () => {
|
||||
const state = { ':pleroma': { 'Pleroma.Upload': { ':uploader': 'Pleroma.Uploaders.Local' }}}
|
||||
|
||||
expect(settingFollowsRules(':filters', 'Pleroma.Upload', state)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('render setting when one of the keys is undefined', () => {
|
||||
const state = { ':pleroma': {}}
|
||||
|
||||
expect(settingFollowsRules(':level', undefined, state)).toBeTruthy()
|
||||
|
||||
expect(settingFollowsRules(':admin_token', undefined, state)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('render setting when state is empty', () => {
|
||||
const state = { ':pleroma': { 'Pleroma.Upload': {}}}
|
||||
|
||||
expect(settingFollowsRules(':proxy_remote', 'Pleroma.Upload', state)).toBeTruthy()
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue