From e516eee479cf6e943b6fc43d0a9d18793c141ba0 Mon Sep 17 00:00:00 2001 From: tusooa Date: Tue, 21 Feb 2023 00:39:16 -0500 Subject: Make block & mute lists able to load more --- src/modules/users.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index a1316ba2..7b41fab6 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -195,9 +195,15 @@ export const mutations = { state.currentUser.blockIds.push(blockId) } }, + setBlockIdsMaxId (state, blockIdsMaxId) { + state.currentUser.blockIdsMaxId = blockIdsMaxId + }, saveMuteIds (state, muteIds) { state.currentUser.muteIds = muteIds }, + setMuteIdsMaxId (state, muteIdsMaxId) { + state.currentUser.muteIdsMaxId = muteIdsMaxId + }, addMuteId (state, muteId) { if (state.currentUser.muteIds.indexOf(muteId) === -1) { state.currentUser.muteIds.push(muteId) @@ -320,10 +326,20 @@ const users = { .then((inLists) => store.commit('updateUserInLists', { id, inLists })) } }, - fetchBlocks (store) { - return store.rootState.api.backendInteractor.fetchBlocks() + fetchBlocks (store, args) { + const { reset } = args || {} + + const maxId = store.state.currentUser.blockIdsMaxId + return store.rootState.api.backendInteractor.fetchBlocks({ maxId }) .then((blocks) => { - store.commit('saveBlockIds', map(blocks, 'id')) + if (reset) { + store.commit('saveBlockIds', map(blocks, 'id')) + } else { + map(blocks, 'id').map(id => store.commit('addBlockId', id)) + } + if (blocks.length) { + store.commit('setBlockIdsMaxId', last(blocks).id) + } store.commit('addNewUsers', blocks) return blocks }) @@ -346,10 +362,20 @@ const users = { editUserNote (store, args) { return editUserNote(store, args) }, - fetchMutes (store) { - return store.rootState.api.backendInteractor.fetchMutes() + fetchMutes (store, args) { + const { reset } = args || {} + + const maxId = store.state.currentUser.muteIdsMaxId + return store.rootState.api.backendInteractor.fetchMutes({ maxId }) .then((mutes) => { - store.commit('saveMuteIds', map(mutes, 'id')) + if (reset) { + store.commit('saveMuteIds', map(mutes, 'id')) + } else { + map(mutes, 'id').map(id => store.commit('addMuteId', id)) + } + if (mutes.length) { + store.commit('setMuteIdsMaxId', last(mutes).id) + } store.commit('addNewUsers', mutes) return mutes }) -- cgit v1.2.3-70-g09d2 From 9632b77786a9d3735f04ecf4a814311fad926ad0 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 13 Mar 2023 00:09:47 +0200 Subject: initial implementation of an admin settings module --- src/main.js | 2 ++ src/modules/adminSettings.js | 48 +++++++++++++++++++++++++++++++++++++++++ src/modules/users.js | 39 ++++++++++++++++++--------------- src/services/api/api.service.js | 21 +++++++++++++++++- 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 src/modules/adminSettings.js (limited to 'src/modules/users.js') diff --git a/src/main.js b/src/main.js index fd712113..71f19a82 100644 --- a/src/main.js +++ b/src/main.js @@ -12,6 +12,7 @@ import apiModule from './modules/api.js' import configModule from './modules/config.js' import profileConfigModule from './modules/profileConfig.js' import serverSideStorageModule from './modules/serverSideStorage.js' +import adminSettingsModule from './modules/adminSettings.js' import shoutModule from './modules/shout.js' import oauthModule from './modules/oauth.js' import authFlowModule from './modules/auth_flow.js' @@ -82,6 +83,7 @@ const persistedStateOptions = { config: configModule, profileConfig: profileConfigModule, serverSideStorage: serverSideStorageModule, + adminSettings: adminSettingsModule, shout: shoutModule, oauth: oauthModule, authFlow: authFlowModule, diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js new file mode 100644 index 00000000..01e9a49e --- /dev/null +++ b/src/modules/adminSettings.js @@ -0,0 +1,48 @@ +import { set, cloneDeep } from 'lodash' + +export const defaultState = { + needsReboot: null, + config: null, + modifiedPaths: null +} + +export const newUserFlags = { + ...defaultState.flagStorage +} + +const serverSideStorage = { + state: { + ...cloneDeep(defaultState) + }, + mutations: { + updateAdminSettings (state, { config, modifiedPaths }) { + state.config = config + state.modifiedPaths = modifiedPaths + } + }, + actions: { + setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) { + const config = {} + const modifiedPaths = new Set() + backendDbConfig.configs.forEach(c => { + const path = c.group + '.' + c.key + if (c.db) { + c.db.forEach(x => modifiedPaths.add(path + '.' + x)) + } + const convert = (value) => { + if (Array.isArray(value) && value.length > 0 && value[0].tuple) { + return value.reduce((acc, c) => { + return { ...acc, [c.tuple[0]]: convert(c.tuple[1]) } + }, {}) + } else { + return value + } + } + set(config, path, convert(c.value)) + }) + commit('updateAdminSettings', { config, modifiedPaths }) + } + } +} + +export default serverSideStorage diff --git a/src/modules/users.js b/src/modules/users.js index a1316ba2..74dbdffc 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -551,6 +551,7 @@ const users = { loginUser (store, accessToken) { return new Promise((resolve, reject) => { const commit = store.commit + const dispatch = store.dispatch commit('beginLogin') store.rootState.api.backendInteractor.verifyCredentials(accessToken) .then((data) => { @@ -563,59 +564,63 @@ const users = { user.domainMutes = [] commit('setCurrentUser', user) commit('setServerSideStorage', user) + if (user.rights.moderator || user.rights.admin) { + store.rootState.api.backendInteractor.fetchInstanceDBConfig() + .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) + } commit('addNewUsers', [user]) - store.dispatch('fetchEmoji') + dispatch('fetchEmoji') getNotificationPermission() .then(permission => commit('setNotificationPermission', permission)) // Set our new backend interactor commit('setBackendInteractor', backendInteractorService(accessToken)) - store.dispatch('pushServerSideStorage') + dispatch('pushServerSideStorage') if (user.token) { - store.dispatch('setWsToken', user.token) + dispatch('setWsToken', user.token) // Initialize the shout socket. - store.dispatch('initializeSocket') + dispatch('initializeSocket') } const startPolling = () => { // Start getting fresh posts. - store.dispatch('startFetchingTimeline', { timeline: 'friends' }) + dispatch('startFetchingTimeline', { timeline: 'friends' }) // Start fetching notifications - store.dispatch('startFetchingNotifications') + dispatch('startFetchingNotifications') // Start fetching chats - store.dispatch('startFetchingChats') + dispatch('startFetchingChats') } - store.dispatch('startFetchingLists') + dispatch('startFetchingLists') if (user.locked) { - store.dispatch('startFetchingFollowRequests') + dispatch('startFetchingFollowRequests') } if (store.getters.mergedConfig.useStreamingApi) { - store.dispatch('fetchTimeline', { timeline: 'friends', since: null }) - store.dispatch('fetchNotifications', { since: null }) - store.dispatch('enableMastoSockets', true).catch((error) => { + dispatch('fetchTimeline', { timeline: 'friends', since: null }) + dispatch('fetchNotifications', { since: null }) + dispatch('enableMastoSockets', true).catch((error) => { console.error('Failed initializing MastoAPI Streaming socket', error) }).then(() => { - store.dispatch('fetchChats', { latest: true }) - setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) + dispatch('fetchChats', { latest: true }) + setTimeout(() => dispatch('setNotificationsSilence', false), 10000) }) } else { startPolling() } // Get user mutes - store.dispatch('fetchMutes') + dispatch('fetchMutes') - store.dispatch('setLayoutWidth', windowWidth()) - store.dispatch('setLayoutHeight', windowHeight()) + dispatch('setLayoutWidth', windowWidth()) + dispatch('setLayoutHeight', windowHeight()) // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index b8c10b21..f0aa898a 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -108,6 +108,8 @@ const PLEROMA_POST_ANNOUNCEMENT_URL = '/api/v1/pleroma/admin/announcements' const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` +const PLEROMA_ADMIN_CONFIG_URL = '/api/v1/pleroma/admin/config' + const oldfetch = window.fetch const fetch = (url, options) => { @@ -1659,6 +1661,22 @@ const setReportState = ({ id, state, credentials }) => { }) } +// ADMIN STUFF // EXPERIMENTAL +const fetchInstanceDBConfig = ({ credentials }) => { + return fetch(PLEROMA_ADMIN_CONFIG_URL, { + headers: authHeaders(credentials) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -1772,7 +1790,8 @@ const apiService = { postAnnouncement, editAnnouncement, deleteAnnouncement, - adminFetchAnnouncements + adminFetchAnnouncements, + fetchInstanceDBConfig } export default apiService -- cgit v1.2.3-70-g09d2 From bfd802ad046886230574cf2262f9c2e5f1b03a3f Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 16 Mar 2023 23:18:55 +0200 Subject: setting admin settings works now. also now we have draftable settings --- .../settings_modal/admin_tabs/instance_tab.vue | 23 ++++- .../settings_modal/helpers/boolean_setting.js | 15 +-- .../settings_modal/helpers/boolean_setting.vue | 3 +- .../settings_modal/helpers/choice_setting.js | 9 +- .../settings_modal/helpers/draft_buttons.vue | 102 +++++++++++++++++++++ .../settings_modal/helpers/integer_setting.js | 8 +- .../settings_modal/helpers/integer_setting.vue | 4 +- src/components/settings_modal/helpers/setting.js | 70 ++++++++++++-- .../settings_modal/helpers/size_setting.js | 5 +- .../settings_modal/helpers/string_setting.js | 4 - .../settings_modal/helpers/string_setting.vue | 6 +- src/modules/adminSettings.js | 52 ++++++++++- src/modules/users.js | 2 +- src/services/api/api.service.js | 26 +++++- 14 files changed, 284 insertions(+), 45 deletions(-) create mode 100644 src/components/settings_modal/helpers/draft_buttons.vue (limited to 'src/modules/users.js') diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue index 65b3d12f..18ba6127 100644 --- a/src/components/settings_modal/admin_tabs/instance_tab.vue +++ b/src/components/settings_modal/admin_tabs/instance_tab.vue @@ -1,18 +1,35 @@ diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js index 8aa5f54b..a3c3bf44 100644 --- a/src/components/settings_modal/helpers/choice_setting.js +++ b/src/components/settings_modal/helpers/choice_setting.js @@ -1,15 +1,12 @@ import Select from 'src/components/select/select.vue' -import ModifiedIndicator from './modified_indicator.vue' -import ProfileSettingIndicator from './profile_setting_indicator.vue' import Setting from './setting.js' export default { + ...Setting, components: { - Select, - ModifiedIndicator, - ProfileSettingIndicator + ...Setting.components, + Select }, - ...Setting, props: { ...Setting.props, options: { diff --git a/src/components/settings_modal/helpers/draft_buttons.vue b/src/components/settings_modal/helpers/draft_buttons.vue new file mode 100644 index 00000000..0d99da13 --- /dev/null +++ b/src/components/settings_modal/helpers/draft_buttons.vue @@ -0,0 +1,102 @@ + + + + + + + diff --git a/src/components/settings_modal/helpers/integer_setting.js b/src/components/settings_modal/helpers/integer_setting.js index 0f29f11a..8ad033e7 100644 --- a/src/components/settings_modal/helpers/integer_setting.js +++ b/src/components/settings_modal/helpers/integer_setting.js @@ -1,15 +1,11 @@ -import ModifiedIndicator from './modified_indicator.vue' import Setting from './setting.js' export default { - components: { - ModifiedIndicator - }, ...Setting, methods: { ...Setting.methods, - update (e) { - this.configSink(this.path, parseInt(e.target.value)) + getValue (e) { + return parseInt(e.target.value) } } } diff --git a/src/components/settings_modal/helpers/integer_setting.vue b/src/components/settings_modal/helpers/integer_setting.vue index 695e2673..e900b87c 100644 --- a/src/components/settings_modal/helpers/integer_setting.vue +++ b/src/components/settings_modal/helpers/integer_setting.vue @@ -13,7 +13,7 @@ step="1" :disabled="disabled" :min="min || 0" - :value="state" + :value="draftMode ? draft :state" @change="update" > {{ ' ' }} @@ -21,6 +21,8 @@ :changed="isChanged" :onclick="reset" /> + + diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index 9195d3e9..0971b919 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -1,5 +1,16 @@ +import Checkbox from 'src/components/checkbox/checkbox.vue' +import ModifiedIndicator from './modified_indicator.vue' +import ProfileSettingIndicator from './profile_setting_indicator.vue' +import DraftButtons from './draft_buttons.vue' import { get, set } from 'lodash' + export default { + components: { + Checkbox, + ModifiedIndicator, + DraftButtons, + ProfileSettingIndicator + }, props: { path: { type: String, @@ -23,6 +34,20 @@ export default { source: { type: String, default: 'default' + }, + draftMode: { + type: Boolean, + default: false + } + }, + data () { + return { + draft: null + } + }, + created () { + if (this.draftMode) { + this.draft = this.state } }, computed: { @@ -53,7 +78,7 @@ export default { case 'profile': return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v }) case 'admin': - return (k, v) => console.log(this.path, k, v) + return (k, v) => this.$store.dispatch('pushAdminSetting', { path: k, value: v }) default: return (k, v) => this.$store.dispatch('setOption', { name: k, value: v }) } @@ -72,25 +97,56 @@ export default { isChanged () { switch (this.source) { case 'profile': - return false case 'admin': - console.log(this.$store.state.adminSettings.modifiedPaths) - return this.$store.state.adminSettings.modifiedPaths.has(this.path) + return false default: return this.state !== this.defaultState } }, + isDirty () { + return this.draftMode && this.draft !== this.state + }, + canHardReset () { + return this.source === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path) + }, matchesExpertLevel () { return (this.expert || 0) <= this.$store.state.config.expertLevel > 0 } }, methods: { + getValue (e) { + return e.target.value + }, update (e) { - console.log('U', this.path, e) - this.configSink(this.path, e) + if (this.draftMode) { + this.draft = this.getValue(e) + } else { + this.configSink(this.path, this.getValue(e)) + } + }, + commitDraft () { + if (this.draftMode) { + this.configSink(this.path, this.draft) + } }, reset () { - set(this.$store.getters.mergedConfig, this.path, this.defaultState) + console.log('reset') + if (this.draftMode) { + console.log(this.draft) + console.log(this.state) + this.draft = this.state + } else { + set(this.$store.getters.mergedConfig, this.path, this.defaultState) + } + }, + hardReset () { + switch (this.source) { + case 'admin': + return this.$store.dispatch('resetAdminSetting', { path: this.path }) + .then(() => { this.draft = this.state }) + default: + console.warn('Hard reset not implemented yet!') + } } } } diff --git a/src/components/settings_modal/helpers/size_setting.js b/src/components/settings_modal/helpers/size_setting.js index 4a0f7e48..12cef705 100644 --- a/src/components/settings_modal/helpers/size_setting.js +++ b/src/components/settings_modal/helpers/size_setting.js @@ -1,4 +1,3 @@ -import ModifiedIndicator from './modified_indicator.vue' import Select from 'src/components/select/select.vue' import Setting from './setting.js' @@ -7,11 +6,11 @@ export const defaultHorizontalUnits = ['px', 'rem', 'vw'] export const defaultVerticalUnits = ['px', 'rem', 'vh'] export default { + ...Setting, components: { - ModifiedIndicator, + ...Setting.components, Select }, - ...Setting, props: { ...Setting.props, min: Number, diff --git a/src/components/settings_modal/helpers/string_setting.js b/src/components/settings_modal/helpers/string_setting.js index 64f8772d..b368cfc8 100644 --- a/src/components/settings_modal/helpers/string_setting.js +++ b/src/components/settings_modal/helpers/string_setting.js @@ -1,9 +1,5 @@ -import ModifiedIndicator from './modified_indicator.vue' import Setting from './setting.js' export default { - components: { - ModifiedIndicator - }, ...Setting } diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue index e4bd2de9..0a71aeab 100644 --- a/src/components/settings_modal/helpers/string_setting.vue +++ b/src/components/settings_modal/helpers/string_setting.vue @@ -11,7 +11,7 @@ class="string-input" step="1" :disabled="disabled" - :value="state" + :value="draftMode ? draft :state" @change="update" > {{ ' ' }} @@ -19,7 +19,9 @@ :changed="isChanged" :onclick="reset" /> + + - + diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index 8006717d..d1df67d4 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -22,8 +22,8 @@ const adminSettingsStorage = { }, actions: { setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) { - const config = {} - const modifiedPaths = new Set() + const config = state.config || {} + const modifiedPaths = state.modifiedPaths || new Set() backendDbConfig.configs.forEach(c => { const path = c.group + '.' + c.key if (c.db) { @@ -40,8 +40,54 @@ const adminSettingsStorage = { } set(config, path, convert(c.value)) }) - console.log(config) commit('updateAdminSettings', { config, modifiedPaths }) + }, + pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) { + const [group, key, ...rest] = path.split(/\./g) + const clone = {} // not actually cloning the entire thing to avoid excessive writes + set(clone, rest.join('.'), value) + + // TODO cleanup paths in modifiedPaths + const convert = (value) => { + if (typeof value !== 'object') { + return value + } else if (Array.isArray(value)) { + return value.map(convert) + } else { + return Object.entries(value).map(([k, v]) => ({ tuple: [k, v] })) + } + } + + rootState.api.backendInteractor.pushInstanceDBConfig({ + payload: { + configs: [{ + group, + key, + value: convert(clone) + }] + } + }) + .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) + .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) + }, + resetAdminSetting ({ rootState, state, commit, dispatch }, { path }) { + console.log('ASS') + const [group, key, subkey] = path.split(/\./g) + + state.modifiedPaths.delete(path) + + return rootState.api.backendInteractor.pushInstanceDBConfig({ + payload: { + configs: [{ + group, + key, + delete: true, + subkeys: [subkey] + }] + } + }) + .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) + .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) } } } diff --git a/src/modules/users.js b/src/modules/users.js index 74dbdffc..12e582f4 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -564,7 +564,7 @@ const users = { user.domainMutes = [] commit('setCurrentUser', user) commit('setServerSideStorage', user) - if (user.rights.moderator || user.rights.admin) { + if (user.rights.admin) { store.rootState.api.backendInteractor.fetchInstanceDBConfig() .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) } diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index f0aa898a..71ba1dec 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -108,7 +108,7 @@ const PLEROMA_POST_ANNOUNCEMENT_URL = '/api/v1/pleroma/admin/announcements' const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` -const PLEROMA_ADMIN_CONFIG_URL = '/api/v1/pleroma/admin/config' +const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config' const oldfetch = window.fetch @@ -1677,6 +1677,27 @@ const fetchInstanceDBConfig = ({ credentials }) => { }) } +const pushInstanceDBConfig = ({ credentials, payload }) => { + return fetch(PLEROMA_ADMIN_CONFIG_URL, { + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...authHeaders(credentials) + }, + method: 'POST', + body: JSON.stringify(payload) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -1791,7 +1812,8 @@ const apiService = { editAnnouncement, deleteAnnouncement, adminFetchAnnouncements, - fetchInstanceDBConfig + fetchInstanceDBConfig, + pushInstanceDBConfig } export default apiService -- cgit v1.2.3-70-g09d2 From 332ad77e3579d2b512ba236b3f2c94ad8875864d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 19 Mar 2023 21:27:07 +0200 Subject: limits tab, backend descriptions --- .../settings_modal/admin_tabs/instance_tab.vue | 103 +++++++++++--- .../settings_modal/admin_tabs/limits_tab.js | 29 ++++ .../settings_modal/admin_tabs/limits_tab.vue | 152 +++++++++++++++++++++ .../settings_modal/helpers/boolean_setting.vue | 13 +- .../settings_modal/helpers/integer_setting.vue | 13 +- src/components/settings_modal/helpers/setting.js | 10 ++ .../settings_modal/helpers/string_setting.vue | 13 +- src/components/settings_modal/settings_modal.scss | 6 + .../settings_modal/settings_modal_admin_content.js | 4 +- .../settings_modal_admin_content.vue | 9 +- src/modules/adminSettings.js | 24 +++- src/modules/users.js | 2 + src/services/api/api.service.js | 17 +++ 13 files changed, 370 insertions(+), 25 deletions(-) create mode 100644 src/components/settings_modal/admin_tabs/limits_tab.js create mode 100644 src/components/settings_modal/admin_tabs/limits_tab.vue (limited to 'src/modules/users.js') diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue index 18ba6127..ad271293 100644 --- a/src/components/settings_modal/admin_tabs/instance_tab.vue +++ b/src/components/settings_modal/admin_tabs/instance_tab.vue @@ -12,6 +12,15 @@ NAME +
  • + + ADMIN EMAIL + +
  • - - POST LIMIT - + SHORT DESCRIPTION + +
  • +
  • + + INSTANCE THUMBNAIL + +
  • +
  • + + BACKGROUND IMAGE + +
  • +
  • + + PUBLIC + +
  • + + +
    +

    {{ $t('admin_dash.registrations') }}

    +
      +
    • + + REGISTRATIONS OPEN + +
        +
      • + + INVITES ENABLED + +
      • +
      +
    • +
    • + + ACTIVATION REQUIRED + +
    • +
    • + + APPROVAL REQUIRED +
    @@ -36,17 +117,3 @@ - - diff --git a/src/components/settings_modal/admin_tabs/limits_tab.js b/src/components/settings_modal/admin_tabs/limits_tab.js new file mode 100644 index 00000000..684739c3 --- /dev/null +++ b/src/components/settings_modal/admin_tabs/limits_tab.js @@ -0,0 +1,29 @@ +import BooleanSetting from '../helpers/boolean_setting.vue' +import ChoiceSetting from '../helpers/choice_setting.vue' +import IntegerSetting from '../helpers/integer_setting.vue' +import StringSetting from '../helpers/string_setting.vue' + +import SharedComputedObject from '../helpers/shared_computed_object.js' +import { library } from '@fortawesome/fontawesome-svg-core' +import { + faGlobe +} from '@fortawesome/free-solid-svg-icons' + +library.add( + faGlobe +) + +const LimitsTab = { + data () {}, + components: { + BooleanSetting, + ChoiceSetting, + IntegerSetting, + StringSetting + }, + computed: { + ...SharedComputedObject() + } +} + +export default LimitsTab diff --git a/src/components/settings_modal/admin_tabs/limits_tab.vue b/src/components/settings_modal/admin_tabs/limits_tab.vue new file mode 100644 index 00000000..3f07c554 --- /dev/null +++ b/src/components/settings_modal/admin_tabs/limits_tab.vue @@ -0,0 +1,152 @@ + + + diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue index 7e05fe85..aedbf23e 100644 --- a/src/components/settings_modal/helpers/boolean_setting.vue +++ b/src/components/settings_modal/helpers/boolean_setting.vue @@ -12,7 +12,12 @@ v-if="!!$slots.default" class="label" > - + + {{ ' ' }} +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/helpers/integer_setting.vue b/src/components/settings_modal/helpers/integer_setting.vue index e900b87c..e935dfb0 100644 --- a/src/components/settings_modal/helpers/integer_setting.vue +++ b/src/components/settings_modal/helpers/integer_setting.vue @@ -4,7 +4,12 @@ class="IntegerSetting" > +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index 0971b919..f270216f 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -59,6 +59,16 @@ export default { return value } }, + backendDescription () { + console.log(get(this.$store.state.adminSettings.descriptions, this.path)) + return get(this.$store.state.adminSettings.descriptions, this.path) + }, + backendDescriptionLabel () { + return this.backendDescription.label + }, + backendDescriptionDescription () { + return this.backendDescription.description + }, 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/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue index 0a71aeab..91a4afa4 100644 --- a/src/components/settings_modal/helpers/string_setting.vue +++ b/src/components/settings_modal/helpers/string_setting.vue @@ -4,7 +4,12 @@ class="StringSetting" > +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/settings_modal.scss b/src/components/settings_modal/settings_modal.scss index f5861229..4cce6099 100644 --- a/src/components/settings_modal/settings_modal.scss +++ b/src/components/settings_modal/settings_modal.scss @@ -17,6 +17,12 @@ } } + .setting-description { + margin-top: 0.2em; + margin-bottom: 2em; + font-size: 70%; + } + .settings-modal-panel { overflow: hidden; transition: transform; diff --git a/src/components/settings_modal/settings_modal_admin_content.js b/src/components/settings_modal/settings_modal_admin_content.js index 88ba1755..c6c8837f 100644 --- a/src/components/settings_modal/settings_modal_admin_content.js +++ b/src/components/settings_modal/settings_modal_admin_content.js @@ -3,6 +3,7 @@ import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' import DataImportExportTab from './tabs/data_import_export_tab.vue' import MutesAndBlocksTab from './tabs/mutes_and_blocks_tab.vue' import InstanceTab from './admin_tabs/instance_tab.vue' +import LimitsTab from './admin_tabs/limits_tab.vue' import { library } from '@fortawesome/fontawesome-svg-core' import { @@ -33,7 +34,8 @@ const SettingsModalAdminContent = { DataImportExportTab, MutesAndBlocksTab, - InstanceTab + InstanceTab, + LimitsTab }, computed: { isLoggedIn () { diff --git a/src/components/settings_modal/settings_modal_admin_content.vue b/src/components/settings_modal/settings_modal_admin_content.vue index 9873b127..16b55828 100644 --- a/src/components/settings_modal/settings_modal_admin_content.vue +++ b/src/components/settings_modal/settings_modal_admin_content.vue @@ -7,12 +7,19 @@ :body-scroll-lock="bodyLock" >
    +
    + +
    diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index d1df67d4..44a4d409 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -3,7 +3,8 @@ import { set, cloneDeep } from 'lodash' export const defaultState = { needsReboot: null, config: null, - modifiedPaths: null + modifiedPaths: null, + descriptions: null } export const newUserFlags = { @@ -18,6 +19,9 @@ const adminSettingsStorage = { updateAdminSettings (state, { config, modifiedPaths }) { state.config = config state.modifiedPaths = modifiedPaths + }, + updateAdminDescriptions (state, { descriptions }) { + state.descriptions = descriptions } }, actions: { @@ -40,8 +44,25 @@ const adminSettingsStorage = { } set(config, path, convert(c.value)) }) + console.log(config[':pleroma'][':welcome']) commit('updateAdminSettings', { config, modifiedPaths }) }, + setInstanceAdminDescriptions ({ state, commit, dispatch }, { backendDescriptions }) { + const convert = ({ children, description, label, key = '', group, suggestions }, path, acc) => { + const newPath = group ? group + '.' + key : key + const obj = { description, label, suggestions } + if (Array.isArray(children)) { + children.forEach(c => { + convert(c, '.' + newPath, obj) + }) + } + set(acc, newPath, obj) + } + + const descriptions = {} + backendDescriptions.forEach(d => convert(d, '', descriptions)) + commit('updateAdminDescriptions', { descriptions }) + }, pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) { const [group, key, ...rest] = path.split(/\./g) const clone = {} // not actually cloning the entire thing to avoid excessive writes @@ -71,7 +92,6 @@ const adminSettingsStorage = { .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) }, resetAdminSetting ({ rootState, state, commit, dispatch }, { path }) { - console.log('ASS') const [group, key, subkey] = path.split(/\./g) state.modifiedPaths.delete(path) diff --git a/src/modules/users.js b/src/modules/users.js index 12e582f4..45cba334 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -567,6 +567,8 @@ const users = { if (user.rights.admin) { store.rootState.api.backendInteractor.fetchInstanceDBConfig() .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) + store.rootState.api.backendInteractor.fetchInstanceConfigDescriptions() + .then(backendDescriptions => dispatch('setInstanceAdminDescriptions', { backendDescriptions })) } commit('addNewUsers', [user]) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 71ba1dec..073f40a3 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -109,6 +109,7 @@ const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config' +const PLEROMA_ADMIN_DESCRIPTIONS_URL = '/api/pleroma/admin/config/descriptions' const oldfetch = window.fetch @@ -1677,6 +1678,21 @@ const fetchInstanceDBConfig = ({ credentials }) => { }) } +const fetchInstanceConfigDescriptions = ({ credentials }) => { + return fetch(PLEROMA_ADMIN_DESCRIPTIONS_URL, { + headers: authHeaders(credentials) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const pushInstanceDBConfig = ({ credentials, payload }) => { return fetch(PLEROMA_ADMIN_CONFIG_URL, { headers: { @@ -1813,6 +1829,7 @@ const apiService = { deleteAnnouncement, adminFetchAnnouncements, fetchInstanceDBConfig, + fetchInstanceConfigDescriptions, pushInstanceDBConfig } -- cgit v1.2.3-70-g09d2 From 4c3af5c362574aad4d851990265ebc7252c6f990 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 27 Mar 2023 22:57:50 +0300 Subject: handle db config disabled case --- .../settings_modal/settings_modal_admin_content.js | 18 ++++++++-- .../settings_modal_admin_content.vue | 39 ++++++++++++++++++++++ src/i18n/en.json | 10 +++++- src/modules/adminSettings.js | 30 ++++++++++++++++- src/modules/users.js | 6 ---- 5 files changed, 93 insertions(+), 10 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/settings_modal/settings_modal_admin_content.js b/src/components/settings_modal/settings_modal_admin_content.js index 07d4cf2e..1c239e59 100644 --- a/src/components/settings_modal/settings_modal_admin_content.js +++ b/src/components/settings_modal/settings_modal_admin_content.js @@ -9,7 +9,7 @@ import { library } from '@fortawesome/fontawesome-svg-core' import { faWrench, faHand, - faFilter, + faLaptopCode, faPaintBrush, faBell, faDownload, @@ -20,7 +20,7 @@ import { library.add( faWrench, faHand, - faFilter, + faLaptopCode, faPaintBrush, faBell, faDownload, @@ -38,6 +38,9 @@ const SettingsModalAdminContent = { LimitsTab }, computed: { + user () { + return this.$store.state.users.currentUser + }, isLoggedIn () { return !!this.$store.state.users.currentUser }, @@ -46,6 +49,17 @@ const SettingsModalAdminContent = { }, bodyLock () { return this.$store.state.interface.settingsModalState === 'visible' + }, + adminDbLoaded () { + return this.$store.state.adminSettings.loaded + }, + noDb () { + return this.$store.state.adminSettings.dbConfigEnabled === false + } + }, + created () { + if (this.user.rights.admin) { + this.$store.dispatch('loadAdminStuff') } }, methods: { diff --git a/src/components/settings_modal/settings_modal_admin_content.vue b/src/components/settings_modal/settings_modal_admin_content.vue index 52c6ddf5..ae670a90 100644 --- a/src/components/settings_modal/settings_modal_admin_content.vue +++ b/src/components/settings_modal/settings_modal_admin_content.vue @@ -4,9 +4,40 @@ class="settings_tab-switcher" :side-tab-bar="true" :scrollable-tabs="true" + :render-only-focused="true" :body-scroll-lock="bodyLock" >
    +
    +
    +

    {{ $t('admin_dash.nodb.heading') }}

    + + + + + +

    {{ $t('admin_dash.nodb.text2') }}

    +
    +
    +
    +
    +
    + +
    diff --git a/src/i18n/en.json b/src/i18n/en.json index dd78d148..86ae7f06 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -845,8 +845,16 @@ "reset_all": "Reset all", "commit_all": "Save all", "tabs": { + "nodb": "No DB Config", "instance": "Instance", - "limits": "Limits" + "limits": "Limits", + "frontends": "Front-ends" + }, + "nodb": { + "heading": "Database config is disabled", + "text": "You need to change backend config files so that {property} is set to {value}, see more in {documentation}.", + "documentation": "documentation", + "text2": "Most configuration options will be unavailable." }, "captcha": { "native": "Native", diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index 25fb8e50..fef73974 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -1,11 +1,13 @@ import { set, get, cloneDeep, differenceWith, isEqual, flatten } from 'lodash' export const defaultState = { + loaded: false, needsReboot: null, config: null, modifiedPaths: null, descriptions: null, - draft: null + draft: null, + dbConfigEnabled: null } export const newUserFlags = { @@ -17,7 +19,13 @@ const adminSettingsStorage = { ...cloneDeep(defaultState) }, mutations: { + setInstanceAdminNoDbConfig (state) { + state.loaded = false + state.dbConfigEnabled = false + }, updateAdminSettings (state, { config, modifiedPaths }) { + state.loaded = true + state.dbConfigEnabled = true state.config = config state.modifiedPaths = modifiedPaths }, @@ -40,6 +48,26 @@ const adminSettingsStorage = { } }, actions: { + loadAdminStuff ({ state, rootState, dispatch, commit }) { + rootState.api.backendInteractor.fetchInstanceDBConfig() + .then(backendDbConfig => { + if (backendDbConfig.error) { + if (backendDbConfig.error.status === 400) { + backendDbConfig.error.json().then(errorJson => { + if (/configurable_from_database/.test(errorJson.error)) { + commit('setInstanceAdminNoDbConfig') + } + }) + } + } else { + dispatch('setInstanceAdminSettings', { backendDbConfig }) + } + }) + if (state.descriptions === null) { + rootState.api.backendInteractor.fetchInstanceConfigDescriptions() + .then(backendDescriptions => this.$store.dispatch('setInstanceAdminDescriptions', { backendDescriptions })) + } + }, setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) { const config = state.config || {} const modifiedPaths = new Set() diff --git a/src/modules/users.js b/src/modules/users.js index 45cba334..a23f6d7d 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -564,12 +564,6 @@ const users = { user.domainMutes = [] commit('setCurrentUser', user) commit('setServerSideStorage', user) - if (user.rights.admin) { - store.rootState.api.backendInteractor.fetchInstanceDBConfig() - .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) - store.rootState.api.backendInteractor.fetchInstanceConfigDescriptions() - .then(backendDescriptions => dispatch('setInstanceAdminDescriptions', { backendDescriptions })) - } commit('addNewUsers', [user]) dispatch('fetchEmoji') -- cgit v1.2.3-70-g09d2