From 7dc22774532872fc99aa7768cf299ab623e9d155 Mon Sep 17 00:00:00 2001
From: tusooa <tusooa@kazv.moe>
Date: Mon, 9 Jan 2023 13:02:16 -0500
Subject: Use stylelint

---
 src/components/settings_modal/helpers/choice_setting.vue | 5 -----
 1 file changed, 5 deletions(-)

(limited to 'src/components/settings_modal/helpers/choice_setting.vue')

diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue
index d141a0d6..8fdbb5d3 100644
--- a/src/components/settings_modal/helpers/choice_setting.vue
+++ b/src/components/settings_modal/helpers/choice_setting.vue
@@ -28,8 +28,3 @@
 </template>
 
 <script src="./choice_setting.js"></script>
-
-<style lang="scss">
-.ChoiceSetting {
-}
-</style>
-- 
cgit v1.2.3-70-g09d2


From af0cd5422304d7b2111739d85c279b3fa175a853 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Sun, 12 Mar 2023 14:32:13 +0200
Subject: serverSideConfig renamed into profileSettingConfig to avoid confusion
 with serverSideStorage, reduced overall need for SharedComputedObject in
 settings tabs, moved copypaste code of "setting" type of helpers into a
 separate file.

---
 .../settings_modal/helpers/boolean_setting.js      |  53 +-------
 .../settings_modal/helpers/boolean_setting.vue     |   4 +-
 .../settings_modal/helpers/choice_setting.js       |  51 ++------
 .../settings_modal/helpers/choice_setting.vue      |   2 +-
 .../settings_modal/helpers/integer_setting.js      |  39 +-----
 .../helpers/profile_setting_indicator.vue          |  51 ++++++++
 .../helpers/server_side_indicator.vue              |  51 --------
 src/components/settings_modal/helpers/setting.js   |  84 +++++++++++++
 .../helpers/shared_computed_object.js              |  18 ---
 .../settings_modal/helpers/size_setting.js         |  48 ++-----
 .../settings_modal/tabs/filtering_tab.vue          |  14 +--
 src/components/settings_modal/tabs/general_tab.js  |   6 +-
 src/components/settings_modal/tabs/general_tab.vue |  29 ++---
 .../settings_modal/tabs/notifications_tab.vue      |   4 +-
 src/components/settings_modal/tabs/profile_tab.vue |  32 +++--
 src/main.js                                        |   4 +-
 src/modules/config.js                              |   3 +-
 src/modules/profileConfig.js                       | 140 +++++++++++++++++++++
 src/modules/serverSideConfig.js                    | 140 ---------------------
 19 files changed, 351 insertions(+), 422 deletions(-)
 create mode 100644 src/components/settings_modal/helpers/profile_setting_indicator.vue
 delete mode 100644 src/components/settings_modal/helpers/server_side_indicator.vue
 create mode 100644 src/components/settings_modal/helpers/setting.js
 create mode 100644 src/modules/profileConfig.js
 delete mode 100644 src/modules/serverSideConfig.js

(limited to 'src/components/settings_modal/helpers/choice_setting.vue')

diff --git a/src/components/settings_modal/helpers/boolean_setting.js b/src/components/settings_modal/helpers/boolean_setting.js
index 2e6992cb..078cc5ff 100644
--- a/src/components/settings_modal/helpers/boolean_setting.js
+++ b/src/components/settings_modal/helpers/boolean_setting.js
@@ -1,56 +1,13 @@
-import { get, set } from 'lodash'
 import Checkbox from 'src/components/checkbox/checkbox.vue'
 import ModifiedIndicator from './modified_indicator.vue'
-import ServerSideIndicator from './server_side_indicator.vue'
+import ProfileSettingIndicator from './profile_setting_indicator.vue'
+import Setting from './setting.js'
+
 export default {
   components: {
     Checkbox,
     ModifiedIndicator,
-    ServerSideIndicator
+    ProfileSettingIndicator
   },
-  props: [
-    'path',
-    'disabled',
-    'expert'
-  ],
-  computed: {
-    pathDefault () {
-      const [firstSegment, ...rest] = this.path.split('.')
-      return [firstSegment + 'DefaultValue', ...rest].join('.')
-    },
-    state () {
-      const value = get(this.$parent, this.path)
-      if (value === undefined) {
-        return this.defaultState
-      } else {
-        return value
-      }
-    },
-    defaultState () {
-      return get(this.$parent, this.pathDefault)
-    },
-    isServerSide () {
-      return this.path.startsWith('serverSide_')
-    },
-    isChanged () {
-      return !this.path.startsWith('serverSide_') && this.state !== this.defaultState
-    },
-    matchesExpertLevel () {
-      return (this.expert || 0) <= this.$parent.expertLevel
-    }
-  },
-  methods: {
-    update (e) {
-      const [firstSegment, ...rest] = this.path.split('.')
-      set(this.$parent, this.path, e)
-      // Updating nested properties does not trigger update on its parent.
-      // probably still not as reliable, but works for depth=1 at least
-      if (rest.length > 0) {
-        set(this.$parent, firstSegment, { ...get(this.$parent, firstSegment) })
-      }
-    },
-    reset () {
-      set(this.$parent, this.path, this.defaultState)
-    }
-  }
+  ...Setting
 }
diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue
index 41142966..bc014bc9 100644
--- a/src/components/settings_modal/helpers/boolean_setting.vue
+++ b/src/components/settings_modal/helpers/boolean_setting.vue
@@ -5,7 +5,7 @@
   >
     <Checkbox
       :model-value="state"
-      :disabled="disabled"
+      :disabled="shouldBeDisabled"
       @update:modelValue="update"
     >
       <span
@@ -19,7 +19,7 @@
         :changed="isChanged"
         :onclick="reset"
       />
-      <ServerSideIndicator :server-side="isServerSide" />
+      <ProfileSettingIndicator :is-profile="isProfileTied" />
     </Checkbox>
   </label>
 </template>
diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js
index 3da559fe..8aa5f54b 100644
--- a/src/components/settings_modal/helpers/choice_setting.js
+++ b/src/components/settings_modal/helpers/choice_setting.js
@@ -1,51 +1,20 @@
-import { get, set } from 'lodash'
 import Select from 'src/components/select/select.vue'
 import ModifiedIndicator from './modified_indicator.vue'
