Move server settings and SSO settings to settings.js module & cleanup sso.vue

This commit is contained in:
advplyr 2022-02-10 18:24:20 -06:00
parent 5060e0b728
commit c34a518754
21 changed files with 132 additions and 283 deletions

View file

@ -3,7 +3,6 @@ import Vue from 'vue'
export const state = () => ({
versionData: null,
serverSettings: null,
streamAudiobook: null,
editModalTab: 'details',
showEditModal: false,
@ -28,14 +27,6 @@ export const getters = {
getIsAudiobookSelected: state => audiobookId => {
return !!state.selectedAudiobooks.includes(audiobookId)
},
getServerSetting: state => key => {
if (!state.serverSettings) return null
return state.serverSettings[key]
},
getBookCoverAspectRatio: state => {
if (!state.serverSettings || !state.serverSettings.coverAspectRatio) return 1.6
return state.serverSettings.coverAspectRatio === 0 ? 1.6 : 1
},
getNumAudiobooksSelected: state => state.selectedAudiobooks.length,
getAudiobookIdStreaming: state => {
return state.streamAudiobook ? state.streamAudiobook.id : null
@ -43,22 +34,6 @@ export const getters = {
}
export const actions = {
updateServerSettings({ commit }, payload) {
var updatePayload = {
...payload
}
return this.$axios.$patch('/api/serverSettings', updatePayload).then((result) => {
if (result.success) {
commit('setServerSettings', result.serverSettings)
return true
} else {
return false
}
}).catch((error) => {
console.error('Failed to update server settings', error)
return false
})
},
checkForUpdate({ commit }) {
return checkForUpdate()
.then((res) => {
@ -102,10 +77,6 @@ export const mutations = {
setVersionData(state, versionData) {
state.versionData = versionData
},
setServerSettings(state, settings) {
if (!settings) return
state.serverSettings = settings
},
setStreamAudiobook(state, audiobook) {
state.playOnLoad = true
state.streamAudiobook = audiobook

63
client/store/settings.js Normal file
View file

@ -0,0 +1,63 @@
export const state = () => ({
SSOSettings: null,
serverSettings: null
})
export const getters = {
getServerSetting: state => key => {
if (!state.serverSettings) return null
return state.serverSettings[key]
},
getBookCoverAspectRatio: state => {
if (!state.serverSettings || !state.serverSettings.coverAspectRatio) return 1.6
return state.serverSettings.coverAspectRatio === 0 ? 1.6 : 1
}
}
export const actions = {
updateServerSettings({ commit }, payload) {
var updatePayload = {
...payload
}
return this.$axios.$patch('/api/serverSettings', updatePayload).then((result) => {
if (result.success) {
commit('setServerSettings', result.serverSettings)
return true
} else {
return false
}
}).catch((error) => {
console.error('Failed to update server settings', error)
return false
})
},
updateSSOSettings({ commit }, payload) {
var updatePayload = {
...payload
}
// Immediately update
commit('setSSOSettings', updatePayload)
return this.$axios.$patch('/api/SSOSettings', updatePayload).then((result) => {
if (result.success) {
commit('setSSOSettings', result.settings)
return true
} else {
return false
}
}).catch((error) => {
console.error('Failed to update sso settings', error)
return false
})
}
}
export const mutations = {
setServerSettings(state, settings) {
if (!settings) return
state.serverSettings = settings
},
setSSOSettings(state, settings) {
if (!settings || !settings.oidc || !settings.user) return
state.SSOSettings = settings
}
}

View file

@ -1,108 +0,0 @@
const defaultSSOSettings = {
oidc: {
issuer: "",
authorizationURL: "",
tokenURL: "",
userInfoURL: "",
clientID: "",
clientSecret: "",
callbackURL: "/oidc/callback",
scope: "openid email profile"
},
user: {
createNewUser: false,
isActive: true,
settings: {
mobileOrderBy: 'recent',
mobileOrderDesc: true,
mobileFilterBy: 'all',
orderBy: 'book.title',
orderDesc: false,
filterBy: 'all',
playbackRate: 1,
bookshelfCoverSize: 120,
collapseSeries: false
},
permissions: {
download: false,
update: false,
delete: false,
upload: false,
accessAllLibraries: false
}
}
}
export const state = () => defaultSSOSettings
export const getters = {
getSSOIssuer: (state) => state.oidc.issuer,
getSSOAuthorizationURL: (state) => state.oidc.authorizationURL,
getSSOTokenURL: (state) => state.oidc.tokenURL,
getSSOUserInfoURL: (state) => state.oidc.userInfoURL,
getSSOClientID: (state) => state.oidc.clientID,
getSSOClientSecret: (state) => state.oidc.clientSecret,
getSSOCallbackURL: (state) => state.oidc.callbackURL,
getSSOScope: (state) => state.oidc.scope,
getUserCreateNewUser: (state) => state.user.createNewUser,
getUserIsActive: (state) => state.user.isActive,
getUserPermissionDownload: (state) => state.user.permissions.download,
getUserPermissionUpdate: (state) => state.user.permissions.update,
getUserPermissionDelete: (state) => state.user.permissions.delete,
getUserPermissionUpload: (state) => state.user.permissions.upload,
getUserPermissionAccessAllLibraries: (state) => state.user.permissions.accessAllLibraries,
}
export const actions = {
updateSSOSettings({ commit }, payload) {
var updatePayload = {
...payload
}
// Immediately update
commit('setSSOSettings', updatePayload)
return this.$axios.$patch('/api/SSOSettings', updatePayload).then((result) => {
if (result.success) {
commit('setSSOSettings', result.settings)
return true
} else {
return false
}
}).catch((error) => {
console.error('Failed to update sso settings', error)
return false
})
},
loadSSOSettings({ state, commit }) {
return this.$axios.$get('/api/collections').then((collections) => {
commit('setCollections', collections)
return collections
}).catch((error) => {
console.error('Failed to get collections', error)
return []
})
}
}
export const mutations = {
setSSOSettings(state, settings) {
if (!settings || !settings.oidc || !settings.user) return
for (const key in settings.oidc) {
state.oidc[key] = settings.oidc[key]
}
for (const key in settings.user) {
if (typeof settings.user[key] === "object" && typeof state.user[key] === "object") {
for (const key2 in settings.user[key]) {
state.user[key][key2] = settings.user[key][key2]
}
continue
}
if (state.user[key] !== undefined) {
state.user[key] = settings.user[key]
}
}
},
}