8418cd34ee0029016f4bb6f85d8970eb69beff3b
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / UntrustAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.parameters
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7
8 /**
9  * AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone].
10  */
11 class UntrustAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("untrustSone.ajax", webInterface) {
12
13         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
14                         request.parameters["sone"]
15                                         ?.let(core::getSone)
16                                         ?.also { core.untrustSone(currentSone, it) }
17                                         ?.let { createSuccessJsonObject() }
18                                         ?: createErrorJsonObject("invalid-sone-id")
19
20 }