mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-24 00:21:12 +01:00
Merge pull request #4027 from Alexshch09/Add-admin-auth-to-LibraryController
fix(auth): Add admin-level auth to LibraryController 'delete', 'update' and 'delete items with issues'
This commit is contained in:
commit
e1b3b657c4
@ -254,6 +254,11 @@ class LibraryController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
*/
|
*/
|
||||||
async update(req, res) {
|
async update(req, res) {
|
||||||
|
if (!req.user.isAdminOrUp) {
|
||||||
|
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to update library`)
|
||||||
|
return res.sendStatus(403)
|
||||||
|
}
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
const updatePayload = {}
|
const updatePayload = {}
|
||||||
const keysToCheck = ['name', 'provider', 'mediaType', 'icon']
|
const keysToCheck = ['name', 'provider', 'mediaType', 'icon']
|
||||||
@ -519,6 +524,11 @@ class LibraryController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
*/
|
*/
|
||||||
async delete(req, res) {
|
async delete(req, res) {
|
||||||
|
if (!req.user.isAdminOrUp) {
|
||||||
|
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to delete library`)
|
||||||
|
return res.sendStatus(403)
|
||||||
|
}
|
||||||
|
|
||||||
// Remove library watcher
|
// Remove library watcher
|
||||||
Watcher.removeLibrary(req.library)
|
Watcher.removeLibrary(req.library)
|
||||||
|
|
||||||
@ -639,6 +649,11 @@ class LibraryController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
*/
|
*/
|
||||||
async removeLibraryItemsWithIssues(req, res) {
|
async removeLibraryItemsWithIssues(req, res) {
|
||||||
|
if (!req.user.isAdminOrUp) {
|
||||||
|
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to delete library items missing or invalid`)
|
||||||
|
return res.sendStatus(403)
|
||||||
|
}
|
||||||
|
|
||||||
const libraryItemsWithIssues = await Database.libraryItemModel.findAll({
|
const libraryItemsWithIssues = await Database.libraryItemModel.findAll({
|
||||||
where: {
|
where: {
|
||||||
libraryId: req.library.id,
|
libraryId: req.library.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user