From 4bf90851f9e7a8f31d4f58f4f74dc46d8e4ddec8 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:27:30 +0200 Subject: [PATCH] =?utf8?q?Use=20a=20property=20for=20=E2=80=9CneedsFormPas?= =?utf8?q?sword=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/GetLikesAjaxPage.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/GetPostAjaxPage.kt | 2 +- src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.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/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt | 2 +- src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt | 2 +- 11 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt index 12e8309..335f269 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt @@ -15,7 +15,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class GetLikesAjaxPage(webInterface: WebInterface) : JsonPage("getLikes.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) { 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 285c479..511ed42 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt @@ -16,6 +16,8 @@ import net.pterodactylus.sone.web.page.FreenetRequest class GetLinkedElementAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val linkedElementRenderFilter: LinkedElementRenderFilter): JsonPage("getLinkedElement.ajax", webInterface) { + override val needsFormPassword = false + override fun createJsonObject(request: FreenetRequest): JsonReturnObject = request.httpRequest.getParam("elements", "[]").asJson() .map(JsonNode::asText) @@ -37,7 +39,6 @@ class GetLinkedElementAjaxPage(webInterface: WebInterface, private val elementLo } } - override fun needsFormPassword() = false override fun requiresLogin() = false private fun String.asJson() = ObjectMapper().readTree(this).asIterable() 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 1671d6d..c3ea74c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt @@ -16,7 +16,7 @@ import java.io.StringWriter */ class GetNotificationsAjaxPage(webInterface: WebInterface) : JsonPage("getNotifications.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun requiresLogin() = false override fun createJsonObject(request: FreenetRequest) = diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt index 2b1deca..2d902a6 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt @@ -15,7 +15,7 @@ import net.pterodactylus.util.template.Template */ class GetPostAjaxPage(webInterface: WebInterface, private val postTemplate: Template) : LoggedInJsonPage("getPost.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["post"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt index 332ab87..fc4b482 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt @@ -15,7 +15,7 @@ import net.pterodactylus.util.template.Template */ class GetReplyAjaxPage(webInterface: WebInterface, private val template: Template) : LoggedInJsonPage("getReply.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["reply"] 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 696c65a..925f628 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -49,7 +49,7 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E private fun String.asJson() = ObjectMapper().readTree(this).asIterable() - override fun needsFormPassword() = false + override val needsFormPassword = false override fun requiresLogin() = false private fun SoneOptions.toJsonOptions() = jsonObject { 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 87eafc3..759cdc0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -22,7 +22,7 @@ class GetTimesAjaxPage(webInterface: WebInterface, this.timeZone = timeZone } - override fun needsFormPassword() = false + override val needsFormPassword = false override fun requiresLogin() = false override fun createJsonObject(request: FreenetRequest) = 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 f98ad28..f12a778 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt @@ -9,7 +9,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest */ class GetTranslationAjaxPage(webInterface: WebInterface) : JsonPage("getTranslation.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun requiresLogin() = false override fun createJsonObject(request: FreenetRequest) = 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 1136616..9ea1d1d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt @@ -24,7 +24,7 @@ abstract class JsonPage(private val path: String, protected val webInterface: We override fun getPath() = path override fun isPrefixPage() = false - open fun needsFormPassword() = true + open val needsFormPassword = true open fun requiresLogin() = true protected fun createSuccessJsonObject() = JsonReturnObject(true) @@ -38,7 +38,7 @@ abstract class JsonPage(private val path: String, protected val webInterface: We if (core.preferences.isRequireFullAccess && !request.toadletContext.isAllowedFullAccess) { return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString()) } - if (needsFormPassword() && request.parameters["formPassword"] != webInterface.formPassword) { + 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)) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt index 694f170..2e0eda3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt @@ -25,7 +25,7 @@ class JsonPageBaseTest : TestObjects() { private val page = object : JsonPage("path.html", webInterface) { - override fun needsFormPassword() = this@JsonPageBaseTest.needsFormPassword + override val needsFormPassword get() = this@JsonPageBaseTest.needsFormPassword override fun createJsonObject(request: FreenetRequest) = pageResponse().also { pageCallCounter.incrementAndGet() } 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 558b414..26fde7d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -29,7 +29,7 @@ abstract class JsonPageTest( @Test fun `page needs form password`() { - assertThat(page.needsFormPassword(), equalTo(needsFormPassword)) + assertThat(page.needsFormPassword, equalTo(needsFormPassword)) } @Test -- 2.7.4