Add:User permission restrict explicit content #637

This commit is contained in:
advplyr 2022-05-28 16:53:03 -05:00
parent 6be741045f
commit 160dac109d
5 changed files with 19 additions and 16 deletions

View File

@ -65,6 +65,15 @@
</div> </div>
</div> </div>
<div class="flex items-center my-2 max-w-md">
<div class="w-1/2">
<p>Can Access Explicit Content</p>
</div>
<div class="w-1/2">
<ui-toggle-switch v-model="newUser.permissions.accessExplicitContent" />
</div>
</div>
<div class="flex items-center my-2 max-w-md"> <div class="flex items-center my-2 max-w-md">
<div class="w-1/2"> <div class="w-1/2">
<p>Can Access All Libraries</p> <p>Can Access All Libraries</p>

View File

@ -104,7 +104,6 @@ class Auth {
async login(req, res) { async login(req, res) {
var username = (req.body.username || '').toLowerCase() var username = (req.body.username || '').toLowerCase()
var password = req.body.password || '' var password = req.body.password || ''
Logger.debug('Check Auth', username, !!password)
var user = this.users.find(u => u.username.toLowerCase() === username) var user = this.users.find(u => u.username.toLowerCase() === username)

View File

@ -485,8 +485,7 @@ class LibraryController {
} }
middleware(req, res, next) { middleware(req, res, next) {
var librariesAccessible = req.user.librariesAccessible || [] if (!req.user.checkCanAccessLibrary(req.params.id)) {
if (librariesAccessible && librariesAccessible.length && !librariesAccessible.includes(req.params.id)) {
Logger.warn(`[LibraryController] Library ${req.params.id} not accessible to user ${req.user.username}`) Logger.warn(`[LibraryController] Library ${req.params.id} not accessible to user ${req.user.username}`)
return res.sendStatus(404) return res.sendStatus(404)
} }
@ -497,7 +496,7 @@ class LibraryController {
} }
req.library = library req.library = library
req.libraryItems = this.db.libraryItems.filter(li => { req.libraryItems = this.db.libraryItems.filter(li => {
return li.libraryId === library.id && req.user.checkCanAccessLibraryItemWithTags(li.media.tags) return li.libraryId === library.id && req.user.checkCanAccessLibraryItem(li)
}) })
next() next()
} }

View File

@ -225,13 +225,8 @@ class PodcastController {
return res.sendStatus(500) return res.sendStatus(500)
} }
// Check user can access this library
if (!req.user.checkCanAccessLibrary(item.libraryId)) {
return res.sendStatus(403)
}
// Check user can access this library item // Check user can access this library item
if (!req.user.checkCanAccessLibraryItemWithTags(item.media.tags)) { if (!req.user.checkCanAccessLibraryItem(item)) {
return res.sendStatus(403) return res.sendStatus(403)
} }

View File

@ -51,11 +51,8 @@ class User {
get canUpload() { get canUpload() {
return !!this.permissions.upload && this.isActive return !!this.permissions.upload && this.isActive
} }
get canAccessAllLibraries() { get canAccessExplicitContent() {
return !!this.permissions.accessAllLibraries && this.isActive return !!this.permissions.accessExplicitContent && this.isActive
}
get canAccessAllTags() {
return !!this.permissions.accessAllTags && this.isActive
} }
get hasPw() { get hasPw() {
return !!this.pash && !!this.pash.length return !!this.pash && !!this.pash.length
@ -82,7 +79,8 @@ class User {
delete: this.type === 'root', delete: this.type === 'root',
upload: this.type === 'root' || this.type === 'admin', upload: this.type === 'root' || this.type === 'admin',
accessAllLibraries: true, accessAllLibraries: true,
accessAllTags: true accessAllTags: true,
accessExplicitContent: true
} }
} }
@ -176,6 +174,8 @@ class User {
if (this.permissions.accessAllLibraries === undefined) this.permissions.accessAllLibraries = true if (this.permissions.accessAllLibraries === undefined) this.permissions.accessAllLibraries = true
// Library restriction permissions added v2.0, defaults to all libraries // Library restriction permissions added v2.0, defaults to all libraries
if (this.permissions.accessAllTags === undefined) this.permissions.accessAllTags = true if (this.permissions.accessAllTags === undefined) this.permissions.accessAllTags = true
// Explicit content restriction permission added v2.0.18
if (this.permissions.accessExplicitContent === undefined) this.permissions.accessExplicitContent = true
this.librariesAccessible = [...(user.librariesAccessible || [])] this.librariesAccessible = [...(user.librariesAccessible || [])]
this.itemTagsAccessible = [...(user.itemTagsAccessible || [])] this.itemTagsAccessible = [...(user.itemTagsAccessible || [])]
@ -343,6 +343,7 @@ class User {
checkCanAccessLibraryItem(libraryItem) { checkCanAccessLibraryItem(libraryItem) {
if (!this.checkCanAccessLibrary(libraryItem.libraryId)) return false if (!this.checkCanAccessLibrary(libraryItem.libraryId)) return false
if (libraryItem.media.metadata.explicit && !this.canAccessExplicitContent) return false
return this.checkCanAccessLibraryItemWithTags(libraryItem.media.tags) return this.checkCanAccessLibraryItemWithTags(libraryItem.media.tags)
} }