X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FUntrustAjaxPage.java;h=5ba66934600649013b13932fa7beefe4bcc8580c;hp=32c622945c585320124c9861c891bd69d656c5e7;hb=9e697ac643d11a2b7644a948732674eea195718a;hpb=d53a79eeb9531a08173431ce2ba19156eeca4a0c diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java index 32c6229..5ba6693 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - TrustAjaxPage.java - Copyright © 2011 David Roden + * Sone - UntrustAjaxPage.java - Copyright © 2011–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 @@ -17,11 +17,14 @@ package net.pterodactylus.sone.web.ajax; +import javax.annotation.Nonnull; + +import com.google.common.base.Optional; + import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.sone.web.page.FreenetRequest; /** * AJAX page that lets the user untrust a Sone. @@ -29,7 +32,7 @@ import net.pterodactylus.util.json.JsonObject; * @see Core#untrustSone(Sone, Sone) * @author David ‘Bombe’ Roden */ -public class UntrustAjaxPage extends JsonPage { +public class UntrustAjaxPage extends LoggedInJsonPage { /** * Creates a new “untrust Sone” AJAX handler. @@ -44,23 +47,16 @@ public class UntrustAjaxPage extends JsonPage { /** * {@inheritDoc} */ + @Nonnull @Override - protected JsonObject createJsonObject(Request request) { - Sone currentSone = getCurrentSone(request.getToadletContext(), false); - if (currentSone == null) { - return createErrorJsonObject("auth-required"); - } + protected JsonReturnObject createJsonObject(@Nonnull Sone currentSone, @Nonnull FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId, false); - if (sone == null) { + Optional sone = webInterface.getCore().getSone(soneId); + if (!sone.isPresent()) { return createErrorJsonObject("invalid-sone-id"); } - webInterface.getCore().untrustSone(currentSone, sone); - Trust trust = webInterface.getCore().getTrust(currentSone, sone); - if (trust == null) { - return createErrorJsonObject("wot-plugin"); - } - return createSuccessJsonObject().put("trustValue", trust.getExplicit()); + webInterface.getCore().untrustSone(currentSone, sone.get()); + return createSuccessJsonObject().put("trustValue", (String) null); } }