Merge branch 'release-0.9.6'
[Sone.git] / src / main / java / net / pterodactylus / sone / web / DeleteReplyPage.java
index d0a45f1..7112b73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - DeleteReplyPage.java - Copyright © 2010 David Roden
+ * Sone - DeleteReplyPage.java - Copyright © 2010–2016 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 package net.pterodactylus.sone.web;
 
-import net.pterodactylus.sone.data.Reply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+import com.google.common.base.Optional;
 
 /**
  * This page lets the user delete a reply.
@@ -38,7 +41,7 @@ public class DeleteReplyPage extends SoneTemplatePage {
         *            The Sone web interface
         */
        public DeleteReplyPage(Template template, WebInterface webInterface) {
-               super("deleteReply.html", template, "Page.DeleteReply.Title", webInterface);
+               super("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true);
        }
 
        //
@@ -49,37 +52,23 @@ public class DeleteReplyPage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36);
-               Reply reply = webInterface.core().getReply(replyId);
-               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+               Optional<PostReply> reply = webInterface.getCore().getPostReply(replyId);
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                if (request.getMethod() == Method.POST) {
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       if (!reply.getSone().equals(currentSone)) {
+                       if (!reply.isPresent() || !reply.get().getSone().isLocal()) {
                                throw new RedirectException("noPermission.html");
                        }
                        if (request.getHttpRequest().isPartSet("confirmDelete")) {
-                               webInterface.core().deleteReply(reply);
+                               webInterface.getCore().deleteReply(reply.get());
                                throw new RedirectException(returnPage);
                        } else if (request.getHttpRequest().isPartSet("abortDelete")) {
                                throw new RedirectException(returnPage);
                        }
                }
-               template.set("reply", reply);
-               template.set("returnPage", returnPage);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean requiresLogin() {
-               return true;
+               templateContext.set("reply", reply);
+               templateContext.set("returnPage", returnPage);
        }
 
 }