mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-27 03:31:46 +00:00
Update passport init with saved settings & check if OIDC is configured
This commit is contained in:
parent
adae905953
commit
9e913b5e17
4 changed files with 97 additions and 97 deletions
|
|
@ -1,6 +1,6 @@
|
|||
const { CoverDestination, BookCoverAspectRatio, BookshelfView } = require('../utils/constants')
|
||||
const Logger = require('../Logger')
|
||||
const User = require('./User')
|
||||
const { isObject } = require('../utils')
|
||||
|
||||
const defaultSettings = {
|
||||
oidc: {
|
||||
|
|
@ -13,57 +13,61 @@ const defaultSettings = {
|
|||
callbackURL: "/oidc/callback",
|
||||
scope: "openid email profile"
|
||||
},
|
||||
user: {
|
||||
createNewUser: false,
|
||||
isActive: true,
|
||||
userSettings: {
|
||||
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
|
||||
}
|
||||
}
|
||||
createNewUser: false,
|
||||
userPermissions: User.getDefaultUserPermissions('guest')
|
||||
}
|
||||
|
||||
class SSOSettings {
|
||||
constructor(settings = defaultSettings) {
|
||||
this.id = 'sso-settings'
|
||||
this.oidc = { ...settings.oidc }
|
||||
this.user = { ...settings.user }
|
||||
this.createNewUser = !!settings.createNewUser
|
||||
this.userPermissions = { ...settings.userPermissions }
|
||||
}
|
||||
|
||||
get isOIDCConfigured() {
|
||||
// Check required OIDC settings are set
|
||||
return !['issue', 'authorizationURL', 'tokenURL', 'clientID', 'clientSecret'].some(key => !this.oidc[key])
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
oidc: { ...this.oidc },
|
||||
user: { ...this.user }
|
||||
createNewUser: this.createNewUser,
|
||||
userPermissions: { ...this.userPermissions }
|
||||
}
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
let hasUpdates = false
|
||||
for (const key in payload) {
|
||||
for (const setting in payload) {
|
||||
if (!this[key] || this[key][setting] === payload[key][setting]) {
|
||||
continue
|
||||
if (isObject(payload[key])) {
|
||||
for (const setting in payload[key]) {
|
||||
if (!this[key] || this[key][setting] === payload[key][setting]) {
|
||||
continue
|
||||
}
|
||||
this[key][setting] = payload[key][setting]
|
||||
hasUpdates = true
|
||||
}
|
||||
this[key][setting] = payload[key][setting]
|
||||
} else if (this[key] !== undefined && this[key] !== payload[key]) {
|
||||
this[key] = payload[key]
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
|
||||
getNewUserPermissions() {
|
||||
return {
|
||||
...this.userPermissions
|
||||
}
|
||||
}
|
||||
|
||||
getOIDCSettings() {
|
||||
return {
|
||||
...this.oidc
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = SSOSettings
|
||||
|
|
@ -46,7 +46,7 @@ class User {
|
|||
return !!this.pash && !!this.pash.length
|
||||
}
|
||||
|
||||
getDefaultUserSettings() {
|
||||
static getDefaultUserSettings() {
|
||||
return {
|
||||
mobileOrderBy: 'recent',
|
||||
mobileOrderDesc: true,
|
||||
|
|
@ -60,12 +60,12 @@ class User {
|
|||
}
|
||||
}
|
||||
|
||||
getDefaultUserPermissions() {
|
||||
static getDefaultUserPermissions(type) {
|
||||
return {
|
||||
download: true,
|
||||
update: true,
|
||||
delete: this.type === 'root',
|
||||
upload: this.type === 'root' || this.type === 'admin',
|
||||
download: type !== 'guest',
|
||||
update: type !== 'guest',
|
||||
delete: type === 'root',
|
||||
upload: type === 'root' || type === 'admin',
|
||||
accessAllLibraries: true
|
||||
}
|
||||
}
|
||||
|
|
@ -152,8 +152,8 @@ class User {
|
|||
this.isLocked = user.type === 'root' ? false : !!user.isLocked
|
||||
this.lastSeen = user.lastSeen || null
|
||||
this.createdAt = user.createdAt || Date.now()
|
||||
this.settings = user.settings || this.getDefaultUserSettings()
|
||||
this.permissions = user.permissions || this.getDefaultUserPermissions()
|
||||
this.settings = user.settings || User.getDefaultUserSettings()
|
||||
this.permissions = user.permissions || User.getDefaultUserPermissions(this.type)
|
||||
// Upload permission added v1.1.13, make sure root user has upload permissions
|
||||
if (this.type === 'root' && !this.permissions.upload) this.permissions.upload = true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue