From 5ebcf8e99818206776539ab6610461dc4386a304 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 5 Oct 2017 21:32:20 +0200 Subject: [PATCH] =?utf8?q?Use=20a=20property=20for=20=E2=80=9CrequiresLogi?= =?utf8?q?n=E2=80=9D=20instead=20of=20a=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt | 2 +- .../net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt | 2 +- .../net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt | 3 +-- .../net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt | 2 +- .../kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt | 2 +- .../kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt | 2 +- src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt | 2 +- 14 files changed, 15 insertions(+), 16 deletions(-) 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)) } } -- 2.7.4