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

@ -56,7 +56,7 @@ export default {
return coverSize
},
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
isCoverSquareAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE

View File

@ -109,10 +109,10 @@ export default {
return this.$store.getters['user/getUserSetting']('collapseSeries')
},
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookshelfView() {
return this.$store.getters['getServerSetting']('bookshelfView')
return this.$store.getters['settings/getServerSetting']('bookshelfView')
},
isCoverSquareAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE

View File

@ -46,7 +46,7 @@ export default {
},
computed: {
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

View File

@ -31,7 +31,7 @@ export default {
},
computed: {
bookCoverAspectRatio() {
return this.$store.getters['getBookCoverAspectRatio']
return this.$store.getters['settings/getBookCoverAspectRatio']
},
coverWidth() {
if (this.bookCoverAspectRatio === 1) return 50 * 1.2

View File

@ -21,7 +21,7 @@ export default {
},
computed: {
bookCoverAspectRatio() {
return this.$store.getters['getBookCoverAspectRatio']
return this.$store.getters['settings/getBookCoverAspectRatio']
}
},
methods: {},

View File

@ -75,7 +75,7 @@ export default {
}
},
bookCoverAspectRatio() {
return this.$store.getters['getBookCoverAspectRatio']
return this.$store.getters['settings/getBookCoverAspectRatio']
},
collection() {
return this.$store.state.globals.selectedCollection || {}

View File

@ -149,7 +149,7 @@ export default {
}
},
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

View File

@ -143,7 +143,7 @@ export default {
}
},
bookCoverAspectRatio() {
return this.$store.getters['getBookCoverAspectRatio']
return this.$store.getters['settings/getBookCoverAspectRatio']
},
providers() {
return this.$store.state.scanners.providers

View File

@ -52,7 +52,7 @@ export default {
},
computed: {
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

View File

@ -110,10 +110,10 @@ export default {
this.$store.commit('user/setSettings', payload.user.settings)
}
if (payload.serverSettings) {
this.$store.commit('setServerSettings', payload.serverSettings)
this.$store.commit('settings/setServerSettings', payload.serverSettings)
}
if (payload.SSOSettings) {
this.$store.commit('sso/setSSOSettings', payload.SSOSettings)
this.$store.commit('settings/setSSOSettings', payload.SSOSettings)
}
// Start scans currently running

View File

@ -190,7 +190,7 @@ export default {
},
computed: {
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

View File

@ -147,7 +147,7 @@ export default {
},
computed: {
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

View File

@ -67,7 +67,7 @@ export default {
},
computed: {
bookCoverAspectRatio() {
return this.$store.getters['getBookCoverAspectRatio']
return this.$store.getters['settings/getBookCoverAspectRatio']
},
streamAudiobook() {
return this.$store.state.streamAudiobook

View File

@ -48,7 +48,7 @@ export default {
return 'Runs at 1am every day (your server time). Saved in /metadata/backups.'
},
serverSettings() {
return this.$store.state.serverSettings
return this.$store.state.settings.serverSettings
}
},
methods: {
@ -66,7 +66,7 @@ export default {
updateServerSettings(payload) {
this.updatingServerSettings = true
this.$store
.dispatch('updateServerSettings', payload)
.dispatch('settings/updateServerSettings', payload)
.then((success) => {
console.log('Updated Server Settings', success)
this.updatingServerSettings = false

View File

@ -123,6 +123,9 @@ export default {
}
},
computed: {
serverSettings() {
return this.$store.state.settings.serverSettings
},
scannerPreferAudioMetaTooltip() {
return 'Audio file ID3 meta tags will be used for book details over folder names'
},
@ -135,9 +138,6 @@ export default {
experimentalFeaturesTooltip() {
return 'Features in development that could use your feedback and help testing.'
},
serverSettings() {
return this.$store.state.serverSettings
},
parseSubtitleTooltip() {
return 'Extract subtitles from audiobook directory names.<br>Subtitle must be seperated by " - "<br>i.e. "Book Title - A Subtitle Here" has the subtitle "A Subtitle Here"'
},
@ -210,7 +210,7 @@ export default {
updateServerSettings(payload) {
this.updatingServerSettings = true
this.$store
.dispatch('updateServerSettings', payload)
.dispatch('settings/updateServerSettings', payload)
.then((success) => {
console.log('Updated Server Settings', success)
this.updatingServerSettings = false

View File

@ -91,7 +91,7 @@ export default {
})
},
serverSettings() {
return this.$store.state.serverSettings
return this.$store.state.settings.serverSettings
},
streamAudiobook() {
return this.$store.state.streamAudiobook
@ -124,7 +124,7 @@ export default {
},
updateServerSettings(payload) {
this.$store
.dispatch('updateServerSettings', payload)
.dispatch('settings/updateServerSettings', payload)
.then((success) => {
console.log('Updated Server Settings', success)
})

View File

@ -1,7 +1,5 @@
<template>
<div>
<!-- <div class="h-0.5 bg-primary bg-opacity-50 w-full" /> -->
<div class="bg-bg rounded-md shadow-lg border border-white border-opacity-5 p-4 mb-8">
<div class="flex items-center mb-2">
<h1 class="text-xl">SSO Provider Settings</h1>
@ -9,32 +7,32 @@
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Issuer&nbsp;</p>
<ui-text-input v-model="issuer" :disabled="updatingSSOSettings" />
<ui-text-input v-model="oidc.issuer" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Authorization URL&nbsp;</p>
<ui-text-input v-model="authorizationURL" :disabled="updatingSSOSettings" />
<ui-text-input v-model="oidc.authorizationURL" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Token URL&nbsp;</p>
<ui-text-input v-model="tokenURL" :disabled="updatingSSOSettings" />
<ui-text-input v-model="oidc.tokenURL" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center py-2">
<p class="pl-4 text-lg">User Info URL&nbsp;</p>
<ui-text-input v-model="userInfoURL" :disabled="updatingSSOSettings" />
<ui-text-input v-model="oidc.userInfoURL" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Client ID&nbsp;</p>
<ui-text-input v-model="clientID" :disabled="updatingSSOSettings" />
<ui-text-input v-model="oidc.clientID" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Client Secret&nbsp;</p>
<ui-text-input type="password" v-model="clientSecret" :disabled="updatingSSOSettings" />
<ui-text-input type="password" v-model="oidc.clientSecret" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center mb-2">
@ -42,32 +40,32 @@
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="createNewUser" :disabled="updatingSSOSettings" />
<ui-toggle-switch v-model="user.createNewUser" :disabled="updatingSSOSettings" />
<p class="pl-4 text-lg">Create a new user on first login</p>
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissionDownload" :disabled="updatingSSOSettings || !createNewUser" />
<ui-toggle-switch v-model="permissionDownload" :disabled="updatingSSOSettings || !user.createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to download</p>
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissionUpdate" :disabled="updatingSSOSettings || !createNewUser" />
<ui-toggle-switch v-model="permissionUpdate" :disabled="updatingSSOSettings || !user.createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to update</p>
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissionDelete" :disabled="updatingSSOSettings || !createNewUser" />
<ui-toggle-switch v-model="permissionDelete" :disabled="updatingSSOSettings || !user.createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to delete</p>
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissionUpload" :disabled="updatingSSOSettings || !createNewUser" />
<ui-toggle-switch v-model="permissionUpload" :disabled="updatingSSOSettings || !user.createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to upload</p>
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissionAccessAllLibraries" :disabled="updatingSSOSettings || !createNewUser" />
<ui-toggle-switch v-model="permissionAccessAllLibraries" :disabled="updatingSSOSettings || !user.createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to access all libraries</p>
</div>
@ -83,12 +81,12 @@ export default {
data() {
return {
oidc: {
issuer: "",
authorizationURL: "",
tokenURL: "",
userInfoURL: "",
clientID: "",
clientSecret: "",
issuer: '',
authorizationURL: '',
tokenURL: '',
userInfoURL: '',
clientID: '',
clientSecret: ''
},
user: {
createNewUser: false,
@ -112,178 +110,103 @@ export default {
accessAllLibraries: false
}
},
updatingSSOSettings: false,
newSSOSettings: {}
updatingSSOSettings: false
}
},
watch: {
SSOSettings(newVal, oldVal) {
console.log('SSO Settings set', newVal, oldVal)
if (newVal && !oldVal) {
this.newSSOSettings = { ...this.SSOSettings }
this.initSSOSettings()
}
}
},
computed: {
SSOSettings() {
return this.$store.state.sso
},
issuer: {
get() {
return this.oidc.issuer
return this.$store.state.sso.oidc.issuer
},
set(val) {
this.oidc.issuer = val
// this.$store.state.sso.oidc.issuer = val
}
},
authorizationURL: {
get() {
return this.oidc.authorizationURL
return this.$store.state.sso.oidc.authorizationURL
},
set(val) {
this.oidc.authorizationURL = val
// this.$store.state.sso.oidc.authorizationURL = val
}
},
tokenURL: {
get() {
return this.oidc.tokenURL
return this.$store.state.sso.oidc.tokenURL
},
set(val) {
this.oidc.tokenURL = val
// this.$store.state.sso.oidc.tokenURL = val
}
},
userInfoURL: {
get() {
return this.oidc.userInfoURL
return this.$store.state.sso.oidc.userInfoURL
},
set(val) {
this.oidc.userInfoURL = val
// this.$store.state.sso.oidc.userInfoURL = val
},
},
clientID: {
get() {
return this.oidc.clientID
return this.$store.state.sso.oidc.clientID
},
set(val) {
this.oidc.clientID = val
// this.$store.state.sso.oidc.clientID = val
},
},
clientSecret: {
get() {
return this.oidc.clientSecret
return this.$store.state.sso.oidc.clientSecret
},
set(val) {
this.oidc.clientSecret = val
// this.$store.state.sso.oidc.clientSecret = val
},
},
createNewUser: {
get() {
return this.user.createNewUser
return this.$store.state.sso.createNewUser
},
set(val) {
this.user.createNewUser = val
// this.$store.state.sso.createNewUser = val
},
return this.$store.state.settings.SSOSettings
},
permissionDownload: {
get() {
return this.user.permissions.download
return this.$store.state.sso.permissions.download
},
set(val) {
this.user.permissions.download = val
// this.$store.state.sso.permissions.download = val
},
}
},
permissionUpdate: {
get() {
return this.user.permissions.update
return this.$store.state.sso.permissions.update
},
set(val) {
this.user.permissions.update = val
// this.$store.state.sso.permissions.update = val
},
}
},
permissionDelete: {
get() {
return this.user.permissions.delete
return this.$store.state.sso.permissions.delete
},
set(val) {
this.user.permissions.delete = val
// this.$store.state.sso.permissions.delete = val
},
}
},
permissionUpload: {
get() {
return this.user.permissions.upload
return this.$store.state.sso.permissions.upload
},
set(val) {
this.user.permissions.upload = val
// this.$store.state.sso.permissions.upload = val
}
},
permissionAccessAllLibraries: {
get() {
return this.user.permissions.accessAllLibraries
return this.$store.state.sso.permissions.accessAllLibraries
},
set(val) {
this.user.permissions.accessAllLibraries = val
// this.$store.state.sso.permissions.accessAllLibraries = val
}
},
}
},
methods: {
saveSSOSettings(payload) {
saveSSOSettings() {
this.updatingSSOSettings = true
this.$store
.dispatch('sso/updateSSOSettings', {oidc: this.oidc, user: this.user})
.then((success) => {
.dispatch('settings/updateSSOSettings', { oidc: this.oidc, user: this.user })
.then((payload) => {
console.log('Update SSO settings success', payload)
this.updatingSSOSettings = false
this.$toast.success('SSO Settings Saved')
})
.catch((error) => {
console.error('Failed to update SSO settings', error)
this.updatingSSOSettings = false
this.$toast.error('Failed to save SSO Settings')
})
},
initSSOSettings() {
for (const key in this.$store.state.sso.oidc) {
this.oidc[key] = this.$store.state.sso.oidc[key]
if (!this.SSOSettings || !this.SSOSettings.user || !this.SSOSettings.oidc) {
console.error('Invalid SSOSettings obj', this.SSOSettings)
return
}
for (const key in this.$store.state.sso.user) {
if (typeof this.$store.state.sso.user[key] === "object" && typeof this.user[key] === "object") {
for (const key2 in this.$store.state.sso.user[key]) {
this.user[key][key2] = this.$store.state.sso.user[key][key2]
for (const key in this.SSOSettings.oidc) {
this.oidc[key] = this.SSOSettings.oidc[key]
}
for (const key in this.SSOSettings.user) {
if (typeof this.SSOSettings.user[key] === 'object' && typeof this.user[key] === 'object') {
for (const key2 in this.SSOSettings.user[key]) {
this.user[key][key2] = this.SSOSettings.user[key][key2]
}
continue
}
if (this.user[key] !== undefined) {
this.user[key] = this.$store.state.sso.user[key]
this.user[key] = this.SSOSettings.user[key]
}
}
},
}
},
mounted() {
this.initSSOSettings()
if (this.SSOSettings) this.initSSOSettings()
}
}
</script>

View File

@ -88,7 +88,7 @@ export default {
},
computed: {
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
return this.$store.getters['settings/getServerSetting']('coverAspectRatio')
},
bookCoverAspectRatio() {
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6

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]
}
}
},
}