X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FDeleteAlbumPage.java;h=94fbaf1bd0f9ac231208fbba7696bf4672a4174e;hb=00a434a23c9ea1e57c63d8a3c0fc4b09277af431;hp=e175870bca3db6f94d6b333fab8fa7e18ae2c763;hpb=a88e930a23b550dae75116d7759924d760941776;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java index e175870..94fbaf1 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java @@ -1,5 +1,5 @@ /* - * Sone - DeleteAlbumPage.java - Copyright © 2011–2012 David Roden + * Sone - DeleteAlbumPage.java - Copyright © 2011–2013 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 @@ -18,11 +18,14 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.IdBuilder; 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; + /** * Page that lets the user delete an {@link Album}. * @@ -49,27 +52,27 @@ public class DeleteAlbumPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { - String albumId = request.getHttpRequest().getPartAsStringFailsafe("album", 36); - Album album = webInterface.getCore().getAlbum(albumId, false); - if (album == null) { + String albumId = request.getHttpRequest().getPartAsStringFailsafe("album", IdBuilder.ID_STRING_LENGTH); + Optional album = webInterface.getCore().getAlbum(albumId); + if (!album.isPresent()) { throw new RedirectException("invalid.html"); } - if (!album.getSone().isLocal()) { + if (!album.get().getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getHttpRequest().isPartSet("abortDelete")) { - throw new RedirectException("imageBrowser.html?album=" + album.getId()); + throw new RedirectException("imageBrowser.html?album=" + album.get().getId()); } - Album parentAlbum = album.getParent(); - webInterface.getCore().deleteAlbum(album); - if (parentAlbum == null) { - throw new RedirectException("imageBrowser.html?sone=" + album.getSone().getId()); + Album parentAlbum = album.get().getParent(); + webInterface.getCore().deleteAlbum(album.get()); + if (parentAlbum.equals(album.get().getSone().getRootAlbum())) { + throw new RedirectException("imageBrowser.html?sone=" + album.get().getSone().getId()); } throw new RedirectException("imageBrowser.html?album=" + parentAlbum.getId()); } String albumId = request.getHttpRequest().getParam("album"); - Album album = webInterface.getCore().getAlbum(albumId, false); - if (album == null) { + Optional album = webInterface.getCore().getAlbum(albumId); + if (!album.isPresent()) { throw new RedirectException("invalid.html"); } templateContext.set("album", album);