/*
- * Sone - DeleteAlbumPage.java - Copyright © 2011 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
package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
+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}.
super("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true);
}
- /**
- * {@inheritDoc}
- */
@Override
- protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ 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) {
+ Optional<Album> album = webInterface.getCore().getAlbum(albumId);
+ if (!album.isPresent()) {
throw new RedirectException("invalid.html");
}
- if (!webInterface.getCore().isLocalSone(album.getSone())) {
+ if (!album.get().getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
- Album parentAlbum = album.getParent();
- webInterface.getCore().deleteAlbum(album);
- if (parentAlbum == null) {
- throw new RedirectException("imageBrowser.html?sone=" + album.getSone().getId());
+ if (request.getHttpRequest().isPartSet("abortDelete")) {
+ throw new RedirectException("imageBrowser.html?album=" + album.get().getId());
+ }
+ Album parentAlbum = album.get().getParent();
+ album.get().remove();
+ 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");
+ Optional<Album> album = webInterface.getCore().getAlbum(albumId);
+ if (!album.isPresent()) {
+ throw new RedirectException("invalid.html");
+ }
+ templateContext.set("album", album);
}
}