Declare returned Core to always be non-null
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeletePostPage.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  * Lets the user delete a post they made.
11  */
12 class DeletePostPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 if (request.isPOST) {
17                         val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html")
18                         val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
19                         if (!post.sone.isLocal) {
20                                 throw RedirectException("noPermission.html")
21                         }
22                         if (request.httpRequest.isPartSet("confirmDelete")) {
23                                 webInterface.core.deletePost(post)
24                                 throw RedirectException(returnPage)
25                         } else if (request.httpRequest.isPartSet("abortDelete")) {
26                                 throw RedirectException(returnPage)
27                         }
28                         templateContext["post"] = post
29                         templateContext["returnPage"] = returnPage
30                         return
31                 }
32                 templateContext["post"] = webInterface.core.getPost(request.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html")
33                 templateContext["returnPage"] = request.httpRequest.getParam("returnPage")
34         }
35
36 }