diff --git a/CHANGELOG.md b/CHANGELOG.md index f1146591..c160a876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/src/views/settings/components/Setting.vue b/src/views/settings/components/Setting.vue index 7593fb3d..28080b21 100644 --- a/src/views/settings/components/Setting.vue +++ b/src/views/settings/components/Setting.vue @@ -7,6 +7,7 @@
@@ -15,6 +16,7 @@ v-for="setting in emailAdapterChildren" :key="setting.key"> @@ -24,6 +26,7 @@
{ + 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) +} diff --git a/test/views/settings/settingFollowsRules.test.js b/test/views/settings/settingFollowsRules.test.js new file mode 100644 index 00000000..a67745c2 --- /dev/null +++ b/test/views/settings/settingFollowsRules.test.js @@ -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() + }) +}) \ No newline at end of file