✨ Annotate IndexPage with MenuName
[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.data.Sone
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9 import javax.inject.Inject
10
11 /**
12  * This page lets the user delete a reply.
13  */
14 class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface):
15                 LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface) {
16
17         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
18                 if (soneRequest.isPOST) {
19                         val replyId = soneRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
20                         val reply = soneRequest.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
21                         if (!reply.sone.isLocal) {
22                                 throw RedirectException("noPermission.html")
23                         }
24                         val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
25                         if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
26                                 soneRequest.core.deleteReply(reply)
27                                 throw RedirectException(returnPage)
28                         }
29                         if (soneRequest.httpRequest.isPartSet("abortDelete")) {
30                                 throw RedirectException(returnPage)
31                         }
32                         templateContext["reply"] = replyId
33                         templateContext["returnPage"] = returnPage
34                         return
35                 }
36                 templateContext["reply"] = soneRequest.httpRequest.getParam("reply")
37                 templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage")
38         }
39
40 }