From: David ‘Bombe’ Roden Date: Thu, 5 Oct 2017 19:32:20 +0000 (+0200) Subject: Use a property for “requiresLogin” instead of a method X-Git-Tag: 0.9.7^2~17 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5ebcf8e99818206776539ab6610461dc4386a304;p=Sone.git Use a property for “requiresLogin” instead of a method --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt index f7d3cc7..b185d2b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt @@ -11,7 +11,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class BookmarkAjaxPage(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = request.parameters["post"].emptyToNull diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt index d9a354f..539d57b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt @@ -11,7 +11,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class DismissNotificationAjaxPage(webInterface: WebInterface) : JsonPage("dismissNotification.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest): JsonReturnObject = request.parameters["notification"]!! diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt index 511ed42..809abdc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt @@ -17,6 +17,7 @@ class GetLinkedElementAjaxPage(webInterface: WebInterface, private val elementLo JsonPage("getLinkedElement.ajax", webInterface) { override val needsFormPassword = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest): JsonReturnObject = request.httpRequest.getParam("elements", "[]").asJson() @@ -39,8 +40,6 @@ class GetLinkedElementAjaxPage(webInterface: WebInterface, private val elementLo } } - override fun requiresLogin() = false - private fun String.asJson() = ObjectMapper().readTree(this).asIterable() private fun renderLinkedElement(linkedElement: LinkedElement) = diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt index c3ea74c..19cdd24 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt @@ -17,7 +17,7 @@ import java.io.StringWriter class GetNotificationsAjaxPage(webInterface: WebInterface) : JsonPage("getNotifications.ajax", webInterface) { override val needsFormPassword = false - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = getCurrentSone(request.toadletContext, false).let { currentSone -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt index 925f628..acb8cec 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -50,7 +50,7 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E private fun String.asJson() = ObjectMapper().readTree(this).asIterable() override val needsFormPassword = false - override fun requiresLogin() = false + override val requiresLogin = false private fun SoneOptions.toJsonOptions() = jsonObject { put("ShowNotification/NewSones", isShowNewSoneNotifications) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt index 759cdc0..6930e45 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -23,7 +23,7 @@ class GetTimesAjaxPage(webInterface: WebInterface, } override val needsFormPassword = false - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = createSuccessJsonObject().apply { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt index f12a778..d260655 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt @@ -10,7 +10,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest class GetTranslationAjaxPage(webInterface: WebInterface) : JsonPage("getTranslation.ajax", webInterface) { override val needsFormPassword = false - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = createSuccessJsonObject() diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt index 9ea1d1d..2da5edc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt @@ -25,7 +25,7 @@ abstract class JsonPage(private val path: String, protected val webInterface: We override fun isPrefixPage() = false open val needsFormPassword = true - open fun requiresLogin() = true + open val requiresLogin = true protected fun createSuccessJsonObject() = JsonReturnObject(true) protected fun createErrorJsonObject(error: String) = @@ -41,7 +41,7 @@ abstract class JsonPage(private val path: String, protected val webInterface: We if (needsFormPassword && request.parameters["formPassword"] != webInterface.formPassword) { return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString()) } - if (requiresLogin() && (sessionProvider.getCurrentSone(request.toadletContext, false) == null)) { + if (requiresLogin && (sessionProvider.getCurrentSone(request.toadletContext, false) == null)) { return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString()) } return try { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt index 7b3a9b2..8605fe6 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt @@ -9,7 +9,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class LockSoneAjaxPage(webInterface: WebInterface) : JsonPage("lockSone.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = request.parameters["sone"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt index 5cdee64..388c289 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt @@ -9,7 +9,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ open class LoggedInJsonPage(path: String, webInterface: WebInterface) : JsonPage(path, webInterface) { - final override fun requiresLogin() = true + final override val requiresLogin = true final override fun createJsonObject(request: FreenetRequest) = createJsonObject(getCurrentSone(request.toadletContext)!!, request) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt index 8053591..9e4e4a3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt @@ -12,7 +12,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class MarkAsKnownAjaxPage(webInterface: WebInterface) : JsonPage("markAsKnown.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) { "sone" -> processIds(request, core::getSone, core::markSoneKnown) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt index 11b3bbf..f8331fe 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt @@ -11,7 +11,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class UnbookmarkAjaxPage(webInterface: WebInterface) : JsonPage("unbookmark.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = request.parameters["post"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt index 18129f3..7d77c05 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt @@ -9,7 +9,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class UnlockSoneAjaxPage(webInterface: WebInterface) : JsonPage("unlockSone.ajax", webInterface) { - override fun requiresLogin() = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = request.parameters["sone"] diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index 26fde7d..e5621f0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -34,7 +34,7 @@ abstract class JsonPageTest( @Test fun `page requires login`() { - assertThat(page.requiresLogin(), equalTo(requiresLogin)) + assertThat(page.requiresLogin, equalTo(requiresLogin)) } }