🚧 Add Loaders to all template-using pages
[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 import javax.inject.Inject
8
9 /**
10  * AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone].
11  */
12 class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) :
13                 LoggedInJsonPage("untrustSone.ajax", webInterface) {
14
15         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
16                         request.parameters["sone"]
17                                         ?.let(core::getSone)
18                                         ?.also { core.untrustSone(currentSone, it) }
19                                         ?.let { createSuccessJsonObject() }
20                                         ?: createErrorJsonObject("invalid-sone-id")
21
22 }