🔥 Remove “create” flag from session provider interface
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 18:29:47 +0000 (20:29 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 18:30:07 +0000 (20:30 +0200)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/kotlin/net/pterodactylus/sone/web/SessionProvider.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt

index 5448054..d8d5e26 100644 (file)
@@ -265,8 +265,8 @@ public class WebInterface implements SessionProvider {
 
        @Override
        @Nullable
 
        @Override
        @Nullable
-       public Sone getCurrentSone(@Nonnull ToadletContext toadletContext, boolean createSession) {
-               return createSession ? getCurrentSoneCreatingSession(toadletContext) : getCurrentSoneWithoutCreatingSession(toadletContext);
+       public Sone getCurrentSone(@Nonnull ToadletContext toadletContext) {
+               return getCurrentSoneWithoutCreatingSession(toadletContext);
        }
 
        /**
        }
 
        /**
index 463ddaa..93cd6af 100644 (file)
@@ -8,7 +8,7 @@ import net.pterodactylus.sone.data.Sone
  */
 interface SessionProvider {
 
  */
 interface SessionProvider {
 
-       fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true): Sone?
+       fun getCurrentSone(toadletContext: ToadletContext): Sone?
        fun setCurrentSone(toadletContext: ToadletContext, sone: Sone?)
 
 }
        fun setCurrentSone(toadletContext: ToadletContext, sone: Sone?)
 
 }
index 99c0828..574a0a8 100644 (file)
@@ -32,7 +32,7 @@ abstract class JsonPage(protected val webInterface: WebInterface) : Page<Freenet
                        JsonErrorReturnObject(error)
 
        protected fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true) =
                        JsonErrorReturnObject(error)
 
        protected fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true) =
-                       sessionProvider.getCurrentSone(toadletContext, createSession)
+                       sessionProvider.getCurrentSone(toadletContext)
 
        override fun handleRequest(request: FreenetRequest, response: Response): Response {
                if (core.preferences.requireFullAccess && !request.toadletContext.isAllowedFullAccess) {
 
        override fun handleRequest(request: FreenetRequest, response: Response): Response {
                if (core.preferences.requireFullAccess && !request.toadletContext.isAllowedFullAccess) {
@@ -41,7 +41,7 @@ abstract class JsonPage(protected val webInterface: WebInterface) : Page<Freenet
                if (needsFormPassword && request.parameters["formPassword"] != webInterface.formPassword) {
                        return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString())
                }
                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) == null)) {
                        return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString())
                }
                return try {
                        return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString())
                }
                return try {
index bc00f99..86131c3 100644 (file)
@@ -29,7 +29,7 @@ open class SoneTemplatePage(
        protected val translation: Translation = webInterface.translation
 
        protected fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true) =
        protected val translation: Translation = webInterface.translation
 
        protected fun getCurrentSone(toadletContext: ToadletContext, createSession: Boolean = true) =
-                       sessionProvider.getCurrentSone(toadletContext, createSession)
+                       sessionProvider.getCurrentSone(toadletContext)
 
        protected fun setCurrentSone(toadletContext: ToadletContext, sone: Sone?) =
                        sessionProvider.setCurrentSone(toadletContext, sone)
 
        protected fun setCurrentSone(toadletContext: ToadletContext, sone: Sone?) =
                        sessionProvider.setCurrentSone(toadletContext, sone)
index f902533..6f77a9c 100644 (file)
@@ -80,7 +80,7 @@ open class TestObjects {
 
        init {
                whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
 
        init {
                whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
-               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(currentSone)
+               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone)
                whenever(webInterface.core).thenReturn(core)
                whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone)
                whenever(webInterface.core).thenReturn(core)
@@ -139,7 +139,7 @@ open class TestObjects {
        }
 
        protected fun unsetCurrentSone() {
        }
 
        protected fun unsetCurrentSone() {
-               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(null)
+               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(null)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null)
                whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null)
        }
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null)
                whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null)
        }
index 605ab33..096b3e6 100644 (file)
@@ -105,7 +105,7 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) -
 
        private fun setupWebInterface() {
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone)
 
        private fun setupWebInterface() {
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone)
-               whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone)
+               whenever(webInterface.getCurrentSone(eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getNotifications(currentSone)).then { notifications.values }
                whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() }
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getNotifications(currentSone)).then { notifications.values }
                whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() }
@@ -173,7 +173,7 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) -
 
        fun unsetCurrentSone() {
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(null)
 
        fun unsetCurrentSone() {
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(null)
-               whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(null)
+               whenever(webInterface.getCurrentSone(eq(toadletContext))).thenReturn(null)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(null)
        }
 
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(null)
        }