X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FEditAlbumPage.kt;h=4e0cf5f70272a10a65c73af47af6f8e1d3d092df;hp=bd612c3b9e65e52550f5c5c6fc93db6f8c1c064d;hb=cd72add62ab407336b471d4b7cda8e33dd2df5c6;hpb=ffd92ca2374c0b2218e583d02e0bdd24b8c110ae diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt index bd612c3..4e0cf5f 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt @@ -1,40 +1,42 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty +import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext +import javax.inject.Inject /** * Page that lets the user edit the name and description of an album. */ -class EditAlbumPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) { +class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface): + LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface) { - override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { - if (freenetRequest.isPOST) { - val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") + override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { + if (soneRequest.isPOST) { + val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") } - if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { + if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { album.parent?.moveAlbumUp(album) - webInterface.core.touchConfiguration() + soneRequest.core.touchConfiguration() throw RedirectException("imageBrowser.html?album=${album.parent?.id}") - } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") { + } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") { album.parent?.moveAlbumDown(album) - webInterface.core.touchConfiguration() + soneRequest.core.touchConfiguration() throw RedirectException("imageBrowser.html?album=${album.parent?.id}") } else { try { album.modify() - .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100)) - .setDescription(freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1000)) + .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100)) + .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000)) .update() } catch (e: AlbumTitleMustNotBeEmpty) { throw RedirectException("emptyAlbumTitle.html") } - webInterface.core.touchConfiguration() + soneRequest.core.touchConfiguration() throw RedirectException("imageBrowser.html?album=${album.id}") } }