-import ServerSideIndicator from './server_side_indicator.vue'
+import ProfileSettingIndicator from './profile_setting_indicator.vue'
+import Setting from './setting.js'
+
 export default {
   components: {
     Select,
     ModifiedIndicator,
-    ServerSideIndicator
+    ProfileSettingIndicator
   },
-  props: [
-    'path',
-    'disabled',
-    'options',
-    'expert'
-  ],
-  computed: {
-    pathDefault () {
-      const [firstSegment, ...rest] = this.path.split('.')
-      return [firstSegment + 'DefaultValue', ...rest].join('.')
-    },
-    state () {
-      const value = get(this.$parent, this.path)
-      if (value === undefined) {
-        return this.defaultState
-      } else {
-        return value
-      }
-    },
-    defaultState () {
-      return get(this.$parent, this.pathDefault)
-    },
-    isServerSide () {
-      return this.path.startsWith('serverSide_')
-    },
-    isChanged () {
-      return !this.path.startsWith('serverSide_') && this.state !== this.defaultState
-    },
-    matchesExpertLevel () {
-      return (this.expert || 0) <= this.$parent.expertLevel
-    }
-  },
-  methods: {
-    update (e) {
-      set(this.$parent, this.path, e)
-    },
-    reset () {
-      set(this.$parent, this.path, this.defaultState)
+  ...Setting,
+  props: {
+    ...Setting.props,
+    options: {
+      type: Array,
+      required: true
     }
   }
 }
diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue
index 8fdbb5d3..4c4cdefe 100644
--- a/src/components/settings_modal/helpers/choice_setting.vue
+++ b/src/components/settings_modal/helpers/choice_setting.vue
@@ -23,7 +23,7 @@
       :changed="isChanged"
       :onclick="reset"
     />
-    <ServerSideIndicator :server-side="isServerSide" />
+    <ProfileSettingIndicator :is-profile="isProfileSetting" />
   </label>
 </template>
 
diff --git a/src/components/settings_modal/helpers/integer_setting.js b/src/components/settings_modal/helpers/integer_setting.js
index e64d0cee..0f29f11a 100644
--- a/src/components/settings_modal/helpers/integer_setting.js
+++ b/src/components/settings_modal/helpers/integer_setting.js
@@ -1,44 +1,15 @@
-import { get, set } from 'lodash'
 import ModifiedIndicator from './modified_indicator.vue'
+import Setting from './setting.js'
+
 export default {
   components: {
     ModifiedIndicator
   },
-  props: {
-    path: String,
-    disabled: Boolean,
-    min: Number,
-    expert: [Number, String]
-  },
-  computed: {
-    pathDefault () {
-      const [firstSegment, ...rest] = this.path.split('.')
-      return [firstSegment + 'DefaultValue', ...rest].join('.')
-    },
-    state () {
-      const value = get(this.$parent, this.path)
-      if (value === undefined) {
-        return this.defaultState
-      } else {
-        return value
-      }
-    },
-    defaultState () {
-      return get(this.$parent, this.pathDefault)
-    },
-    isChanged () {
-      return this.state !== this.defaultState
-    },
-    matchesExpertLevel () {
-      return (this.expert || 0) <= this.$parent.expertLevel
-    }
-  },
+  ...Setting,
   methods: {
+    ...Setting.methods,
     update (e) {
-      set(this.$parent, this.path, parseInt(e.target.value))
-    },
-    reset () {
-      set(this.$parent, this.path, this.defaultState)
+      this.configSink(this.path, parseInt(e.target.value))
     }
   }
 }
diff --git a/src/components/settings_modal/helpers/profile_setting_indicator.vue b/src/components/settings_modal/helpers/profile_setting_indicator.vue
new file mode 100644
index 00000000..d160781b
--- /dev/null
+++ b/src/components/settings_modal/helpers/profile_setting_indicator.vue
@@ -0,0 +1,51 @@
+<template>
+  <span
+    v-if="isProfile"
+    class="ProfileSettingIndicator"
+  >
+    <Popover
+      trigger="hover"
+    >
+      <template #trigger>
+        &nbsp;
+        <FAIcon
+          icon="server"
+          :aria-label="$t('settings.setting_server_side')"
+        />
+      </template>
+      <template #content>
+        <div class="profilesetting-tooltip">
+          {{ $t('settings.setting_server_side') }}
+        </div>
+      </template>
+    </Popover>
+  </span>
+</template>
+
+<script>
+import Popover from 'src/components/popover/popover.vue'
+import { library } from '@fortawesome/fontawesome-svg-core'
+import { faServer } from '@fortawesome/free-solid-svg-icons'
+
+library.add(
+  faServer
+)
+
+export default {
+  components: { Popover },
+  props: ['isProfile']
+}
+</script>
+
+<style lang="scss">
+.ProfileSettingIndicator {
+  display: inline-block;
+  position: relative;
+}
+
+.profilesetting-tooltip {
+  margin: 0.5em 1em;
+  min-width: 10em;
+  text-align: center;
+}
+</style>
diff --git a/src/components/settings_modal/helpers/server_side_indicator.vue b/src/components/settings_modal/helpers/server_side_indicator.vue
deleted file mode 100644
index bf181959..00000000
--- a/src/components/settings_modal/helpers/server_side_indicator.vue
+++ /dev/null
@@ -1,51 +0,0 @@
-<template>
-  <span
-    v-if="serverSide"
-    class="ServerSideIndicator"
-  >
-    <Popover
-      trigger="hover"
-    >
-      <template #trigger>
-        &nbsp;
-        <FAIcon
-          icon="server"
-          :aria-label="$t('settings.setting_server_side')"
-        />
-      </template>
-      <template #content>
-        <div class="serverside-tooltip">
-          {{ $t('settings.setting_server_side') }}
-        </div>
-      </template>
-    </Popover>
-  </span>
-</template>
-
-<script>
-import Popover from 'src/components/popover/popover.vue'
-import { library } from '@fortawesome/fontawesome-svg-core'
-import { faServer } from '@fortawesome/free-solid-svg-icons'
-
-library.add(
-  faServer
-)
-
-export default {
-  components: { Popover },
-  props: ['serverSide']
-}
-</script>
-
-<style lang="scss">
-.ServerSideIndicator {
-  display: inline-block;
-  position: relative;
-}
-
-.serverside-tooltip {
-  margin: 0.5em 1em;
-  min-width: 10em;
-  text-align: center;
-}
-</style>
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
new file mode 100644
index 00000000..dc37675c
--- /dev/null
+++ b/src/components/settings_modal/helpers/setting.js
@@ -0,0 +1,84 @@
+import { get, set } from 'lodash'
+export default {
+  props: {
+    path: {
+      type: String,
+      required: true
+    },
+    disabled: {
+      type: Boolean,
+      default: false
+    },
+    parentPath: {
+      type: String
+    },
+    parentInvert: {
+      type: Boolean,
+      default: false
+    },
+    expert: {
+      type: [Number, String],
+      default: 0
+    },
+    source: {
+      type: String,
+      default: 'default'
+    }
+  },
+  computed: {
+    state () {
+      const value = get(this.configSource, this.path)
+      if (value === undefined) {
+        return this.defaultState
+      } else {
+        return value
+      }
+    },
+    shouldBeDisabled () {
+      const parentValue = this.parentPath !== undefined ? get(this.configSource, this.parentPath) : null
+      return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false)
+    },
+    configSource () {
+      switch (this.source) {
+        case 'profile':
+          return this.$store.state.profileConfig
+        default:
+          return this.$store.getters.mergedConfig
+      }
+    },
+    configSink () {
+      switch (this.source) {
+        case 'profile':
+          return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v })
+        default:
+          return (k, v) => this.$store.dispatch('setOption', { name: k, value: v })
+      }
+    },
+    defaultState () {
+      switch (this.source) {
+        case 'profile':
+          return {}
+        default:
+          return get(this.$store.getters.defaultConfig, this.path)
+      }
+    },
+    isProfileTied () {
+      return this.source === 'profile'
+    },
+    isChanged () {
+      return !this.source === 'default' && this.state !== this.defaultState
+    },
+    matchesExpertLevel () {
+      return (this.expert || 0) <= this.$store.state.config.expertLevel > 0
+    }
+  },
+  methods: {
+    update (e) {
+      console.log('U', this.path, e)
+      this.configSink(this.path, e)
+    },
+    reset () {
+      set(this.$store.getters.mergedConfig, this.path, this.defaultState)
+    }
+  }
+}
diff --git a/src/components/settings_modal/helpers/shared_computed_object.js b/src/components/settings_modal/helpers/shared_computed_object.js
index 12431dca..6b22174d 100644
--- a/src/components/settings_modal/helpers/shared_computed_object.js
+++ b/src/components/settings_modal/helpers/shared_computed_object.js
@@ -1,19 +1,9 @@
 import { defaultState as configDefaultState } from 'src/modules/config.js'
