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