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

@ -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