adjusted SSOSettings model and changed all code based on the model

This commit is contained in:
David Leimroth 2022-02-10 14:45:21 +01:00
parent b12a38d12b
commit 3cd09eecba
9 changed files with 251 additions and 103 deletions

View file

@ -9,32 +9,32 @@
<div class="flex items-center py-2">
<p class="pl-4 text-lg">Issuer&nbsp;</p>
<ui-text-input v-model="oidc.issuer" :disabled="updatingSSOSettings" @input="updateSSOIssuer" />
<ui-text-input v-model="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="oidc.authorizationURL" :disabled="updatingSSOSettings" @input="updateAuthorizationURL" />
<ui-text-input v-model="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="oidc.tokenURL" :disabled="updatingSSOSettings" @input="updateTokenURL" />
<ui-text-input v-model="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="oidc.userInfoURL" :disabled="updatingSSOSettings" @input="updateUserInfoURL" />
<ui-text-input v-model="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="oidc.clientID" :disabled="updatingSSOSettings" @input="updateClientID" />
<ui-text-input v-model="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="oidc.clientSecret" :disabled="updatingSSOSettings" @input="updateClientSecret" />
<ui-text-input type="password" v-model="clientSecret" :disabled="updatingSSOSettings" />
</div>
<div class="flex items-center mb-2">
@ -42,32 +42,32 @@
</div>
<div class="flex items-center mb-2">
<ui-toggle-switch v-model="permissions.createNewUser" :disabled="updatingSSOSettings" @input="updatePermissionCreateNewUser" />
<ui-toggle-switch v-model="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="permissions.download" :disabled="updatingSSOSettings || !permissions.createNewUser" @input="updatePermissionDownload" />
<ui-toggle-switch v-model="permissionDownload" :disabled="updatingSSOSettings || !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="permissions.update" :disabled="updatingSSOSettings || !permissions.createNewUser" @input="updatePermissionUpdate" />
<ui-toggle-switch v-model="permissionUpdate" :disabled="updatingSSOSettings || !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="permissions.delete" :disabled="updatingSSOSettings || !permissions.createNewUser" @input="updatePermissionDelete" />
<ui-toggle-switch v-model="permissionDelete" :disabled="updatingSSOSettings || !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="permissions.upload" :disabled="updatingSSOSettings || !permissions.createNewUser" @input="updatePermissionUpload" />
<ui-toggle-switch v-model="permissionUpload" :disabled="updatingSSOSettings || !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="permissions.accessAllLibraries" :disabled="updatingSSOSettings || !permissions.createNewUser" @input="updatePermissionAccessAllLibraries" />
<ui-toggle-switch v-model="permissionAccessAllLibraries" :disabled="updatingSSOSettings || !createNewUser" />
<p class="pl-4 text-lg">The new user is allowed to access all libraries</p>
</div>
@ -90,16 +90,28 @@ export default {
clientID: "",
clientSecret: "",
},
permissions: {
user: {
createNewUser: false,
download: false,
update: false,
delete: false,
upload: false,
accessAllLibraries: 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
}
},
updatingSSOSettings: false,
newSSOSettings: {}
}
@ -114,55 +126,136 @@ export default {
},
computed: {
SSOSettings() {
return this.$store.state.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
},
},
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: {
updateSSOIssuer(val) {
this.oidc.issuer = val
},
updateAuthorizationURL(val) {
this.oidc.authorizationURL = val
},
updateTokenURL(val) {
this.oidc.tokenURL = val
},
updateUserInfoURL(val) {
this.oidc.userInfoURL = val
},
updateClientID(val) {
this.oidc.clientID = val
},
updateClientSecret(val) {
this.oidc.clientSecret = val
},
updatePermissionCreateNewUser(val) {
this.permissions.createNewUser = val
},
updatePermissionDownload(val) {
this.permissions.createNewUser = val
},
updatePermissionUpdate(val) {
this.permissions.createNewUser = val
},
updatePermissionDelete(val) {
this.permissions.createNewUser = val
},
updatePermissionUpload(val) {
this.permissions.createNewUser = val
},
updatePermissionAccessAllLibraries(val) {
this.permissions.createNewUser = val
},
updatePermissionCreateNewUser(val) {
this.permissions.createNewUser = val
},
saveSSOSettings(payload) {
this.updatingSSOSettings = true
this.$store
.dispatch('sso/updateSSOSettings', {oidc: this.oidc, permissions: this.permissions})
.dispatch('sso/updateSSOSettings', {oidc: this.oidc, user: this.user})
.then((success) => {
console.log('Updated SSO Settings', success)
this.updatingSSOSettings = false
})
.catch((error) => {
@ -171,20 +264,21 @@ export default {
})
},
initSSOSettings() {
this.newSSOSettings = this.SSOSettings ? { ...this.SSOSettings } : {}
for (const key in this.$store.state.sso.oidc) {
this.oidc[key] = this.$store.state.sso.oidc[key]
}
this.oidc.issuer = this.newSSOSettings.issuer
this.oidc.authorizationURL = this.newSSOSettings.authorizationURL
this.oidc.tokenURL = this.newSSOSettings.tokenURL
this.oidc.userInfoURL = this.newSSOSettings.userInfoURL
this.oidc.clientID = this.newSSOSettings.clientID
this.oidc.clientSecret = this.newSSOSettings.clientSecret
this.updatingSSOSettings = this.newSSOSettings.updatingSSOSettings
// this.newSSOSettings.coverDestination === this.$constants.CoverDestination.AUDIOBOOK
// this.useSquareBookCovers = this.newSSOSettings.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE
// this.useAlternativeBookshelfView = this.newSSOSettings.bookshelfView === this.$constants.BookshelfView.TITLES
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]
}
continue
}
if (this.user[key] !== undefined) {
this.user[key] = this.$store.state.sso.user[key]
}
}
},
},