migrate adminSettings to pinia

This commit is contained in:
Henry Jameson 2026-06-09 13:11:21 +03:00
commit 50b356fc1d
15 changed files with 178 additions and 164 deletions

View file

@ -7,7 +7,7 @@ import { useAdminUsersStore } from 'src/stores/adminUsers.js'
const AdminCard = { const AdminCard = {
props: { props: {
userId: { userId: {
type: String type: String,
}, },
}, },
components: { components: {
@ -43,7 +43,7 @@ const AdminCard = {
}, },
isConfirmed() { isConfirmed() {
return this.userAdminData.is_confirmed return this.userAdminData.is_confirmed
} },
}, },
} }

View file

@ -9,6 +9,8 @@ import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import TupleSetting from '../helpers/tuple_setting.vue' import TupleSetting from '../helpers/tuple_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const AuthTab = { const AuthTab = {
provide() { provide() {
return { return {
@ -30,9 +32,7 @@ const AuthTab = {
computed: { computed: {
...SharedComputedObject(), ...SharedComputedObject(),
LDAPEnabled() { LDAPEnabled() {
return this.$store.state.adminSettings.draft[':pleroma'][':ldap'][ return useAdminSettingsStore().draft[':pleroma'][':ldap'][':enabled']
':enabled'
]
}, },
}, },
} }

View file

@ -7,6 +7,7 @@ import IntegerSetting from '../helpers/integer_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
@ -43,7 +44,7 @@ const FrontendsTab = {
computed: { computed: {
...SharedComputedObject(), ...SharedComputedObject(),
frontends() { frontends() {
return this.$store.state.adminSettings.frontends return useAdminSettingsStore().frontends
}, },
}, },
methods: { methods: {
@ -104,7 +105,7 @@ const FrontendsTab = {
const ref = suggestRef || this.getSuggestedRef(frontend) const ref = suggestRef || this.getSuggestedRef(frontend)
const { name } = frontend const { name } = frontend
this.$store.commit('updateAdminDraft', { useAdminSettingsStore.updateAdminDraft({
path: [':pleroma', ':frontends', ':primary'], path: [':pleroma', ':frontends', ':primary'],
value: { name, ref }, value: { name, ref },
}) })

View file

@ -12,6 +12,8 @@ import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import TupleSetting from '../helpers/tuple_setting.vue' import TupleSetting from '../helpers/tuple_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const HTTPTab = { const HTTPTab = {
provide() { provide() {
return { return {
@ -35,7 +37,7 @@ const HTTPTab = {
...SharedComputedObject(), ...SharedComputedObject(),
sslOptions() { sslOptions() {
const desc = get( const desc = get(
this.$store.state.adminSettings.descriptions, useAdminSettingsStore().descriptions,
':pleroma.:http.:adapter.:ssl_options.:versions', ':pleroma.:http.:adapter.:ssl_options.:versions',
) )
return new Set( return new Set(

View file

@ -12,6 +12,8 @@ import PWAManifestIconsSetting from '../helpers/pwa_manifest_icons_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const InstanceTab = { const InstanceTab = {
provide() { provide() {
return { return {
@ -34,7 +36,7 @@ const InstanceTab = {
computed: { computed: {
...SharedComputedObject(), ...SharedComputedObject(),
providersOptions() { providersOptions() {
const desc = get(this.$store.state.adminSettings.descriptions, [ const desc = get(useAdminSettingsStore().descriptions, [
':pleroma', ':pleroma',
'Pleroma.Web.Metadata', 'Pleroma.Web.Metadata',
':providers', ':providers',
@ -47,7 +49,7 @@ const InstanceTab = {
) )
}, },
limitLocalContentOptions() { limitLocalContentOptions() {
const desc = get(this.$store.state.adminSettings.descriptions, [ const desc = get(useAdminSettingsStore().descriptions, [
':pleroma', ':pleroma',
':instance', ':instance',
':limit_to_local_content', ':limit_to_local_content',

View file

@ -10,6 +10,8 @@ import ListSetting from '../helpers/list_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const LinksTab = { const LinksTab = {
provide() { provide() {
return { return {
@ -30,27 +32,27 @@ const LinksTab = {
computed: { computed: {
classIsPresent() { classIsPresent() {
return ( return (
this.$store.state.adminSettings.draft[':pleroma']['Pleroma.Formatter'][ useAdminSettingsStore().draft[':pleroma']['Pleroma.Formatter'][
':class' ':class'
] !== false ] !== false
) )
}, },
relIsPresent() { relIsPresent() {
return ( return (
this.$store.state.adminSettings.draft[':pleroma']['Pleroma.Formatter'][ useAdminSettingsStore().draft[':pleroma']['Pleroma.Formatter'][
':rel' ':rel'
] !== false ] !== false
) )
}, },
truncateIsPresent() { truncateIsPresent() {
return ( return (
this.$store.state.adminSettings.draft[':pleroma']['Pleroma.Formatter'][ useAdminSettingsStore().draft[':pleroma']['Pleroma.Formatter'][
':truncate' ':truncate'
] !== false ] !== false
) )
}, },
truncateDescription() { truncateDescription() {
return get(this.$store.state.adminSettings.descriptions, [ return get(useAdminSettingsStore().descriptions, [
':pleroma', ':pleroma',
'Pleroma.Formatter', 'Pleroma.Formatter',
':truncate', ':truncate',
@ -58,7 +60,7 @@ const LinksTab = {
}, },
ttlSettersOptions() { ttlSettersOptions() {
const desc = get( const desc = get(
this.$store.state.adminSettings.descriptions, useAdminSettingsStore().descriptions,
':pleroma.:rich_media.:ttl_setters', ':pleroma.:rich_media.:ttl_setters',
) )
return new Set( return new Set(
@ -70,7 +72,7 @@ const LinksTab = {
}, },
parsersOptions() { parsersOptions() {
const desc = get( const desc = get(
this.$store.state.adminSettings.descriptions, useAdminSettingsStore().descriptions,
':pleroma.:rich_media.:parsers', ':pleroma.:rich_media.:parsers',
) )
return new Set( return new Set(
@ -97,12 +99,12 @@ const LinksTab = {
] ]
}, },
mediaProxyEnabled() { mediaProxyEnabled() {
return this.$store.state.adminSettings.draft[':pleroma'][':media_proxy'][ return useAdminSettingsStore().draft[':pleroma'][':media_proxy'][
':enabled' ':enabled'
] ]
}, },
mediaInvalidationProvider() { mediaInvalidationProvider() {
return this.$store.state.adminSettings.draft[':pleroma'][':media_proxy'][ return useAdminSettingsStore().draft[':pleroma'][':media_proxy'][
':invalidation' ':invalidation'
][':provider'] ][':provider']
}, },
@ -110,19 +112,19 @@ const LinksTab = {
}, },
methods: { methods: {
checkRel(e) { checkRel(e) {
this.$store.commit('updateAdminDraft', { useAdminSettingsStore.updateAdminDraft({
path: [':pleroma', 'Pleroma.Formatter', ':rel'], path: [':pleroma', 'Pleroma.Formatter', ':rel'],
value: e ? '' : false, value: e ? '' : false,
}) })
}, },
checkClass(e) { checkClass(e) {
this.$store.commit('updateAdminDraft', { useAdminSettingsStore.updateAdminDraft({
path: [':pleroma', 'Pleroma.Formatter', ':class'], path: [':pleroma', 'Pleroma.Formatter', ':class'],
value: e ? '' : false, value: e ? '' : false,
}) })
}, },
checkTruncate(e) { checkTruncate(e) {
this.$store.commit('updateAdminDraft', { useAdminSettingsStore.updateAdminDraft({
path: [':pleroma', 'Pleroma.Formatter', ':truncate'], path: [':pleroma', 'Pleroma.Formatter', ':truncate'],
value: e ? 20 : false, value: e ? 20 : false,
}) })

View file

@ -7,6 +7,8 @@ import IntegerSetting from '../helpers/integer_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const MailerTab = { const MailerTab = {
provide() { provide() {
return { return {
@ -26,7 +28,7 @@ const MailerTab = {
computed: { computed: {
adaptersLabels() { adaptersLabels() {
const prefix = 'Swoosh.Adapters.' const prefix = 'Swoosh.Adapters.'
const descriptions = this.$store.state.adminSettings.descriptions const descriptions = useAdminSettingsStore().descriptions
const options = const options =
descriptions[':pleroma']['Pleroma.Emails.Mailer'][':adapter'] descriptions[':pleroma']['Pleroma.Emails.Mailer'][':adapter']
.suggestions .suggestions
@ -46,20 +48,20 @@ const MailerTab = {
// ])) // ]))
}, },
adapter() { adapter() {
return this.$store.state.adminSettings.draft[':pleroma'][ return useAdminSettingsStore().draft[':pleroma']['Pleroma.Emails.Mailer'][
'Pleroma.Emails.Mailer' ':adapter'
][':adapter'] ]
}, },
mailerEnabled() { mailerEnabled() {
return this.$store.state.adminSettings.draft[':pleroma'][ return useAdminSettingsStore().draft[':pleroma']['Pleroma.Emails.Mailer'][
'Pleroma.Emails.Mailer' ':enabled'
][':enabled'] ]
}, },
...SharedComputedObject(), ...SharedComputedObject(),
}, },
methods: { methods: {
adapterHasKey(key) { adapterHasKey(key) {
const descriptions = this.$store.state.adminSettings.descriptions const descriptions = useAdminSettingsStore().descriptions
const mailerStuff = descriptions[':pleroma']['Pleroma.Emails.Mailer'] const mailerStuff = descriptions[':pleroma']['Pleroma.Emails.Mailer']
const adapterStuff = mailerStuff[':subgroup,' + this.adapter] const adapterStuff = mailerStuff[':subgroup,' + this.adapter]
return Object.hasOwn(adapterStuff, key) return Object.hasOwn(adapterStuff, key)

View file

@ -7,6 +7,8 @@ import ListSetting from '../helpers/list_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const MediaProxyTab = { const MediaProxyTab = {
provide() { provide() {
return { return {
@ -25,12 +27,12 @@ const MediaProxyTab = {
}, },
computed: { computed: {
mediaProxyEnabled() { mediaProxyEnabled() {
return this.$store.state.adminSettings.draft[':pleroma'][':media_proxy'][ return useAdminSettingsStore().draft[':pleroma'][':media_proxy'][
':enabled' ':enabled'
] ]
}, },
mediaInvalidationProvider() { mediaInvalidationProvider() {
return this.$store.state.adminSettings.draft[':pleroma'][':media_proxy'][ return useAdminSettingsStore().draft[':pleroma'][':media_proxy'][
':invalidation' ':invalidation'
][':provider'] ][':provider']
}, },

View file

@ -4,6 +4,8 @@ import IntegerSetting from '../helpers/integer_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import StringSetting from '../helpers/string_setting.vue' import StringSetting from '../helpers/string_setting.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
const UploadsTab = { const UploadsTab = {
provide() { provide() {
return { return {
@ -40,9 +42,9 @@ const UploadsTab = {
}, },
computed: { computed: {
uploader() { uploader() {
return this.$store.state.adminSettings.draft[':pleroma'][ return useAdminSettingsStore().draft[':pleroma']['Pleroma.Upload'][
'Pleroma.Upload' ':uploader'
][':uploader'] ]
}, },
...SharedComputedObject(), ...SharedComputedObject(),
}, },

View file

@ -115,7 +115,8 @@ const UsersTab = {
}, },
methods: { methods: {
fetchUsers(page) { fetchUsers(page) {
return useAdminUsersStore().fetchAdminUsers({ return useAdminUsersStore()
.fetchAdminUsers({
...this.fetchOptions, ...this.fetchOptions,
page, page,
}) })

View file

@ -4,6 +4,7 @@ import DraftButtons from './draft_buttons.vue'
import LocalSettingIndicator from './local_setting_indicator.vue' import LocalSettingIndicator from './local_setting_indicator.vue'
import ModifiedIndicator from './modified_indicator.vue' import ModifiedIndicator from './modified_indicator.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceStore } from 'src/stores/instance.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { useLocalConfigStore } from 'src/stores/local_config.js' import { useLocalConfigStore } from 'src/stores/local_config.js'
@ -125,14 +126,14 @@ export default {
draft: { draft: {
get() { get() {
if (this.realSource === 'admin' || this.path == null) { if (this.realSource === 'admin' || this.path == null) {
return get(this.$store.state.adminSettings.draft, this.canonPath) return get(useAdminSettingsStore().draft, this.canonPath)
} else { } else {
return this.localDraft return this.localDraft
} }
}, },
set(value) { set(value) {
if (this.realSource === 'admin' || this.path == null) { if (this.realSource === 'admin' || this.path == null) {
this.$store.commit('updateAdminDraft', { useAdminSettingsStore.updateAdminDraft({
path: this.canonPath, path: this.canonPath,
value, value,
}) })
@ -164,10 +165,7 @@ export default {
: this.draftMode : this.draftMode
}, },
backendDescription() { backendDescription() {
return get( return get(useAdminSettingsStore().descriptions, this.descriptionPath)
this.$store.state.adminSettings.descriptions,
this.descriptionPath,
)
}, },
backendDescriptionLabel() { backendDescriptionLabel() {
if (this.realSource !== 'admin') return '' if (this.realSource !== 'admin') return ''
@ -221,10 +219,7 @@ export default {
let parentValue = null let parentValue = null
if (this.parentPath !== undefined && this.realSource === 'admin') { if (this.parentPath !== undefined && this.realSource === 'admin') {
if (this.realDraftMode) { if (this.realDraftMode) {
parentValue = get( parentValue = get(useAdminSettingsStore().draft, this.parentPath)
this.$store.state.adminSettings.draft,
this.parentPath,
)
} else { } else {
parentValue = get(this.configSource, this.parentPath) parentValue = get(this.configSource, this.parentPath)
} }
@ -243,7 +238,7 @@ export default {
case 'profile': case 'profile':
return this.$store.state.profileConfig return this.$store.state.profileConfig
case 'admin': case 'admin':
return this.$store.state.adminSettings.config return useAdminSettingsStore().config
default: default:
return useMergedConfigStore().mergedConfig return useMergedConfigStore().mergedConfig
} }
@ -259,7 +254,7 @@ export default {
this.$store.dispatch('setProfileOption', { name: k, value: v }) this.$store.dispatch('setProfileOption', { name: k, value: v })
case 'admin': case 'admin':
return (k, v) => return (k, v) =>
this.$store.dispatch('pushAdminSetting', { path: k, value: v }) useAdminSettingsStore.pushAdminSetting({ path: k, value: v })
default: default:
return (readPath, value) => { return (readPath, value) => {
const writePath = `${readPath}` const writePath = `${readPath}`
@ -372,9 +367,7 @@ export default {
canHardReset() { canHardReset() {
return ( return (
this.realSource === 'admin' && this.realSource === 'admin' &&
this.$store.state.adminSettings.modifiedPaths?.has( useAdminSettingsStore().modifiedPaths?.has(this.canonPath.join(' -> '))
this.canonPath.join(' -> '),
)
) )
}, },
matchesExpertLevel() { matchesExpertLevel() {

View file

@ -8,6 +8,7 @@ import Modal from 'src/components/modal/modal.vue'
import PanelLoading from 'src/components/panel_loading/panel_loading.vue' import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
import Popover from 'src/components/popover/popover.vue' import Popover from 'src/components/popover/popover.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { useLocalConfigStore } from 'src/stores/local_config.js' import { useLocalConfigStore } from 'src/stores/local_config.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
@ -232,10 +233,10 @@ const SettingsModal = {
return clone return clone
}, },
resetAdminDraft() { resetAdminDraft() {
this.$store.commit('resetAdminDraft') useAdminSettingsStore.resetAdminDraft()
}, },
pushAdminDraft() { pushAdminDraft() {
this.$store.dispatch('pushAdminDraft') useAdminSettingsStore.pushAdminDraft()
}, },
...mapActions(useInterfaceStore, [ ...mapActions(useInterfaceStore, [
'temporaryChangesRevert', 'temporaryChangesRevert',
@ -265,8 +266,8 @@ const SettingsModal = {
}, },
adminDraftAny() { adminDraftAny() {
return !isEqual( return !isEqual(
this.$store.state.adminSettings.config, useAdminSettingsStore().config,
this.$store.state.adminSettings.draft, useAdminSettingsStore().draft,
) )
}, },
}, },

View file

@ -19,6 +19,7 @@ import UploadsTab from './admin_tabs/uploads_tab.vue'
import UsersTab from './admin_tabs/users_tab.vue' import UsersTab from './admin_tabs/users_tab.vue'
import VerticalTabSwitcher from './helpers/vertical_tab_switcher.jsx' import VerticalTabSwitcher from './helpers/vertical_tab_switcher.jsx'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
@ -109,18 +110,18 @@ const SettingsModalAdminContent = {
return useInterfaceStore().settingsModalState === 'visible' return useInterfaceStore().settingsModalState === 'visible'
}, },
adminDbLoaded() { adminDbLoaded() {
return this.$store.state.adminSettings.loaded return useAdminSettingsStore().loaded
}, },
adminDescriptionsLoaded() { adminDescriptionsLoaded() {
return this.$store.state.adminSettings.descriptions !== null return useAdminSettingsStore().descriptions !== null
}, },
noDb() { noDb() {
return this.$store.state.adminSettings.dbConfigEnabled === false return useAdminSettingsStore().dbConfigEnabled === false
}, },
}, },
created() { created() {
if (this.user.rights.admin) { if (this.user.rights.admin) {
this.$store.dispatch('loadAdminStuff') useAdminSettingsStore().loadAdminStuff()
} }
}, },
methods: { methods: {

View file

@ -1,4 +1,3 @@
import adminSettings from './adminSettings.js'
import api from './api.js' import api from './api.js'
import chats from './chats.js' import chats from './chats.js'
import drafts from './drafts.js' import drafts from './drafts.js'
@ -13,7 +12,6 @@ export default {
users, users,
api, api,
profileConfig, profileConfig,
adminSettings,
drafts, drafts,
chats, chats,
} }

View file

@ -1,4 +1,5 @@
import { cloneDeep, differenceWith, flatten, get, isEqual, set } from 'lodash' import { cloneDeep, differenceWith, flatten, get, isEqual, set } from 'lodash'
import { defineStore } from 'pinia'
export const defaultState = { export const defaultState = {
frontends: [], frontends: [],
@ -15,17 +16,17 @@ export const newUserFlags = {
...defaultState.flagStorage, ...defaultState.flagStorage,
} }
const adminSettingsStorage = { export const useAdminSettingsStore = defineStore('adminSettings', {
state: { state: () => ({
...cloneDeep(defaultState), ...cloneDeep(defaultState),
}, }),
mutations: { actions: {
setInstanceAdminNoDbConfig(state) { setInstanceAdminNoDbConfig() {
state.loaded = false this.loaded = false
state.dbConfigEnabled = false this.dbConfigEnabled = false
}, },
setAvailableFrontends(state, { frontends }) { setAvailableFrontends({ frontends }) {
state.frontends = frontends.map((f) => { this.frontends = frontends.map((f) => {
f.installedRefs = f.installed_refs f.installedRefs = f.installed_refs
if (f.name === 'pleroma-fe') { if (f.name === 'pleroma-fe') {
f.refs = ['master', 'develop'] f.refs = ['master', 'develop']
@ -35,58 +36,60 @@ const adminSettingsStorage = {
return f return f
}) })
}, },
updateAdminSettings(state, { config, modifiedPaths }) { updateAdminSettings({ config, modifiedPaths }) {
state.loaded = true this.loaded = true
state.dbConfigEnabled = true this.dbConfigEnabled = true
state.config = config this.config = config
state.modifiedPaths = modifiedPaths this.modifiedPaths = modifiedPaths
}, },
updateAdminDescriptions(state, { descriptions }) { updateAdminDescriptions({ descriptions }) {
state.descriptions = descriptions this.descriptions = descriptions
}, },
updateAdminDraft(state, { path, value }) { updateAdminDraft({ path, value }) {
const [group, key, subkey] = path const [group, key, subkey] = path
const parent = [group, key, subkey] const parent = [group, key, subkey]
set(state.draft, path, value) set(this.draft, path, value)
// force-updating grouped draft to trigger refresh of group settings // force-updating grouped draft to trigger refresh of group settings
if (path.length > parent.length) { if (path.length > parent.length) {
set(state.draft, parent, cloneDeep(get(state.draft, parent))) set(this.draft, parent, cloneDeep(get(this.draft, parent)))
} }
}, },
resetAdminDraft(state) { resetAdminDraft() {
state.draft = cloneDeep(state.config) this.draft = cloneDeep(this.config)
}, },
}, async fetchAdminUsers(opts) {
actions: { const data = await window.vuex.state.api.backendInteractor.adminListUsers(
async fetchAdminUsers(store, opts) { {
const data = await store.rootState.api.backendInteractor.adminListUsers({ opts,
opts, },
})
data.users.forEach((user) =>
store.dispatch('fetchUserIfMissing', user.id),
) )
data.users.forEach((user) =>
window.vuex.dispatch('fetchUserIfMissing', user.id),
)
return data return data
}, },
adminAddUserToAdminGroup(store, user) { adminAddUserToAdminGroup(user) {
store.rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.adminAddUserToAdminGroup({ user }) .adminAddUserToAdminGroup({ user })
.then((res) => .then((res) =>
store.commit('updateRight', { window.vuex.commit('updateRight', {
user, user,
right: 'admin', right: 'admin',
value: res.is_admin, value: res.is_admin,
}), }),
) )
}, },
adminRemoveUserFromAdminGroup(store, user) { adminRemoveUserFromAdminGroup(user) {
// prevent revokation of own rights // prevent revokation of own rights
if (user.id !== store.rootState.users.currentUser.id) { if (user.id !== window.vuex.state.users.currentUser.id) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.adminRemoveUserFromAdminGroup({ user }) .adminRemoveUserFromAdminGroup({ user })
.then((res) => .then((res) =>
store.commit('updateRight', { window.vuex.commit('updateRight', {
user, user,
right: 'admin', right: 'admin',
value: res.is_admin, value: res.is_admin,
@ -94,24 +97,24 @@ const adminSettingsStorage = {
) )
} }
}, },
adminAddUserToModeratorGroup(store, user) { adminAddUserToModeratorGroup(user) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.adminAddUserToModeratorGroup({ user }) .adminAddUserToModeratorGroup({ user })
.then((res) => .then((res) =>
store.commit('updateRight', { window.vuex.commit('updateRight', {
user, user,
right: 'moderator', right: 'moderator',
value: res.is_moderator, value: res.is_moderator,
}), }),
) )
}, },
adminRemoveUserFromModeratorGroup(store, user) { adminRemoveUserFromModeratorGroup(user) {
// prevent revokation of own rights // prevent revokation of own rights
if (user.id !== store.state.users.currentUser.id) { if (user.id !== window.vuex.state.users.currentUser.id) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.adminRemoveUserFromModeratorGroup({ user }) .adminRemoveUserFromModeratorGroup({ user })
.then((res) => .then((res) =>
store.commit('updateRight', { window.vuex.commit('updateRight', {
user, user,
right: 'moderator', right: 'moderator',
value: res.is_moderator, value: res.is_moderator,
@ -119,89 +122,89 @@ const adminSettingsStorage = {
) )
} }
}, },
adminActivateUser(store, user) { adminActivateUser(user) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.activateUser({ user }) .activateUser({ user })
.then((res) => { .then((res) => {
const deactivated = !res.is_active const deactivated = !res.is_active
store.commit('updateActivationStatus', { user, deactivated }) window.vuex.commit('updateActivationStatus', { user, deactivated })
}) })
}, },
adminDeactivateUser(store, user) { adminDeactivateUser(user) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.deactivateUser({ user }) .deactivateUser({ user })
.then((res) => { .then((res) => {
const deactivated = !res.is_active const deactivated = !res.is_active
store.commit('updateActivationStatus', { user, deactivated }) window.vuex.commit('updateActivationStatus', { user, deactivated })
}) })
}, },
adminDeleteUser(store, user) { adminDeleteUser(user) {
return store.rootState.api.backendInteractor.deleteUser({ user }) return window.vuex.state.api.backendInteractor.deleteUser({ user })
}, },
adminConfirmUser(store, user) { adminConfirmUser(user) {
return store.rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.adminConfirmUser({ user }) .adminConfirmUser({ user })
.then(() => store.dispatch('fetchUser', user.id)) .then(() => window.vuex.dispatch('fetchUser', user.id))
}, },
adminResendConfirmationEmail(store, user) { adminResendConfirmationEmail(user) {
return store.rootState.api.backendInteractor.adminResendConfirmationEmail( return window.vuex.state.api.backendInteractor.adminResendConfirmationEmail(
{ user }, { user },
) )
}, },
adminApproveUser(store, user) { adminApproveUser(user) {
return store.rootState.api.backendInteractor.adminApproveUser({ user }) return window.vuex.state.api.backendInteractor.adminApproveUser({ user })
}, },
adminListStatuses(store, { userId, opts }) { adminListStatuses({ userId, opts }) {
return store.rootState.api.backendInteractor.adminListStatuses({ return window.vuex.state.api.backendInteractor.adminListStatuses({
userId, userId,
opts, opts,
}) })
}, },
adminChangeStatusScope(store, { opts }) { adminChangeStatusScope({ opts }) {
return store.rootState.api.backendInteractor.adminChangeStatusScope({ return window.vuex.state.api.backendInteractor.adminChangeStatusScope({
opts, opts,
}) })
}, },
adminDisableMFA(store, user) { adminDisableMFA(user) {
return store.rootState.api.backendInteractor.adminDisableMFA({ user }) return window.vuex.state.api.backendInteractor.adminDisableMFA({ user })
}, },
adminTagUser(store, { user, tag }) { adminTagUser({ user, tag }) {
return store.rootState.api.backendInteractor.tagUser({ user, tag }) return window.vuex.state.api.backendInteractor.tagUser({ user, tag })
}, },
adminUntagUser(store, { user, tag }) { adminUntagUser({ user, tag }) {
return store.rootState.api.backendInteractor.untagUser({ user, tag }) return window.vuex.state.api.backendInteractor.untagUser({ user, tag })
}, },
loadFrontendsStuff({ rootState, commit }) { loadFrontendsStuff() {
rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.fetchAvailableFrontends() .fetchAvailableFrontends()
.then((frontends) => commit('setAvailableFrontends', { frontends })) .then((frontends) => this.setAvailableFrontends({ frontends }))
}, },
loadAdminStuff({ state, rootState, dispatch, commit }) { loadAdminStuff() {
rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.fetchInstanceDBConfig() .fetchInstanceDBConfig()
.then((backendDbConfig) => { .then((backendDbConfig) => {
if (backendDbConfig.error) { if (backendDbConfig.error) {
if (backendDbConfig.error.status === 400) { if (backendDbConfig.error.status === 400) {
backendDbConfig.error.json().then((errorJson) => { backendDbConfig.error.json().then((errorJson) => {
if (/configurable_from_database/.test(errorJson.error)) { if (/configurable_from_database/.test(errorJson.error)) {
commit('setInstanceAdminNoDbConfig') this.setInstanceAdminNoDbConfig()
} }
}) })
} }
} else { } else {
dispatch('setInstanceAdminSettings', { backendDbConfig }) this.setInstanceAdminSettings({ backendDbConfig })
} }
}) })
if (state.descriptions === null) { if (this.descriptions === null) {
rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.fetchInstanceConfigDescriptions() .fetchInstanceConfigDescriptions()
.then((backendDescriptions) => .then((backendDescriptions) =>
dispatch('setInstanceAdminDescriptions', { backendDescriptions }), this.setInstanceAdminDescriptions({ backendDescriptions }),
) )
} }
}, },
setInstanceAdminSettings({ state, commit }, { backendDbConfig }) { setInstanceAdminSettings({ backendDbConfig }) {
const config = state.config || {} const config = this.config || {}
const modifiedPaths = new Set() const modifiedPaths = new Set()
backendDbConfig.configs.forEach((c) => { backendDbConfig.configs.forEach((c) => {
@ -257,10 +260,10 @@ const adminSettingsStorage = {
}, },
} }
} }
commit('updateAdminSettings', { config, modifiedPaths }) this.updateAdminSettings({ config, modifiedPaths })
commit('resetAdminDraft') this.resetAdminDraft()
}, },
setInstanceAdminDescriptions({ commit }, { backendDescriptions }) { setInstanceAdminDescriptions({ backendDescriptions }) {
const convert = ( const convert = (
{ children, description, label, key = '<ROOT>', group, suggestions }, { children, description, label, key = '<ROOT>', group, suggestions },
path, path,
@ -279,12 +282,12 @@ const adminSettingsStorage = {
const descriptions = {} const descriptions = {}
backendDescriptions.forEach((d) => convert(d, '', descriptions)) backendDescriptions.forEach((d) => convert(d, '', descriptions))
commit('updateAdminDescriptions', { descriptions }) this.updateAdminDescriptions({ descriptions })
}, },
// This action takes draft state, diffs it with live config state and then pushes // This action takes draft state, diffs it with live config state and then pushes
// only differences between the two. Difference detection only work up to subkey (third) level. // only differences between the two. Difference detection only work up to subkey (third) level.
pushAdminDraft({ rootState, state, dispatch }) { pushAdminDraft() {
// TODO cleanup paths in modifiedPaths // TODO cleanup paths in modifiedPaths
const convert = (value) => { const convert = (value) => {
if (typeof value !== 'object') { if (typeof value !== 'object') {
@ -298,20 +301,20 @@ const adminSettingsStorage = {
// Getting all group-keys used in config // Getting all group-keys used in config
const allGroupKeys = flatten( const allGroupKeys = flatten(
Object.entries(state.config).map(([group, lv1data]) => Object.entries(this.config).map(([group, lv1data]) =>
Object.keys(lv1data).map((key) => ({ group, key })), Object.keys(lv1data).map((key) => ({ group, key })),
), ),
) )
// Only using group-keys where there are changes detected // Only using group-keys where there are changes detected
const changedGroupKeys = allGroupKeys.filter(({ group, key }) => { const changedGroupKeys = allGroupKeys.filter(({ group, key }) => {
return !isEqual(state.config[group][key], state.draft[group][key]) return !isEqual(this.config[group][key], this.draft[group][key])
}) })
// Here we take all changed group-keys and get all changed subkeys // Here we take all changed group-keys and get all changed subkeys
const changed = changedGroupKeys.map(({ group, key }) => { const changed = changedGroupKeys.map(({ group, key }) => {
const config = state.config[group][key] const config = this.config[group][key]
const draft = state.draft[group][key] const draft = this.draft[group][key]
// We convert group-key value into entries arrays // We convert group-key value into entries arrays
const eConfig = Object.entries(config) const eConfig = Object.entries(config)
@ -328,18 +331,20 @@ const adminSettingsStorage = {
} }
}) })
rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.pushInstanceDBConfig({ .pushInstanceDBConfig({
payload: { payload: {
configs: changed, configs: changed,
}, },
}) })
.then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) .then(() =>
window.vuex.state.api.backendInteractor.fetchInstanceDBConfig(),
)
.then((backendDbConfig) => .then((backendDbConfig) =>
dispatch('setInstanceAdminSettings', { backendDbConfig }), this.setInstanceAdminSettings({ backendDbConfig }),
) )
}, },
pushAdminSetting({ rootState, dispatch }, { path, value }) { pushAdminSetting({ path, value }) {
const [group, key, ...rest] = Array.isArray(path) const [group, key, ...rest] = Array.isArray(path)
? path ? path
: path.split(/\./g) : path.split(/\./g)
@ -357,7 +362,7 @@ const adminSettingsStorage = {
} }
} }
rootState.api.backendInteractor window.vuex.state.api.backendInteractor
.pushInstanceDBConfig({ .pushInstanceDBConfig({
payload: { payload: {
configs: [ configs: [
@ -369,19 +374,21 @@ const adminSettingsStorage = {
], ],
}, },
}) })
.then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) .then(() =>
window.vuex.state.api.backendInteractor.fetchInstanceDBConfig(),
)
.then((backendDbConfig) => .then((backendDbConfig) =>
dispatch('setInstanceAdminSettings', { backendDbConfig }), this.setInstanceAdminSettings({ backendDbConfig }),
) )
}, },
resetAdminSetting({ rootState, state, dispatch }, { path }) { resetAdminSetting({ path }) {
const [group, key, subkey] = Array.isArray(path) const [group, key, subkey] = Array.isArray(path)
? path ? path
: path.split(/\./g) : path.split(/\./g)
state.modifiedPaths.delete(path) this.modifiedPaths.delete(path)
return rootState.api.backendInteractor return window.vuex.state.api.backendInteractor
.pushInstanceDBConfig({ .pushInstanceDBConfig({
payload: { payload: {
configs: [ configs: [
@ -394,12 +401,12 @@ const adminSettingsStorage = {
], ],
}, },
}) })
.then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) .then(() =>
window.vuex.state.api.backendInteractor.fetchInstanceDBConfig(),
)
.then((backendDbConfig) => .then((backendDbConfig) =>
dispatch('setInstanceAdminSettings', { backendDbConfig }), this.setInstanceAdminSettings({ backendDbConfig }),
) )
}, },
}, },
} })
export default adminSettingsStorage