-import { defaultState as serverSideConfigDefaultState } from 'src/modules/serverSideConfig.js'
 
 const SharedComputedObject = () => ({
   user () {
     return this.$store.state.users.currentUser
   },
-  // Getting values for default properties
-  ...Object.keys(configDefaultState)
-    .map(key => [
-      key + 'DefaultValue',
-      function () {
-        return this.$store.getters.defaultConfig[key]
-      }
-    ])
-    .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
   // Generating computed values for vuex properties
   ...Object.keys(configDefaultState)
     .map(key => [key, {
@@ -23,14 +13,6 @@ const SharedComputedObject = () => ({
       }
     }])
     .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
-  ...Object.keys(serverSideConfigDefaultState)
-    .map(key => ['serverSide_' + key, {
-      get () { return this.$store.state.serverSideConfig[key] },
-      set (value) {
-        this.$store.dispatch('setServerSideOption', { name: key, value })
-      }
-    }])
-    .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
   // Special cases (need to transform values or perform actions first)
   useStreamingApi: {
     get () { return this.$store.getters.mergedConfig.useStreamingApi },
diff --git a/src/components/settings_modal/helpers/size_setting.js b/src/components/settings_modal/helpers/size_setting.js
index 58697412..4a0f7e48 100644
--- a/src/components/settings_modal/helpers/size_setting.js
+++ b/src/components/settings_modal/helpers/size_setting.js
@@ -1,6 +1,6 @@
-import { get, set } from 'lodash'
 import ModifiedIndicator from './modified_indicator.vue'
 import Select from 'src/components/select/select.vue'
+import Setting from './setting.js'
 
 export const allCssUnits = ['cm', 'mm', 'in', 'px', 'pt', 'pc', 'em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', '%']
 export const defaultHorizontalUnits = ['px', 'rem', 'vw']
@@ -11,57 +11,31 @@ export default {
     ModifiedIndicator,
     Select
   },
+  ...Setting,
   props: {
-    path: String,
-    disabled: Boolean,
+    ...Setting.props,
     min: Number,
     units: {
-      type: [String],
+      type: Array,
       default: () => allCssUnits
-    },
-    expert: [Number, String]
+    }
   },
   computed: {
-    pathDefault () {
-      const [firstSegment, ...rest] = this.path.split('.')
-      return [firstSegment + 'DefaultValue', ...rest].join('.')
-    },
+    ...Setting.computed,
     stateUnit () {
-      return (this.state || '').replace(/\d+/, '')
+      return this.state.replace(/\d+/, '')
     },
     stateValue () {
-      return (this.state || '').replace(/\D+/, '')
-    },
-    state () {
-      const value = get(this.$parent, this.path)
-      if (value === undefined) {
-        return this.defaultState
-      } else {
-        return value
-      }
-    },
-    defaultState () {
-      return get(this.$parent, this.pathDefault)
-    },
-    isChanged () {
-      return this.state !== this.defaultState
-    },
-    matchesExpertLevel () {
-      return (this.expert || 0) <= this.$parent.expertLevel
+      return this.state.replace(/\D+/, '')
     }
   },
   methods: {
-    update (e) {
-      set(this.$parent, this.path, e)
-    },
-    reset () {
-      set(this.$parent, this.path, this.defaultState)
-    },
+    ...Setting.methods,
     updateValue (e) {
-      set(this.$parent, this.path, parseInt(e.target.value) + this.stateUnit)
+      this.configSink(this.path, parseInt(e.target.value) + this.stateUnit)
     },
     updateUnit (e) {
-      set(this.$parent, this.path, this.stateValue + e.target.value)
+      this.configSink(this.path, this.stateValue + e.target.value)
     }
   }
 }
diff --git a/src/components/settings_modal/tabs/filtering_tab.vue b/src/components/settings_modal/tabs/filtering_tab.vue
index 97046ff0..46c6bc5c 100644
--- a/src/components/settings_modal/tabs/filtering_tab.vue
+++ b/src/components/settings_modal/tabs/filtering_tab.vue
@@ -7,13 +7,11 @@
           <BooleanSetting path="hideFilteredStatuses">
             {{ $t('settings.hide_filtered_statuses') }}
           </BooleanSetting>
-          <ul
-            class="setting-list suboptions"
-            :class="[{disabled: !streaming}]"
-          >
+          <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
-                :disabled="hideFilteredStatuses"
+                parentPath="hideFilteredStatuses"
+                :parentInvert="true"
                 path="hideWordFilteredPosts"
               >
                 {{ $t('settings.hide_wordfiltered_statuses') }}
@@ -22,7 +20,8 @@
             <li>
               <BooleanSetting
                 v-if="user"
-                :disabled="hideFilteredStatuses"
+                parentPath="hideFilteredStatuses"
+                :parentInvert="true"
                 path="hideMutedThreads"
               >
                 {{ $t('settings.hide_muted_threads') }}
@@ -31,7 +30,8 @@
             <li>
               <BooleanSetting
                 v-if="user"
-                :disabled="hideFilteredStatuses"
+                parentPath="hideFilteredStatuses"
+                :parentInvert="true"
                 path="hideMutedPosts"
               >
                 {{ $t('settings.hide_muted_posts') }}
diff --git a/src/components/settings_modal/tabs/general_tab.js b/src/components/settings_modal/tabs/general_tab.js
index ea24d6ad..e8f7016e 100644
--- a/src/components/settings_modal/tabs/general_tab.js
+++ b/src/components/settings_modal/tabs/general_tab.js
@@ -6,7 +6,7 @@ import SizeSetting, { defaultHorizontalUnits } from '../helpers/size_setting.vue
 import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue'
 
 import SharedComputedObject from '../helpers/shared_computed_object.js'
-import ServerSideIndicator from '../helpers/server_side_indicator.vue'
+import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue'
 import { library } from '@fortawesome/fontawesome-svg-core'
 import {
   faGlobe
@@ -65,7 +65,7 @@ const GeneralTab = {
     SizeSetting,
     InterfaceLanguageSwitcher,
     ScopeSelector,
-    ServerSideIndicator
+    ProfileSettingIndicator
   },
   computed: {
     horizontalUnits () {
@@ -108,7 +108,7 @@ const GeneralTab = {
   },
   methods: {
     changeDefaultScope (value) {
-      this.$store.dispatch('setServerSideOption', { name: 'defaultScope', value })
+      this.$store.dispatch('setProfileOption', { name: 'defaultScope', value })
     }
   }
 }
diff --git a/src/components/settings_modal/tabs/general_tab.vue b/src/components/settings_modal/tabs/general_tab.vue
index 65248ac1..0eb3d06c 100644
--- a/src/components/settings_modal/tabs/general_tab.vue
+++ b/src/components/settings_modal/tabs/general_tab.vue
@@ -29,14 +29,11 @@
           <BooleanSetting path="streaming">
             {{ $t('settings.streaming') }}
           </BooleanSetting>
-          <ul
-            class="setting-list suboptions"
-            :class="[{disabled: !streaming}]"
-          >
+          <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
                 path="pauseOnUnfocused"
-                :disabled="!streaming"
+                parentPath="streaming"
               >
                 {{ $t('settings.pause_on_unfocused') }}
               </BooleanSetting>
@@ -265,7 +262,7 @@
         <li>
           <BooleanSetting
             v-if="user"
-            path="serverSide_stripRichContent"
+            source="profile" path="stripRichContent"
             expert="1"
           >
             {{ $t('settings.no_rich_text_description') }}
@@ -290,7 +287,7 @@
             <BooleanSetting
               path="preloadImage"
               expert="1"
-              :disabled="!hideNsfw"
+              parentPath="hideNsfw"
             >
               {{ $t('settings.preload_images') }}
             </BooleanSetting>
@@ -299,7 +296,7 @@
             <BooleanSetting
               path="useOneClickNsfw"
               expert="1"
-              :disabled="!hideNsfw"
+              parentPath="hideNsfw"
             >
               {{ $t('settings.use_one_click_nsfw') }}
             </BooleanSetting>
@@ -312,15 +309,13 @@
           >
             {{ $t('settings.loop_video') }}
           </BooleanSetting>
-          <ul
-            class="setting-list suboptions"
-            :class="[{disabled: !streaming}]"
-          >
+          <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
                 path="loopVideoSilentOnly"
                 expert="1"
-                :disabled="!loopVideo || !loopSilentAvailable"
+                parentPath="loopVideo"
+                :disabled="!loopSilentAvailable"
               >
                 {{ $t('settings.loop_video_silent_only') }}
               </BooleanSetting>
@@ -418,18 +413,18 @@
       <ul class="setting-list">
         <li>
           <label for="default-vis">
-            {{ $t('settings.default_vis') }} <ServerSideIndicator :server-side="true" />
+            {{ $t('settings.default_vis') }} <ProfileSettingIndicator :is-profile="true" />
             <ScopeSelector
               class="scope-selector"
               :show-all="true"
-              :user-default="serverSide_defaultScope"
-              :initial-scope="serverSide_defaultScope"
+              :user-default="$store.state.profileConfig.defaultScope"
+              :initial-scope="$store.state.profileConfig.defaultScope"
               :on-scope-change="changeDefaultScope"
             />
           </label>
         </li>
         <li>
-          <!-- <BooleanSetting path="serverSide_defaultNSFW"> -->
+          <!-- <BooleanSetting source="profile" path="defaultNSFW"> -->
           <BooleanSetting path="sensitiveByDefault">
             {{ $t('settings.sensitive_by_default') }}
           </BooleanSetting>
diff --git a/src/components/settings_modal/tabs/notifications_tab.vue b/src/components/settings_modal/tabs/notifications_tab.vue
index dd3806ed..ea095372 100644
--- a/src/components/settings_modal/tabs/notifications_tab.vue
+++ b/src/components/settings_modal/tabs/notifications_tab.vue
@@ -4,7 +4,7 @@
       <h2>{{ $t('settings.notification_setting_filters') }}</h2>
       <ul class="setting-list">
         <li>
-          <BooleanSetting path="serverSide_blockNotificationsFromStrangers">
+          <BooleanSetting source="profile" path="blockNotificationsFromStrangers">
             {{ $t('settings.notification_setting_block_from_strangers') }}
           </BooleanSetting>
         </li>
@@ -67,7 +67,7 @@
         </li>
         <li>
           <BooleanSetting
-            path="serverSide_webPushHideContents"
+            source="profile" path="webPushHideContents"
             expert="1"
           >
             {{ $t('settings.notification_setting_hide_notification_contents') }}
diff --git a/src/components/settings_modal/tabs/profile_tab.vue b/src/components/settings_modal/tabs/profile_tab.vue
index 6a5b478a..74652990 100644
--- a/src/components/settings_modal/tabs/profile_tab.vue
+++ b/src/components/settings_modal/tabs/profile_tab.vue
@@ -254,37 +254,35 @@
       <h2>{{ $t('settings.account_privacy') }}</h2>
       <ul class="setting-list">
         <li>
-          <BooleanSetting path="serverSide_locked">
+          <BooleanSetting source="profile" path="locked">
             {{ $t('settings.lock_account_description') }}
           </BooleanSetting>
         </li>
         <li>
-          <BooleanSetting path="serverSide_discoverable">
+          <BooleanSetting source="profile" path="discoverable">
             {{ $t('settings.discoverable') }}
           </BooleanSetting>
         </li>
         <li>
-          <BooleanSetting path="serverSide_allowFollowingMove">
+          <BooleanSetting source="profile" path="allowFollowingMove">
             {{ $t('settings.allow_following_move') }}
           </BooleanSetting>
         </li>
         <li>
-          <BooleanSetting path="serverSide_hideFavorites">
+          <BooleanSetting source="profile" path="hideFavorites">
             {{ $t('settings.hide_favorites_description') }}
           </BooleanSetting>
         </li>
         <li>
-          <BooleanSetting path="serverSide_hideFollowers">
+          <BooleanSetting source="profile" path="hideFollowers">
             {{ $t('settings.hide_followers_description') }}
           </BooleanSetting>
-          <ul
-            class="setting-list suboptions"
-            :class="[{disabled: !serverSide_hideFollowers}]"
-          >
+          <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
-                path="serverSide_hideFollowersCount"
-                :disabled="!serverSide_hideFollowers"
+                source="profile"
+                path="hideFollowersCount"
+                parentPath="hideFollowers"
               >
                 {{ $t('settings.hide_followers_count_description') }}
               </BooleanSetting>
@@ -292,17 +290,15 @@
           </ul>
         </li>
         <li>
-          <BooleanSetting path="serverSide_hideFollows">
+          <BooleanSetting source="profile" path="hideFollows">
             {{ $t('settings.hide_follows_description') }}
           </BooleanSetting>
-          <ul
-            class="setting-list suboptions"
-            :class="[{disabled: !serverSide_hideFollows}]"
-          >
+          <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
-                path="serverSide_hideFollowsCount"
-                :disabled="!serverSide_hideFollows"
+                source="profile"
+                path="hideFollowsCount"
+                parentPath="hideFollows"
               >
                 {{ $t('settings.hide_follows_count_description') }}
               </BooleanSetting>
diff --git a/src/main.js b/src/main.js
index d3e60a0f..fd712113 100644
--- a/src/main.js
+++ b/src/main.js
@@ -10,7 +10,7 @@ import listsModule from './modules/lists.js'
 import usersModule from './modules/users.js'
 import apiModule from './modules/api.js'
 import configModule from './modules/config.js'
-import serverSideConfigModule from './modules/serverSideConfig.js'
+import profileConfigModule from './modules/profileConfig.js'
 import serverSideStorageModule from './modules/serverSideStorage.js'
 import shoutModule from './modules/shout.js'
 import oauthModule from './modules/oauth.js'
@@ -80,7 +80,7 @@ const persistedStateOptions = {
       lists: listsModule,
       api: apiModule,
       config: configModule,
-      serverSideConfig: serverSideConfigModule,
+      profileConfig: profileConfigModule,
       serverSideStorage: serverSideStorageModule,
       shout: shoutModule,
       oauth: oauthModule,
diff --git a/src/modules/config.js b/src/modules/config.js
index 3d9cf591..6ab59d6d 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -1,6 +1,7 @@
 import Cookies from 'js-cookie'
 import { setPreset, applyTheme, applyConfig } from '../services/style_setter/style_setter.js'
 import messages from '../i18n/messages'
+import { set } from 'lodash'
 import localeService from '../services/locale/locale.service.js'
 
 const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage'
@@ -147,7 +148,7 @@ const config = {
   },
   mutations: {
     setOption (state, { name, value }) {
-      state[name] = value
+      set(state, name, value)
     },
     setHighlight (state, { user, color, type }) {
       const data = this.state.config.highlight[user]
diff --git a/src/modules/profileConfig.js b/src/modules/profileConfig.js
new file mode 100644
index 00000000..2cb2014a
--- /dev/null
+++ b/src/modules/profileConfig.js
@@ -0,0 +1,140 @@
+import { get, set } from 'lodash'
+
+const defaultApi = ({ rootState, commit }, { path, value }) => {
+  const params = {}
+  set(params, path, value)
+  return rootState
+    .api
+    .backendInteractor
+    .updateProfile({ params })
+    .then(result => {
+      commit('addNewUsers', [result])
+      commit('setCurrentUser', result)
+    })
+}
+
+const notificationsApi = ({ rootState, commit }, { path, value, oldValue }) => {
+  const settings = {}
+  set(settings, path, value)
+  return rootState
+    .api
+    .backendInteractor
+    .updateNotificationSettings({ settings })
+    .then(result => {
+      if (result.status === 'success') {
+        commit('confirmProfileOption', { name, value })
+      } else {
+        commit('confirmProfileOption', { name, value: oldValue })
+      }
+    })
+}
+
+/**
+ * Map that stores relation between path for reading (from user profile),
+ * for writing (into API) an what API to use.
+ *
+ * Shorthand - instead of { get, set, api? } object it's possible to use string
+ * in case default api is used and get = set
+ *
+ * If no api is specified, defaultApi is used (see above)
+ */
+export const settingsMap = {
+  defaultScope: 'source.privacy',
+  defaultNSFW: 'source.sensitive', // BROKEN: pleroma/pleroma#2837
+  stripRichContent: {
+    get: 'source.pleroma.no_rich_text',
+    set: 'no_rich_text'
+  },
+  // Privacy
+  locked: 'locked',
+  acceptChatMessages: {
+    get: 'pleroma.accepts_chat_messages',
+    set: 'accepts_chat_messages'
+  },
+  allowFollowingMove: {
+    get: 'pleroma.allow_following_move',
+    set: 'allow_following_move'
+  },
+  discoverable: {
+    get: 'source.pleroma.discoverable',
+    set: 'discoverable'
+  },
+  hideFavorites: {
+    get: 'pleroma.hide_favorites',
+    set: 'hide_favorites'
+  },
+  hideFollowers: {
+    get: 'pleroma.hide_followers',
+    set: 'hide_followers'
+  },
+  hideFollows: {
+    get: 'pleroma.hide_follows',
+    set: 'hide_follows'
+  },
+  hideFollowersCount: {
+    get: 'pleroma.hide_followers_count',
+    set: 'hide_followers_count'
+  },
+  hideFollowsCount: {
+    get: 'pleroma.hide_follows_count',
+    set: 'hide_follows_count'
+  },
+  // NotificationSettingsAPIs
+  webPushHideContents: {
+    get: 'pleroma.notification_settings.hide_notification_contents',
+    set: 'hide_notification_contents',
+    api: notificationsApi
+  },
+  blockNotificationsFromStrangers: {
+    get: 'pleroma.notification_settings.block_from_strangers',
+    set: 'block_from_strangers',
+    api: notificationsApi
+  }
+}
+
+export const defaultState = Object.fromEntries(Object.keys(settingsMap).map(key => [key, null]))
+
+const profileConfig = {
+  state: { ...defaultState },
+  mutations: {
+    confirmProfileOption (state, { name, value }) {
+      set(state, name, value)
+    },
+    wipeProfileOption (state, { name }) {
+      set(state, name, null)
+    },
+    wipeAllProfileOptions (state) {
+      Object.keys(settingsMap).forEach(key => {
+        set(state, key, null)
+      })
+    },
+    // Set the settings based on their path location
+    setCurrentUser (state, user) {
+      Object.entries(settingsMap).forEach((map) => {
+        const [name, value] = map
+        const { get: path = value } = value
+        set(state, name, get(user._original, path))
+      })
+    }
+  },
+  actions: {
+    setProfileOption ({ rootState, state, commit, dispatch }, { name, value }) {
+      const oldValue = get(state, name)
+      const map = settingsMap[name]
+      if (!map) throw new Error('Invalid server-side setting')
+      const { set: path = map, api = defaultApi } = map
+      commit('wipeProfileOption', { name })
+
+      api({ rootState, commit }, { path, value, oldValue })
+        .catch((e) => {
+          console.warn('Error setting server-side option:', e)
+          commit('confirmProfileOption', { name, value: oldValue })
+        })
+    },
+    logout ({ commit }) {
+      commit('wipeAllProfileOptions')
+    }
+  }
+}
+
+export default profileConfig
diff --git a/src/modules/serverSideConfig.js b/src/modules/serverSideConfig.js
deleted file mode 100644
index 476263bc..00000000
--- a/src/modules/serverSideConfig.js
+++ /dev/null
@@ -1,140 +0,0 @@
-import { get, set } from 'lodash'
-
-const defaultApi = ({ rootState, commit }, { path, value }) => {
-  const params = {}
-  set(params, path, value)
-  return rootState
-    .api
-    .backendInteractor
-    .updateProfile({ params })
-    .then(result => {
-      commit('addNewUsers', [result])
-      commit('setCurrentUser', result)
-    })
-}
-
-const notificationsApi = ({ rootState, commit }, { path, value, oldValue }) => {
-  const settings = {}
-  set(settings, path, value)
-  return rootState
-    .api
-    .backendInteractor
-    .updateNotificationSettings({ settings })
-    .then(result => {
-      if (result.status === 'success') {
-        commit('confirmServerSideOption', { name, value })
-      } else {
-        commit('confirmServerSideOption', { name, value: oldValue })
-      }
-    })
-}
-
-/**
- * Map that stores relation between path for reading (from user profile),
- * for writing (into API) an what API to use.
- *
- * Shorthand - instead of { get, set, api? } object it's possible to use string
- * in case default api is used and get = set
- *
- * If no api is specified, defaultApi is used (see above)
- */
-export const settingsMap = {
-  defaultScope: 'source.privacy',
-  defaultNSFW: 'source.sensitive', // BROKEN: pleroma/pleroma#2837
-  stripRichContent: {
-    get: 'source.pleroma.no_rich_text',
-    set: 'no_rich_text'
-  },
-  // Privacy
-  locked: 'locked',
-  acceptChatMessages: {
-    get: 'pleroma.accepts_chat_messages',
-    set: 'accepts_chat_messages'
-  },
-  allowFollowingMove: {
-    get: 'pleroma.allow_following_move',
-    set: 'allow_following_move'
-  },
-  discoverable: {
-    get: 'source.pleroma.discoverable',
-    set: 'discoverable'
-  },
-  hideFavorites: {
-    get: 'pleroma.hide_favorites',
-    set: 'hide_favorites'
-  },
-  hideFollowers: {
-    get: 'pleroma.hide_followers',
-    set: 'hide_followers'
-  },
-  hideFollows: {
-    get: 'pleroma.hide_follows',
-    set: 'hide_follows'
-  },
-  hideFollowersCount: {
-    get: 'pleroma.hide_followers_count',
-    set: 'hide_followers_count'
-  },
-  hideFollowsCount: {
-    get: 'pleroma.hide_follows_count',
-    set: 'hide_follows_count'
-  },
-  // NotificationSettingsAPIs
-  webPushHideContents: {
-    get: 'pleroma.notification_settings.hide_notification_contents',
-    set: 'hide_notification_contents',
-    api: notificationsApi
-  },
-  blockNotificationsFromStrangers: {
-    get: 'pleroma.notification_settings.block_from_strangers',
-    set: 'block_from_strangers',
-    api: notificationsApi
-  }
-}
-
-export const defaultState = Object.fromEntries(Object.keys(settingsMap).map(key => [key, null]))
-
-const serverSideConfig = {
-  state: { ...defaultState },
-  mutations: {
-    confirmServerSideOption (state, { name, value }) {
-      set(state, name, value)
-    },
-    wipeServerSideOption (state, { name }) {
-      set(state, name, null)
-    },
-    wipeAllServerSideOptions (state) {
-      Object.keys(settingsMap).forEach(key => {
-        set(state, key, null)
-      })
-    },
-    // Set the settings based on their path location
-    setCurrentUser (state, user) {
-      Object.entries(settingsMap).forEach((map) => {
-        const [name, value] = map
-        const { get: path = value } = value
-        set(state, name, get(user._original, path))
-      })
-    }
-  },
-  actions: {
-    setServerSideOption ({ rootState, state, commit, dispatch }, { name, value }) {
-      const oldValue = get(state, name)
-      const map = settingsMap[name]
-      if (!map) throw new Error('Invalid server-side setting')
-      const { set: path = map, api = defaultApi } = map
-      commit('wipeServerSideOption', { name })
-
-      api({ rootState, commit }, { path, value, oldValue })
-        .catch((e) => {
-          console.warn('Error setting server-side option:', e)
-          commit('confirmServerSideOption', { name, value: oldValue })
-        })
-    },
-    logout ({ commit }) {
-      commit('wipeAllServerSideOptions')
-    }
-  }
-}
-
-export default serverSideConfig
-- 
cgit v1.2.3-70-g09d2


From 0b5e536b4c96a81ec78f323be9bece6deae61773 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Mon, 20 Mar 2023 23:36:47 +0200
Subject: ChoiceSetting support added, added captcha settings

---
 .../settings_modal/admin_tabs/instance_tab.vue     | 51 ++++++++++++++++++++++
 .../settings_modal/helpers/choice_setting.js       | 27 +++++++++++-
 .../settings_modal/helpers/choice_setting.vue      | 18 ++++++--
 .../settings_modal/helpers/number_setting.vue      | 15 ++++++-
 src/components/settings_modal/helpers/setting.js   |  7 ++-
 .../helpers/shared_computed_object.js              |  3 ++
 src/modules/adminSettings.js                       | 13 +++---
 7 files changed, 121 insertions(+), 13 deletions(-)

(limited to 'src/components/settings_modal/helpers/choice_setting.vue')

diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue
index ad271293..ff784287 100644
--- a/src/components/settings_modal/admin_tabs/instance_tab.vue
+++ b/src/components/settings_modal/admin_tabs/instance_tab.vue
@@ -111,6 +111,57 @@
             APPROVAL REQUIRED
           </BooleanSetting>
         </li>
+        <li>
+          <h3>{{ $t('admin_dash.captcha.header') }}</h3>
+        </li>
+        <li>
+          <BooleanSetting
+            source="admin"
+            :path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
+            draft-mode
+          >
+            CAPTCHA
+          </BooleanSetting>
+          <ul class="setting-list suboptions">
+            <li>
+              <ChoiceSetting
+                source="admin"
+                :path="[':pleroma', 'Pleroma.Captcha', ':method']"
+                :parent-path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
+                :option-label-map="{
+                  'Pleroma.Captcha.Native': $t('admin_dash.captcha.native'),
+                  'Pleroma.Captcha.Kocaptcha': $t('admin_dash.captcha.kocaptcha')
+                }"
+                draft-mode
+              >
+                CAPTCHA TYPE
+              </ChoiceSetting>
+              <IntegerSetting
+                source="admin"
+                :path="[':pleroma', 'Pleroma.Captcha', ':seconds_valid']"
+                :parent-path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
+                draft-mode
+              >
+                VALID
+              </IntegerSetting>
+            </li>
+          </ul>
+          <ul
+            v-if="adminConfig[':pleroma']['Pleroma.Captcha'][':enabled'] && adminConfig[':pleroma']['Pleroma.Captcha'][':method'] === 'Pleroma.Captcha.Kocaptcha'"
+            class="setting-list suboptions"
+          >
+            <h4>{{ $t('admin_dash.kocaptcha') }}</h4>
+            <li>
+              <StringSetting
+                source="admin"
+                :path="[':pleroma', 'Pleroma.Captcha.Kocaptcha', ':endpoint']"
+                draft-mode
+              >
+                cockAPTCHA ENDPOINT
+              </StringSetting>
+            </li>
+          </ul>
+        </li>
       </ul>
     </div>
   </div>
diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js
index a3c3bf44..3ff81bc9 100644
--- a/src/components/settings_modal/helpers/choice_setting.js
+++ b/src/components/settings_modal/helpers/choice_setting.js
@@ -11,7 +11,32 @@ export default {
     ...Setting.props,
     options: {
       type: Array,
-      required: true
+      required: false
+    },
+    optionLabelMap: {
+      type: Object,
+      required: false,
+      default: {}
+    }
+  },
+  computed: {
+    ...Setting.computed,
+    realOptions () {
+      if (this.source === 'admin') {
+        console.log(this.backendDescriptionSuggestions)
+        return this.backendDescriptionSuggestions.map(x => ({
+          key: x,
+          value: x,
+          label: this.optionLabelMap[x] || x
+        }))
+      }
+      return this.options
+    }
+  },
+  methods: {
+    ...Setting.methods,
+    getValue (e) {
+      return e
     }
   }
 }
diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue
index 4c4cdefe..55f9a62c 100644
--- a/src/components/settings_modal/helpers/choice_setting.vue
+++ b/src/components/settings_modal/helpers/choice_setting.vue
@@ -3,15 +3,20 @@
     v-if="matchesExpertLevel"
     class="ChoiceSetting"
   >
-    <slot />
+    <template v-if="backendDescription">
+      {{ backendDescriptionLabel }}
+    </template>
+    <template v-else>
+      <slot />
+    </template>
     {{ ' ' }}
     <Select
-      :model-value="state"
+      :model-value="draftMode ? draft :state"
       :disabled="disabled"
       @update:modelValue="update"
     >
       <option
-        v-for="option in options"
+        v-for="option in realOptions"
         :key="option.key"
         :value="option.value"
       >
@@ -24,6 +29,13 @@
       :onclick="reset"
     />
     <ProfileSettingIndicator :is-profile="isProfileSetting" />
+    <DraftButtons />
+    <p
+      v-if="backendDescriptionDescription"
+      class="setting-description"
+    >
+      {{ backendDescriptionDescription + ' ' }}
+    </p>
   </label>
 </template>
 
diff --git a/src/components/settings_modal/helpers/number_setting.vue b/src/components/settings_modal/helpers/number_setting.vue
index 81335762..93a7a79a 100644
--- a/src/components/settings_modal/helpers/number_setting.vue
+++ b/src/components/settings_modal/helpers/number_setting.vue
@@ -4,7 +4,12 @@
     class="NumberSetting"
   >
     <label :for="path">
-      <slot />
+      <template v-if="backendDescription">
+        {{ backendDescriptionLabel + ' ' }}
+      </template>
+      <template v-else>
+        <slot />
+      </template>
     </label>
     <input
       :id="path"
@@ -21,6 +26,14 @@
       :changed="isChanged"
       :onclick="reset"
     />
+    <ProfileSettingIndicator :is-profile="isProfileSetting" />
+    <DraftButtons />
+    <p
+      v-if="backendDescriptionDescription"
+      class="setting-description"
+    >
+      {{ backendDescriptionDescription + ' ' }}
+    </p>
   </span>
 </template>
 
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
index 8c7074a5..a6d35fb9 100644
--- a/src/components/settings_modal/helpers/setting.js
+++ b/src/components/settings_modal/helpers/setting.js
@@ -13,7 +13,7 @@ export default {
   },
   props: {
     path: {
-      type: String,
+      type: [String, Array],
       required: true
     },
     disabled: {
@@ -21,7 +21,7 @@ export default {
       default: false
     },
     parentPath: {
-      type: String
+      type: [String, Array]
     },
     parentInvert: {
       type: Boolean,
@@ -68,6 +68,9 @@ export default {
     backendDescriptionDescription () {
       return this.backendDescription?.description
     },
+    backendDescriptionSuggestions () {
+      return this.backendDescription?.suggestions
+    },
     shouldBeDisabled () {
       const parentValue = this.parentPath !== undefined ? get(this.configSource, this.parentPath) : null
       return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false)
diff --git a/src/components/settings_modal/helpers/shared_computed_object.js b/src/components/settings_modal/helpers/shared_computed_object.js
index 912999ce..d02db542 100644
--- a/src/components/settings_modal/helpers/shared_computed_object.js
+++ b/src/components/settings_modal/helpers/shared_computed_object.js
@@ -7,6 +7,9 @@ const SharedComputedObject = () => ({
   },
   mergedConfig () {
     return this.$store.getters.mergedConfig
+  },
+  adminConfig () {
+    return this.$store.state.adminSettings.config
   }
 })
 
diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js
index 44a4d409..a84fadbf 100644
--- a/src/modules/adminSettings.js
+++ b/src/modules/adminSettings.js
@@ -29,7 +29,7 @@ const adminSettingsStorage = {
       const config = state.config || {}
       const modifiedPaths = state.modifiedPaths || new Set()
       backendDbConfig.configs.forEach(c => {
-        const path = c.group + '.' + c.key
+        const path = [c.group, c.key]
         if (c.db) {
           c.db.forEach(x => modifiedPaths.add(path + '.' + x))
         }
@@ -44,16 +44,16 @@ const adminSettingsStorage = {
         }
         set(config, path, convert(c.value))
       })
-      console.log(config[':pleroma'][':welcome'])
+      console.log(config[':pleroma'])
       commit('updateAdminSettings', { config, modifiedPaths })
     },
     setInstanceAdminDescriptions ({ state, commit, dispatch }, { backendDescriptions }) {
       const convert = ({ children, description, label, key = '<ROOT>', group, suggestions }, path, acc) => {
-        const newPath = group ? group + '.' + key : key
+        const newPath = group ? [group, key] : [key]
         const obj = { description, label, suggestions }
         if (Array.isArray(children)) {
           children.forEach(c => {
-            convert(c, '.' + newPath, obj)
+            convert(c, newPath, obj)
           })
         }
         set(acc, newPath, obj)
@@ -61,12 +61,13 @@ const adminSettingsStorage = {
 
       const descriptions = {}
       backendDescriptions.forEach(d => convert(d, '', descriptions))
+      console.log(descriptions[':pleroma']['Pleroma.Captcha'])
       commit('updateAdminDescriptions', { descriptions })
     },
     pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) {
-      const [group, key, ...rest] = path.split(/\./g)
+      const [group, key, ...rest] = Array.isArray(path) ? path : path.split(/\./g)
       const clone = {} // not actually cloning the entire thing to avoid excessive writes
-      set(clone, rest.join('.'), value)
+      set(clone, rest, value)
 
       // TODO cleanup paths in modifiedPaths
       const convert = (value) => {
-- 
cgit v1.2.3-70-g09d2


From 2bf224e214d9b42333a2139a89c089ca9a544149 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Tue, 21 Mar 2023 22:46:40 +0200
Subject: made draft-mode and source inject-able

---
 .../settings_modal/admin_tabs/instance_tab.js      |  6 ++
 .../settings_modal/admin_tabs/instance_tab.vue     | 78 ++++------------------
 .../settings_modal/helpers/choice_setting.js       |  3 +-
 .../settings_modal/helpers/choice_setting.vue      |  2 +-
 .../settings_modal/helpers/number_setting.vue      |  2 +-
 src/components/settings_modal/helpers/setting.js   | 41 ++++++++----
 .../settings_modal/helpers/string_setting.vue      |  2 +-
 7 files changed, 50 insertions(+), 84 deletions(-)

(limited to 'src/components/settings_modal/helpers/choice_setting.vue')

diff --git a/src/components/settings_modal/admin_tabs/instance_tab.js b/src/components/settings_modal/admin_tabs/instance_tab.js
index 77a05d38..7aaedbce 100644
--- a/src/components/settings_modal/admin_tabs/instance_tab.js
+++ b/src/components/settings_modal/admin_tabs/instance_tab.js
@@ -14,6 +14,12 @@ library.add(
 )
 
 const InstanceTab = {
+  provide () {
+    return {
+      defaultDraftMode: true,
+      defaultSource: 'admin'
+    }
+  },
   components: {
     BooleanSetting,
     ChoiceSetting,
diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue
index 411982cc..43ad4c8c 100644
--- a/src/components/settings_modal/admin_tabs/instance_tab.vue
+++ b/src/components/settings_modal/admin_tabs/instance_tab.vue
@@ -4,65 +4,37 @@
       <h2>{{ $t('admin_dash.instance.instance') }}</h2>
       <ul class="setting-list">
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:name"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:name">
             NAME
           </StringSetting>
         </li>
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:email"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:email">
             ADMIN EMAIL
           </StringSetting>
         </li>
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:description"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:description">
             DESCRIPTION
           </StringSetting>
         </li>
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:short_description"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:short_description">
             SHORT DESCRIPTION
           </StringSetting>
         </li>
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:instance_thumbnail"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:instance_thumbnail">
             INSTANCE THUMBNAIL
           </StringSetting>
         </li>
         <li>
-          <StringSetting
-            source="admin"
-            path=":pleroma.:instance.:background_image"
-            draft-mode
-          >
+          <StringSetting path=":pleroma.:instance.:background_image">
             BACKGROUND IMAGE
           </StringSetting>
         </li>
         <li>
-          <BooleanSetting
-            source="admin"
-            path=":pleroma.:instance.:public"
-            draft-mode
-          >
+          <BooleanSetting path=":pleroma.:instance.:public">
             PUBLIC
           </BooleanSetting>
         </li>
@@ -72,21 +44,15 @@
       <h2>{{ $t('admin_dash.instance.registrations') }}</h2>
       <ul class="setting-list">
         <li>
-          <BooleanSetting
-            source="admin"
-            path=":pleroma.:instance.:registrations_open"
-            draft-mode
-          >
+          <BooleanSetting path=":pleroma.:instance.:registrations_open">
             REGISTRATIONS OPEN
           </BooleanSetting>
           <ul class="setting-list suboptions">
             <li>
               <BooleanSetting
-                source="admin"
                 path=":pleroma.:instance.:invites_enabled"
                 parent-path=":pleroma.:instance.:registrations_open"
                 :parent-invert="true"
-                draft-mode
               >
                 INVITES ENABLED
               </BooleanSetting>
@@ -94,20 +60,12 @@
           </ul>
         </li>
         <li>
-          <BooleanSetting
-            source="admin"
-            path=":pleroma.:instance.:account_activation_required"
-            draft-mode
-          >
+          <BooleanSetting path=":pleroma.:instance.:account_activation_required">
             ACTIVATION REQUIRED
           </BooleanSetting>
         </li>
         <li>
-          <BooleanSetting
-            source="admin"
-            path=":pleroma.:instance.:account_approval_required"
-            draft-mode
-          >
+          <BooleanSetting path=":pleroma.:instance.:account_approval_required">
             APPROVAL REQUIRED
           </BooleanSetting>
         </li>
@@ -115,32 +73,24 @@
           <h3>{{ $t('admin_dash.instance.captcha_header') }}</h3>
         </li>
         <li>
-          <BooleanSetting
-            source="admin"
-            :path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
-            draft-mode
-          >
+          <BooleanSetting :path="[':pleroma', 'Pleroma.Captcha', ':enabled']">
             CAPTCHA
           </BooleanSetting>
           <ul class="setting-list suboptions">
             <li>
               <ChoiceSetting
-                source="admin"
                 :path="[':pleroma', 'Pleroma.Captcha', ':method']"
                 :parent-path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
                 :option-label-map="{
                   'Pleroma.Captcha.Native': $t('admin_dash.captcha.native'),
                   'Pleroma.Captcha.Kocaptcha': $t('admin_dash.captcha.kocaptcha')
                 }"
-                draft-mode
               >
                 CAPTCHA TYPE
               </ChoiceSetting>
               <IntegerSetting
-                source="admin"
                 :path="[':pleroma', 'Pleroma.Captcha', ':seconds_valid']"
                 :parent-path="[':pleroma', 'Pleroma.Captcha', ':enabled']"
-                draft-mode
               >
                 VALID
               </IntegerSetting>
@@ -152,11 +102,7 @@
           >
             <h4>{{ $t('admin_dash.instance.kocaptcha') }}</h4>
             <li>
-              <StringSetting
-                source="admin"
-                :path="[':pleroma', 'Pleroma.Captcha.Kocaptcha', ':endpoint']"
-                draft-mode
-              >
+              <StringSetting :path="[':pleroma', 'Pleroma.Captcha.Kocaptcha', ':endpoint']">
                 cockAPTCHA ENDPOINT
               </StringSetting>
             </li>
diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js
index 3ff81bc9..bdeece76 100644
--- a/src/components/settings_modal/helpers/choice_setting.js
+++ b/src/components/settings_modal/helpers/choice_setting.js
@@ -22,8 +22,7 @@ export default {
   computed: {
     ...Setting.computed,
     realOptions () {
-      if (this.source === 'admin') {
-        console.log(this.backendDescriptionSuggestions)
+      if (this.realSource === 'admin') {
         return this.backendDescriptionSuggestions.map(x => ({
           key: x,
           value: x,
diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue
index 55f9a62c..8713acf5 100644
--- a/src/components/settings_modal/helpers/choice_setting.vue
+++ b/src/components/settings_modal/helpers/choice_setting.vue
@@ -11,7 +11,7 @@
     </template>
     {{ ' ' }}
     <Select
-      :model-value="draftMode ? draft :state"
+      :model-value="realDraftMode ? draft :state"
       :disabled="disabled"
       @update:modelValue="update"
     >
diff --git a/src/components/settings_modal/helpers/number_setting.vue b/src/components/settings_modal/helpers/number_setting.vue
index 93a7a79a..f97d5cf2 100644
--- a/src/components/settings_modal/helpers/number_setting.vue
+++ b/src/components/settings_modal/helpers/number_setting.vue
@@ -18,7 +18,7 @@
       :step="step || 1"
       :disabled="disabled"
       :min="min || 0"
-      :value="draftMode ? draft :state"
+      :value="realDraftMode ? draft :state"
       @change="update"
     >
     {{ ' ' }}
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
index fd730db9..7cad27b7 100644
--- a/src/components/settings_modal/helpers/setting.js
+++ b/src/components/settings_modal/helpers/setting.js
@@ -31,10 +31,18 @@ export default {
     },
     source: {
       type: String,
-      default: 'default'
+      default: undefined
     },
     draftMode: {
       type: Boolean,
+      default: undefined
+    }
+  },
+  inject: {
+    defaultSource: {
+      default: 'default'
+    },
+    defaultDraftMode: {
       default: false
     }
   },
@@ -44,7 +52,7 @@ export default {
     }
   },
   created () {
-    if (this.draftMode) {
+    if (this.realDraftMode) {
       this.draft = this.state
     }
   },
@@ -57,6 +65,12 @@ export default {
         return value
       }
     },
+    realSource () {
+      return this.source || this.defaultSource
+    },
+    realDraftMode () {
+      return typeof this.draftMode === 'undefined' ? this.defaultDraftMode : this.draftMode
+    },
     backendDescription () {
       return get(this.$store.state.adminSettings.descriptions, this.path)
     },
@@ -74,7 +88,8 @@ export default {
       return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false)
     },
     configSource () {
-      switch (this.source) {
+      console.log('SRC', this.realSource)
+      switch (this.realSource) {
         case 'profile':
           return this.$store.state.profileConfig
         case 'admin':
@@ -84,7 +99,7 @@ export default {
       }
     },
     configSink () {
-      switch (this.source) {
+      switch (this.realSource) {
         case 'profile':
           return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v })
         case 'admin':
@@ -94,7 +109,7 @@ export default {
       }
     },
     defaultState () {
-      switch (this.source) {
+      switch (this.realSource) {
         case 'profile':
           return {}
         default:
@@ -102,10 +117,10 @@ export default {
       }
     },
     isProfileSetting () {
-      return this.source === 'profile'
+      return this.realSource === 'profile'
     },
     isChanged () {
-      switch (this.source) {
+      switch (this.realSource) {
         case 'profile':
         case 'admin':
           return false
@@ -114,10 +129,10 @@ export default {
       }
     },
     isDirty () {
-      return this.draftMode && this.draft !== this.state
+      return this.realDraftMode && this.draft !== this.state
     },
     canHardReset () {
-      return this.source === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path)
+      return this.realSource === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path)
     },
     matchesExpertLevel () {
       return (this.expert || 0) <= this.$store.state.config.expertLevel > 0
@@ -128,20 +143,20 @@ export default {
       return e.target.value
     },
     update (e) {
-      if (this.draftMode) {
+      if (this.realDraftMode) {
         this.draft = this.getValue(e)
       } else {
         this.configSink(this.path, this.getValue(e))
       }
     },
     commitDraft () {
-      if (this.draftMode) {
+      if (this.realDraftMode) {
         this.configSink(this.path, this.draft)
       }
     },
     reset () {
       console.log('reset')
-      if (this.draftMode) {
+      if (this.realDraftMode) {
         console.log(this.draft)
         console.log(this.state)
         this.draft = this.state
@@ -150,7 +165,7 @@ export default {
       }
     },
     hardReset () {
-      switch (this.source) {
+      switch (this.realSource) {
         case 'admin':
           return this.$store.dispatch('resetAdminSetting', { path: this.path })
             .then(() => { this.draft = this.state })
diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue
index 91a4afa4..fb91b5d9 100644
--- a/src/components/settings_modal/helpers/string_setting.vue
+++ b/src/components/settings_modal/helpers/string_setting.vue
@@ -16,7 +16,7 @@
       class="string-input"
       step="1"
       :disabled="disabled"
-      :value="draftMode ? draft :state"
+      :value="realDraftMode ? draft : state"
       @change="update"
     >
     {{ ' ' }}
-- 
cgit v1.2.3-70-g09d2


From 4c158e636bd7ae9ec03a202e54aa681e66645a78 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Wed, 12 Apr 2023 23:58:21 +0300
Subject: more i18n stuff, added missing labels and such

---
 .../settings_modal/admin_tabs/instance_tab.vue     | 12 +++++++
 .../settings_modal/helpers/boolean_setting.vue     |  2 +-
 .../settings_modal/helpers/choice_setting.vue      |  2 +-
 .../settings_modal/helpers/number_setting.vue      |  2 +-
 src/components/settings_modal/helpers/setting.js   | 41 ++++++++++++++++++++--
 .../settings_modal/helpers/string_setting.vue      |  2 +-
 src/i18n/en.json                                   | 23 +++++++++++-
 7 files changed, 77 insertions(+), 7 deletions(-)

(limited to 'src/components/settings_modal/helpers/choice_setting.vue')

diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue
index fc41af65..40e33495 100644
--- a/src/components/settings_modal/admin_tabs/instance_tab.vue
+++ b/src/components/settings_modal/admin_tabs/instance_tab.vue
@@ -58,6 +58,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:timelines.:local"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             LOCAL TIMELINES
           </BooleanSetting>
@@ -66,6 +68,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:timelines.:federated"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             FED TIMELINES
           </BooleanSetting>
@@ -82,6 +86,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:profiles.:local"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             LOCAL PROFILES
           </BooleanSetting>
@@ -90,6 +96,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:profiles.:remote"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             FED PROFILES
           </BooleanSetting>
@@ -106,6 +114,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:activities.:local"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             LOCAL STATUSES
           </BooleanSetting>
@@ -114,6 +124,8 @@
           <BooleanSetting
             path=":pleroma.:restrict_unauthenticated.:activities.:remote"
             indeterminate-state=":if_instance_is_private"
+            swap-description-and-label
+            hide-description
           >
             FED STATUSES
           </BooleanSetting>
diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue
index 6307d526..3089c3b3 100644
--- a/src/components/settings_modal/helpers/boolean_setting.vue
+++ b/src/components/settings_modal/helpers/boolean_setting.vue
@@ -14,7 +14,7 @@
         class="label"
         :class="{ 'faint': shouldBeDisabled }"
       >
-        <template v-if="backendDescription">
+        <template v-if="backendDescriptionLabel">
           {{ backendDescriptionLabel }}
         </template>
         <template v-else>
diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue
index 8713acf5..114e9b7d 100644
--- a/src/components/settings_modal/helpers/choice_setting.vue
+++ b/src/components/settings_modal/helpers/choice_setting.vue
@@ -3,7 +3,7 @@
     v-if="matchesExpertLevel"
     class="ChoiceSetting"
   >
-    <template v-if="backendDescription">
+    <template v-if="backendDescriptionLabel">
       {{ backendDescriptionLabel }}
     </template>
     <template v-else>
diff --git a/src/components/settings_modal/helpers/number_setting.vue b/src/components/settings_modal/helpers/number_setting.vue
index 2b90c336..ce168570 100644
--- a/src/components/settings_modal/helpers/number_setting.vue
+++ b/src/components/settings_modal/helpers/number_setting.vue
@@ -4,7 +4,7 @@
     class="NumberSetting"
   >
     <label :for="path" :class="{ 'faint': shouldBeDisabled }">
-      <template v-if="backendDescription">
+      <template v-if="backendDescriptionLabel">
         {{ backendDescriptionLabel + ' ' }}
       </template>
       <template v-else>
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
index 4f0be448..fec1b947 100644
--- a/src/components/settings_modal/helpers/setting.js
+++ b/src/components/settings_modal/helpers/setting.js
@@ -33,6 +33,18 @@ export default {
       type: String,
       default: undefined
     },
+    hideDescription: {
+      type: Boolean
+    },
+    swapDescriptionAndLabel: {
+      type: Boolean
+    },
+    overrideBackendDescription: {
+      type: Boolean
+    },
+    overrideBackendDescriptionLabel: {
+      type: Boolean
+    },
     draftMode: {
       type: Boolean,
       default: undefined
@@ -95,10 +107,35 @@ export default {
       return get(this.$store.state.adminSettings.descriptions, this.path)
     },
     backendDescriptionLabel () {
-      return this.backendDescription?.label
+      if (this.realSource !== 'admin') return ''
+      if (!this.backendDescription || this.overrideBackendDescriptionLabel) {
+        return this.$t([
+          'admin_dash',
+          'temp_overrides',
+          ...this.canonPath.map(p => p.replace(/\./g, '_DOT_')),
+          'label'
+        ].join('.'))
+      } else {
+        return this.swapDescriptionAndLabel
+          ? this.backendDescription?.description
+          : this.backendDescription?.label
+      }
     },
     backendDescriptionDescription () {
-      return this.backendDescription?.description
+      if (this.realSource !== 'admin') return ''
+      if (this.hideDescription) return null
+      if (!this.backendDescription || this.overrideBackendDescription) {
+        return this.$t([
+          'admin_dash',
+          'temp_overrides',
+          ...this.canonPath.map(p => p.replace(/\./g, '_DOT_')),
+          'description'
+        ].join('.'))
+      } else {
+        return this.swapDescriptionAndLabel
+          ? this.backendDescription?.label
+          : this.backendDescription?.description
+      }
     },
     backendDescriptionSuggestions () {
       return this.backendDescription?.suggestions
diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue
index 5ee75a84..7e70b82f 100644
--- a/src/components/settings_modal/helpers/string_setting.vue
+++ b/src/components/settings_modal/helpers/string_setting.vue
@@ -4,7 +4,7 @@
     class="StringSetting"
   >
     <label :for="path" :class="{ 'faint': shouldBeDisabled }">
-      <template v-if="backendDescription">
+      <template v-if="backendDescriptionLabel">
         {{ backendDescriptionLabel + ' ' }}
       </template>
       <template v-else>
diff --git a/src/i18n/en.json b/src/i18n/en.json
index f4c2df3e..082ad826 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -864,7 +864,14 @@
       "instance": "Instance information",
       "registrations": "User sign-ups",
       "captcha_header": "CAPTCHA",
-      "kocaptcha": "KoCaptcha settings"
+      "kocaptcha": "KoCaptcha settings",
+      "access": "Instance access",
+      "restrict": {
+        "header": "Restrict access",
+        "timelines": "Timelines access",
+        "profiles": "User profiles access",
+        "activities": "Statues/activities access"
+      }
     },
     "limits": {
       "arbitrary_limits": "Arbitrary limits",
@@ -890,6 +897,20 @@
       "default_frontend_tip": "Default front-end will be shown to all users. Currently there's no way to for a user to select personal front-end. If you switch away from PleromaFE you'll most likely have to use old and buggy AdminFE to do instance configuration until we replace it.",
       "default_frontend_tip2": "WIP: Since Pleroma backend doesn't properly list all installed frontends you'll have to enter name and reference manually. List below provides shortcuts to fill the values.",
       "available_frontends": "Available for install"
+    },
+    "temp_overrides": {
+      ":pleroma": {
+        ":instance": {
+          ":description_limit": {
+            "label": "Limit",
+            "description": "Character limit for attachment descriptions"
+          },
+          ":background_image": {
+            "label": "Background image",
+            "description": "Background image (primarily used by PleromaFE)"
+          }
+        }
+      }
     }
   },
   "time": {
-- 
cgit v1.2.3-70-g09d2

