Update to Kotlin 1.2.0
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteReplyPage.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  * This page lets the user delete a reply.
11  */
12 class DeleteReplyPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
14
15         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
16                 if (freenetRequest.isPOST) {
17                         val replyId = freenetRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
18                         val reply = webInterface.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
19                         if (!reply.sone.isLocal) {
20                                 throw RedirectException("noPermission.html")
21                         }
22                         val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
23                         if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
24                                 webInterface.core.deleteReply(reply)
25                                 throw RedirectException(returnPage)
26                         }
27                         if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
28                                 throw RedirectException(returnPage)
29                         }
30                         templateContext["reply"] = replyId
31                         templateContext["returnPage"] = returnPage
32                         return
33                 }
34                 templateContext["reply"] = freenetRequest.httpRequest.getParam("reply")
35                 templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")
36         }
37
38 }