initial implementation of an admin settings module
This commit is contained in:
parent
55ea6df40b
commit
9632b77786
@ -12,6 +12,7 @@ import apiModule from './modules/api.js'
|
|||||||
import configModule from './modules/config.js'
|
import configModule from './modules/config.js'
|
||||||
import profileConfigModule from './modules/profileConfig.js'
|
import profileConfigModule from './modules/profileConfig.js'
|
||||||
import serverSideStorageModule from './modules/serverSideStorage.js'
|
import serverSideStorageModule from './modules/serverSideStorage.js'
|
||||||
|
import adminSettingsModule from './modules/adminSettings.js'
|
||||||
import shoutModule from './modules/shout.js'
|
import shoutModule from './modules/shout.js'
|
||||||
import oauthModule from './modules/oauth.js'
|
import oauthModule from './modules/oauth.js'
|
||||||
import authFlowModule from './modules/auth_flow.js'
|
import authFlowModule from './modules/auth_flow.js'
|
||||||
@ -82,6 +83,7 @@ const persistedStateOptions = {
|
|||||||
config: configModule,
|
config: configModule,
|
||||||
profileConfig: profileConfigModule,
|
profileConfig: profileConfigModule,
|
||||||
serverSideStorage: serverSideStorageModule,
|
serverSideStorage: serverSideStorageModule,
|
||||||
|
adminSettings: adminSettingsModule,
|
||||||
shout: shoutModule,
|
shout: shoutModule,
|
||||||
oauth: oauthModule,
|
oauth: oauthModule,
|
||||||
authFlow: authFlowModule,
|
authFlow: authFlowModule,
|
||||||
|
48
src/modules/adminSettings.js
Normal file
48
src/modules/adminSettings.js
Normal file
@ -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
|
@ -551,6 +551,7 @@ const users = {
|
|||||||
loginUser (store, accessToken) {
|
loginUser (store, accessToken) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const commit = store.commit
|
const commit = store.commit
|
||||||
|
const dispatch = store.dispatch
|
||||||
commit('beginLogin')
|
commit('beginLogin')
|
||||||
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
|
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@ -563,59 +564,63 @@ const users = {
|
|||||||
user.domainMutes = []
|
user.domainMutes = []
|
||||||
commit('setCurrentUser', user)
|
commit('setCurrentUser', user)
|
||||||
commit('setServerSideStorage', user)
|
commit('setServerSideStorage', user)
|
||||||
|
if (user.rights.moderator || user.rights.admin) {
|
||||||
|
store.rootState.api.backendInteractor.fetchInstanceDBConfig()
|
||||||
|
.then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig }))
|
||||||
|
}
|
||||||
commit('addNewUsers', [user])
|
commit('addNewUsers', [user])
|
||||||
|
|
||||||
store.dispatch('fetchEmoji')
|
dispatch('fetchEmoji')
|
||||||
|
|
||||||
getNotificationPermission()
|
getNotificationPermission()
|
||||||
.then(permission => commit('setNotificationPermission', permission))
|
.then(permission => commit('setNotificationPermission', permission))
|
||||||
|
|
||||||
// Set our new backend interactor
|
// Set our new backend interactor
|
||||||
commit('setBackendInteractor', backendInteractorService(accessToken))
|
commit('setBackendInteractor', backendInteractorService(accessToken))
|
||||||
store.dispatch('pushServerSideStorage')
|
dispatch('pushServerSideStorage')
|
||||||
|
|
||||||
if (user.token) {
|
if (user.token) {
|
||||||
store.dispatch('setWsToken', user.token)
|
dispatch('setWsToken', user.token)
|
||||||
|
|
||||||
// Initialize the shout socket.
|
// Initialize the shout socket.
|
||||||
store.dispatch('initializeSocket')
|
dispatch('initializeSocket')
|
||||||
}
|
}
|
||||||
|
|
||||||
const startPolling = () => {
|
const startPolling = () => {
|
||||||
// Start getting fresh posts.
|
// Start getting fresh posts.
|
||||||
store.dispatch('startFetchingTimeline', { timeline: 'friends' })
|
dispatch('startFetchingTimeline', { timeline: 'friends' })
|
||||||
|
|
||||||
// Start fetching notifications
|
// Start fetching notifications
|
||||||
store.dispatch('startFetchingNotifications')
|
dispatch('startFetchingNotifications')
|
||||||
|
|
||||||
// Start fetching chats
|
// Start fetching chats
|
||||||
store.dispatch('startFetchingChats')
|
dispatch('startFetchingChats')
|
||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch('startFetchingLists')
|
dispatch('startFetchingLists')
|
||||||
|
|
||||||
if (user.locked) {
|
if (user.locked) {
|
||||||
store.dispatch('startFetchingFollowRequests')
|
dispatch('startFetchingFollowRequests')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (store.getters.mergedConfig.useStreamingApi) {
|
if (store.getters.mergedConfig.useStreamingApi) {
|
||||||
store.dispatch('fetchTimeline', { timeline: 'friends', since: null })
|
dispatch('fetchTimeline', { timeline: 'friends', since: null })
|
||||||
store.dispatch('fetchNotifications', { since: null })
|
dispatch('fetchNotifications', { since: null })
|
||||||
store.dispatch('enableMastoSockets', true).catch((error) => {
|
dispatch('enableMastoSockets', true).catch((error) => {
|
||||||
console.error('Failed initializing MastoAPI Streaming socket', error)
|
console.error('Failed initializing MastoAPI Streaming socket', error)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
store.dispatch('fetchChats', { latest: true })
|
dispatch('fetchChats', { latest: true })
|
||||||
setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
|
setTimeout(() => dispatch('setNotificationsSilence', false), 10000)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
startPolling()
|
startPolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user mutes
|
// Get user mutes
|
||||||
store.dispatch('fetchMutes')
|
dispatch('fetchMutes')
|
||||||
|
|
||||||
store.dispatch('setLayoutWidth', windowWidth())
|
dispatch('setLayoutWidth', windowWidth())
|
||||||
store.dispatch('setLayoutHeight', windowHeight())
|
dispatch('setLayoutHeight', windowHeight())
|
||||||
|
|
||||||
// Fetch our friends
|
// Fetch our friends
|
||||||
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
|
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
|
||||||
|
@ -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_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}`
|
||||||
const PLEROMA_DELETE_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 oldfetch = window.fetch
|
||||||
|
|
||||||
const fetch = (url, options) => {
|
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 = {
|
const apiService = {
|
||||||
verifyCredentials,
|
verifyCredentials,
|
||||||
fetchTimeline,
|
fetchTimeline,
|
||||||
@ -1772,7 +1790,8 @@ const apiService = {
|
|||||||
postAnnouncement,
|
postAnnouncement,
|
||||||
editAnnouncement,
|
editAnnouncement,
|
||||||
deleteAnnouncement,
|
deleteAnnouncement,
|
||||||
adminFetchAnnouncements
|
adminFetchAnnouncements,
|
||||||
|
fetchInstanceDBConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
export default apiService
|
export default apiService
|
||||||
|
Loading…
Reference in New Issue
Block a user