fix(auth): Add admin-level auth to LibraryController delete update and issue removal

This commit is contained in:
alexshch09 2025-02-22 00:44:52 +01:00
parent 0cc2e39367
commit 452d354b52

View File

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