Update:User type admin permissions to create podcasts and download episodes #507

This commit is contained in:
advplyr 2022-04-29 18:29:40 -05:00
parent 4dac8ac16c
commit 729fdd5c9f
3 changed files with 26 additions and 6 deletions

View File

@ -95,14 +95,16 @@
<p class="ml-4">Book has no audio tracks but has valid ebook files. The e-reader is experimental and can be turned on in config.</p> <p class="ml-4">Book has no audio tracks but has valid ebook files. The e-reader is experimental and can be turned on in config.</p>
</div> </div>
<!-- Podcast episode downloads queue -->
<div v-if="episodeDownloadsQueued.length" class="px-4 py-2 mt-4 bg-info bg-opacity-40 text-sm font-semibold rounded-md text-gray-100 relative max-w-max mx-auto md:mx-0"> <div v-if="episodeDownloadsQueued.length" class="px-4 py-2 mt-4 bg-info bg-opacity-40 text-sm font-semibold rounded-md text-gray-100 relative max-w-max mx-auto md:mx-0">
<div class="flex items-center"> <div class="flex items-center">
<p class="text-sm py-1">{{ episodeDownloadsQueued.length }} Episode{{ episodeDownloadsQueued.length === 1 ? '' : 's' }} queued for download</p> <p class="text-sm py-1">{{ episodeDownloadsQueued.length }} Episode{{ episodeDownloadsQueued.length === 1 ? '' : 's' }} queued for download</p>
<span class="material-icons hover:text-error text-xl ml-3 cursor-pointer" @click="clearDownloadQueue">close</span> <span v-if="userIsAdminOrUp" class="material-icons hover:text-error text-xl ml-3 cursor-pointer" @click="clearDownloadQueue">close</span>
</div> </div>
</div> </div>
<!-- Podcast episodes currently downloading -->
<div v-if="episodesDownloading.length" class="px-4 py-2 mt-4 bg-success bg-opacity-20 text-sm font-semibold rounded-md text-gray-100 relative max-w-max mx-auto md:mx-0"> <div v-if="episodesDownloading.length" class="px-4 py-2 mt-4 bg-success bg-opacity-20 text-sm font-semibold rounded-md text-gray-100 relative max-w-max mx-auto md:mx-0">
<div v-for="episode in episodesDownloading" :key="episode.id" class="flex items-center"> <div v-for="episode in episodesDownloading" :key="episode.id" class="flex items-center">
<widgets-loading-spinner /> <widgets-loading-spinner />

View File

@ -9,8 +9,8 @@ const filePerms = require('../utils/filePerms')
class PodcastController { class PodcastController {
async create(req, res) { async create(req, res) {
if (!req.user.isRoot) { if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-root user attempted to create podcast`, req.user) Logger.error(`[PodcastController] Non-admin user attempted to create podcast`, req.user)
return res.sendStatus(500) return res.sendStatus(500)
} }
const payload = req.body const payload = req.body
@ -115,10 +115,19 @@ class PodcastController {
} }
async checkNewEpisodes(req, res) { async checkNewEpisodes(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user attempted to check/download episodes`, req.user)
return res.sendStatus(500)
}
var libraryItem = this.db.getLibraryItem(req.params.id) var libraryItem = this.db.getLibraryItem(req.params.id)
if (!libraryItem || libraryItem.mediaType !== 'podcast') { if (!libraryItem || libraryItem.mediaType !== 'podcast') {
return res.sendStatus(404) return res.sendStatus(404)
} }
if (!req.user.checkCanAccessLibrary(libraryItem.libraryId)) {
Logger.error(`[PodcastController] User attempted to check/download episodes for a library without permission`, req.user)
return res.sendStatus(500)
}
if (!libraryItem.media.metadata.feedUrl) { if (!libraryItem.media.metadata.feedUrl) {
Logger.error(`[PodcastController] checkNewEpisodes no feed url for item ${libraryItem.id}`) Logger.error(`[PodcastController] checkNewEpisodes no feed url for item ${libraryItem.id}`)
return res.status(500).send('Podcast has no rss feed url') return res.status(500).send('Podcast has no rss feed url')
@ -131,8 +140,8 @@ class PodcastController {
} }
clearEpisodeDownloadQueue(req, res) { clearEpisodeDownloadQueue(req, res) {
if (!req.user.canUpdate) { if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] User attempting to clear download queue without permission "${req.user.username}"`) Logger.error(`[PodcastController] Non-admin user attempting to clear download queue "${req.user.username}"`)
return res.sendStatus(500) return res.sendStatus(500)
} }
this.podcastManager.clearDownloadQueue(req.params.id) this.podcastManager.clearDownloadQueue(req.params.id)
@ -151,11 +160,17 @@ class PodcastController {
} }
async downloadEpisodes(req, res) { async downloadEpisodes(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user attempted to download episodes`, req.user)
return res.sendStatus(500)
}
var libraryItem = this.db.getLibraryItem(req.params.id) var libraryItem = this.db.getLibraryItem(req.params.id)
if (!libraryItem || libraryItem.mediaType !== 'podcast') { if (!libraryItem || libraryItem.mediaType !== 'podcast') {
return res.sendStatus(404) return res.sendStatus(404)
} }
if (!req.user.canUpload || !req.user.checkCanAccessLibrary(libraryItem.libraryId)) { if (!req.user.checkCanAccessLibrary(libraryItem.libraryId)) {
Logger.error(`[PodcastController] User attempted to download episodes for library without permission`, req.user)
return res.sendStatus(404) return res.sendStatus(404)
} }

View File

@ -33,6 +33,9 @@ class User {
get isAdmin() { get isAdmin() {
return this.type === 'admin' return this.type === 'admin'
} }
get isAdminOrUp() {
return this.isAdmin || this.isRoot
}
get canDelete() { get canDelete() {
return !!this.permissions.delete && this.isActive return !!this.permissions.delete && this.isActive
} }