1 package net.pterodactylus.sone.web.pages
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
12 * This page lets the user delete a reply.
14 class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface):
15 LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface) {
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")
24 val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
25 if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
26 soneRequest.core.deleteReply(reply)
27 throw RedirectException(returnPage)
29 if (soneRequest.httpRequest.isPartSet("abortDelete")) {
30 throw RedirectException(returnPage)
32 templateContext["reply"] = replyId
33 templateContext["returnPage"] = returnPage
36 templateContext["reply"] = soneRequest.httpRequest.getParam("reply")
37 templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage")