🔥 Remove session access from freenet request
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / EditAlbumPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.data.Album.Modifier.*
5 import net.pterodactylus.sone.main.*
6 import net.pterodactylus.sone.utils.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.*
10 import javax.inject.*
11
12 /**
13  * Page that lets the user edit the name and description of an album.
14  */
15 @ToadletPath("editAlbum.html")
16 class EditAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17                 LoggedInPage("Page.EditAlbum.Title", webInterface, loaders, templateRenderer) {
18
19         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20                 if (soneRequest.isPOST) {
21                         val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html")
22                         album.takeUnless { it.sone.isLocal }?.run { redirectTo("noPermission.html") }
23                         if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
24                                 album.parent?.moveAlbumUp(album)
25                                 soneRequest.core.touchConfiguration()
26                                 redirectTo("imageBrowser.html?album=${album.parent?.id}")
27                         } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
28                                 album.parent?.moveAlbumDown(album)
29                                 soneRequest.core.touchConfiguration()
30                                 redirectTo("imageBrowser.html?album=${album.parent?.id}")
31                         } else {
32                                 try {
33                                         album.modify()
34                                                         .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
35                                                         .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
36                                                         .update()
37                                 } catch (e: AlbumTitleMustNotBeEmpty) {
38                                         redirectTo("emptyAlbumTitle.html")
39                                 }
40                                 soneRequest.core.touchConfiguration()
41                                 redirectTo("imageBrowser.html?album=${album.id}")
42                         }
43                 }
44         }
45
46 }