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