Merge branch 'release-0.9.7'
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteAlbumPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user delete an {@link Album}.
11  */
12 class DeleteAlbumPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) {
14
15         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
16                 if (freenetRequest.isPOST) {
17                         val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
18                         if (!album.sone.isLocal) {
19                                 throw RedirectException("noPermission.html")
20                         }
21                         if (freenetRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
22                                 throw RedirectException("imageBrowser.html?album=${album.id}")
23                         }
24                         webInterface.core.deleteAlbum(album)
25                         throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
26                 }
27                 val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getParam("album"))
28                 templateContext["album"] = album ?: throw RedirectException("invalid.html")
29         }
30
31 }