Use a property for “needsFormPassword” instead of a method
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 5 Oct 2017 19:27:30 +0000 (21:27 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 5 Oct 2017 19:27:30 +0000 (21:27 +0200)
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt

index 12e8309..335f269 100644 (file)
@@ -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"]) {
index 285c479..511ed42 100644 (file)
@@ -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()
index 1671d6d..c3ea74c 100644 (file)
@@ -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) =
index 2b1deca..2d902a6 100644 (file)
@@ -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"]
index 332ab87..fc4b482 100644 (file)
@@ -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"]
index 696c65a..925f628 100644 (file)
@@ -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 {
index 87eafc3..759cdc0 100644 (file)
@@ -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) =
index f98ad28..f12a778 100644 (file)
@@ -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) =
index 1136616..9ea1d1d 100644 (file)
@@ -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)) {
index 694f170..2e0eda3 100644 (file)
@@ -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() }
index 558b414..26fde7d 100644 (file)
@@ -29,7 +29,7 @@ abstract class JsonPageTest(
 
        @Test
        fun `page needs form password`() {
-               assertThat(page.needsFormPassword(), equalTo(needsFormPassword))
+               assertThat(page.needsFormPassword, equalTo(needsFormPassword))
        }
 
        @Test