From fc8e9ea5c978d2f5a00894e093364ae62f18934b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 23 Feb 2019 11:08:10 +0100 Subject: [PATCH] Replace Preferences with Kotlin version --- .../net/pterodactylus/sone/core/Preferences.java | 434 --------------------- .../pterodactylus/sone/core/PreferencesLoader.java | 22 +- .../net/pterodactylus/sone/core/Preferences.kt | 141 +++++++ .../net/pterodactylus/sone/web/ajax/JsonPage.kt | 2 +- .../pterodactylus/sone/web/pages/CreateSonePage.kt | 2 +- .../net/pterodactylus/sone/web/pages/LoginPage.kt | 2 +- .../net/pterodactylus/sone/web/pages/LogoutPage.kt | 2 +- .../pterodactylus/sone/web/pages/OptionsPage.kt | 26 +- .../sone/web/pages/SoneTemplatePage.kt | 2 +- .../sone/core/PreferencesLoaderTest.java | 4 +- .../net/pterodactylus/sone/core/PreferencesTest.kt | 92 ++--- .../sone/web/ajax/DistrustAjaxPageTest.kt | 2 +- .../sone/web/ajax/JsonPageBaseTest.kt | 2 +- .../sone/web/ajax/TrustAjaxPageTest.kt | 2 +- .../sone/web/pages/BookmarksPageTest.kt | 2 +- .../sone/web/pages/CreateSonePageTest.kt | 4 +- .../sone/web/pages/ImageBrowserPageTest.kt | 2 +- .../pterodactylus/sone/web/pages/IndexPageTest.kt | 4 +- .../pterodactylus/sone/web/pages/LoginPageTest.kt | 6 +- .../pterodactylus/sone/web/pages/LogoutPageTest.kt | 4 +- .../pterodactylus/sone/web/pages/NewPageTest.kt | 6 +- .../sone/web/pages/OptionsPageTest.kt | 30 +- .../pterodactylus/sone/web/pages/SearchPageTest.kt | 8 +- .../sone/web/pages/SoneTemplatePageTest.kt | 4 +- .../sone/web/pages/ViewSonePageTest.kt | 2 +- 25 files changed, 257 insertions(+), 550 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/core/Preferences.java create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/Preferences.kt diff --git a/src/main/java/net/pterodactylus/sone/core/Preferences.java b/src/main/java/net/pterodactylus/sone/core/Preferences.java deleted file mode 100644 index 283f8e2..0000000 --- a/src/main/java/net/pterodactylus/sone/core/Preferences.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Sone - Preferences.java - Copyright © 2013–2019 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.core; - -import static com.google.common.base.Predicates.equalTo; -import static java.lang.Integer.MAX_VALUE; -import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS; -import static net.pterodactylus.sone.utils.IntegerRangePredicate.range; - -import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent; -import net.pterodactylus.sone.fcp.FcpInterface; -import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; -import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent; -import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent; -import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged; -import net.pterodactylus.sone.utils.DefaultOption; -import net.pterodactylus.sone.utils.Option; -import net.pterodactylus.util.config.Configuration; -import net.pterodactylus.util.config.ConfigurationException; - -import com.google.common.base.Predicates; -import com.google.common.eventbus.EventBus; - -/** - * Convenience interface for external classes that want to access the core’s - * configuration. - */ -public class Preferences { - - private final EventBus eventBus; - private final Option insertionDelay = - new DefaultOption<>(60, range(0, MAX_VALUE)); - private final Option postsPerPage = - new DefaultOption<>(10, range(1, MAX_VALUE)); - private final Option imagesPerPage = - new DefaultOption<>(9, range(1, MAX_VALUE)); - private final Option charactersPerPost = - new DefaultOption<>(400, Predicates.or( - range(50, MAX_VALUE), equalTo(-1))); - private final Option postCutOffLength = - new DefaultOption<>(200, range(50, MAX_VALUE)); - private final Option requireFullAccess = - new DefaultOption<>(false); - private final Option positiveTrust = - new DefaultOption<>(75, range(0, 100)); - private final Option negativeTrust = - new DefaultOption<>(-25, range(-100, 100)); - private final Option trustComment = - new DefaultOption<>("Set from Sone Web Interface"); - private final Option activateFcpInterface = - new DefaultOption<>(false); - private final Option fcpFullAccessRequired = - new DefaultOption<>(ALWAYS); - - public Preferences(EventBus eventBus) { - this.eventBus = eventBus; - } - - /** - * Returns the insertion delay. - * - * @return The insertion delay - */ - public int getInsertionDelay() { - return insertionDelay.get(); - } - - /** - * Validates the given insertion delay. - * - * @param insertionDelay - * The insertion delay to validate - * @return {@code true} if the given insertion delay was valid, - * {@code false} otherwise - */ - public boolean validateInsertionDelay(Integer insertionDelay) { - return this.insertionDelay.validate(insertionDelay); - } - - /** - * Sets the insertion delay - * - * @param insertionDelay - * The new insertion delay, or {@code null} to restore it to - * the default value - * @return This preferences - */ - public Preferences setInsertionDelay(Integer insertionDelay) { - this.insertionDelay.set(insertionDelay); - eventBus.post(new InsertionDelayChangedEvent(getInsertionDelay())); - eventBus.post(new PreferenceChangedEvent("InsertionDelay", getInsertionDelay())); - return this; - } - - /** - * Returns the number of posts to show per page. - * - * @return The number of posts to show per page - */ - public int getPostsPerPage() { - return postsPerPage.get(); - } - - /** - * Validates the number of posts per page. - * - * @param postsPerPage - * The number of posts per page - * @return {@code true} if the number of posts per page was valid, - * {@code false} otherwise - */ - public boolean validatePostsPerPage(Integer postsPerPage) { - return this.postsPerPage.validate(postsPerPage); - } - - /** - * Sets the number of posts to show per page. - * - * @param postsPerPage - * The number of posts to show per page - * @return This preferences object - */ - public Preferences setPostsPerPage(Integer postsPerPage) { - this.postsPerPage.set(postsPerPage); - eventBus.post(new PreferenceChangedEvent("PostsPerPage", getPostsPerPage())); - return this; - } - - /** - * Returns the number of images to show per page. - * - * @return The number of images to show per page - */ - public int getImagesPerPage() { - return imagesPerPage.get(); - } - - /** - * Validates the number of images per page. - * - * @param imagesPerPage - * The number of images per page - * @return {@code true} if the number of images per page was valid, - * {@code false} otherwise - */ - public boolean validateImagesPerPage(Integer imagesPerPage) { - return this.imagesPerPage.validate(imagesPerPage); - } - - /** - * Sets the number of images per page. - * - * @param imagesPerPage - * The number of images per page - * @return This preferences object - */ - public Preferences setImagesPerPage(Integer imagesPerPage) { - this.imagesPerPage.set(imagesPerPage); - return this; - } - - /** - * Returns the number of characters per post, or -1 if the - * posts should not be cut off. - * - * @return The numbers of characters per post - */ - public int getCharactersPerPost() { - return charactersPerPost.get(); - } - - /** - * Validates the number of characters per post. - * - * @param charactersPerPost - * The number of characters per post - * @return {@code true} if the number of characters per post was valid, - * {@code false} otherwise - */ - public boolean validateCharactersPerPost(Integer charactersPerPost) { - return this.charactersPerPost.validate(charactersPerPost); - } - - /** - * Sets the number of characters per post. - * - * @param charactersPerPost - * The number of characters per post, or -1 to - * not cut off the posts - * @return This preferences objects - */ - public Preferences setCharactersPerPost(Integer charactersPerPost) { - this.charactersPerPost.set(charactersPerPost); - return this; - } - - /** - * Returns the number of characters the shortened post should have. - * - * @return The number of characters of the snippet - */ - public int getPostCutOffLength() { - return postCutOffLength.get(); - } - - /** - * Validates the number of characters after which to cut off the post. - * - * @param postCutOffLength - * The number of characters of the snippet - * @return {@code true} if the number of characters of the snippet is - * valid, {@code false} otherwise - */ - public boolean validatePostCutOffLength(Integer postCutOffLength) { - return this.postCutOffLength.validate(postCutOffLength); - } - - /** - * Sets the number of characters the shortened post should have. - * - * @param postCutOffLength - * The number of characters of the snippet - * @return This preferences - */ - public Preferences setPostCutOffLength(Integer postCutOffLength) { - this.postCutOffLength.set(postCutOffLength); - return this; - } - - /** - * Returns whether Sone requires full access to be even visible. - * - * @return {@code true} if Sone requires full access, {@code false} - * otherwise - */ - public boolean isRequireFullAccess() { - return requireFullAccess.get(); - } - - /** - * Sets whether Sone requires full access to be even visible. - * - * @param requireFullAccess - * {@code true} if Sone requires full access, {@code false} - * otherwise - */ - public void setRequireFullAccess(Boolean requireFullAccess) { - this.requireFullAccess.set(requireFullAccess); - } - - /** - * Returns the positive trust. - * - * @return The positive trust - */ - public int getPositiveTrust() { - return positiveTrust.get(); - } - - /** - * Validates the positive trust. - * - * @param positiveTrust - * The positive trust to validate - * @return {@code true} if the positive trust was valid, {@code false} - * otherwise - */ - public boolean validatePositiveTrust(Integer positiveTrust) { - return this.positiveTrust.validate(positiveTrust); - } - - /** - * Sets the positive trust. - * - * @param positiveTrust - * The new positive trust, or {@code null} to restore it to - * the default vlaue - * @return This preferences - */ - public Preferences setPositiveTrust(Integer positiveTrust) { - this.positiveTrust.set(positiveTrust); - return this; - } - - /** - * Returns the negative trust. - * - * @return The negative trust - */ - public int getNegativeTrust() { - return negativeTrust.get(); - } - - /** - * Validates the negative trust. - * - * @param negativeTrust - * The negative trust to validate - * @return {@code true} if the negative trust was valid, {@code false} - * otherwise - */ - public boolean validateNegativeTrust(Integer negativeTrust) { - return this.negativeTrust.validate(negativeTrust); - } - - /** - * Sets the negative trust. - * - * @param negativeTrust - * The negative trust, or {@code null} to restore it to the - * default value - * @return The preferences - */ - public Preferences setNegativeTrust(Integer negativeTrust) { - this.negativeTrust.set(negativeTrust); - return this; - } - - /** - * Returns the trust comment. This is the comment that is set in the web - * of trust when a trust value is assigned to an identity. - * - * @return The trust comment - */ - public String getTrustComment() { - return trustComment.get(); - } - - /** - * Sets the trust comment. - * - * @param trustComment - * The trust comment, or {@code null} to restore it to the - * default value - * @return This preferences - */ - public Preferences setTrustComment(String trustComment) { - this.trustComment.set(trustComment); - return this; - } - - /** - * Returns whether the {@link FcpInterface FCP interface} is currently - * active. - * - * @see FcpInterface#setActive(boolean) - * @return {@code true} if the FCP interface is currently active, - * {@code false} otherwise - */ - public boolean isFcpInterfaceActive() { - return activateFcpInterface.get(); - } - - /** - * Sets whether the {@link FcpInterface FCP interface} is currently - * active. - * - * @see FcpInterface#setActive(boolean) - * @param fcpInterfaceActive - * {@code true} to activate the FCP interface, {@code false} - * to deactivate the FCP interface - * @return This preferences object - */ - public Preferences setFcpInterfaceActive(Boolean fcpInterfaceActive) { - this.activateFcpInterface.set(fcpInterfaceActive); - if (isFcpInterfaceActive()) { - eventBus.post(new FcpInterfaceActivatedEvent()); - } else { - eventBus.post(new FcpInterfaceDeactivatedEvent()); - } - return this; - } - - /** - * Returns the action level for which full access to the FCP interface - * is required. - * - * @return The action level for which full access to the FCP interface - * is required - */ - public FullAccessRequired getFcpFullAccessRequired() { - return fcpFullAccessRequired.get(); - } - - /** - * Sets the action level for which full access to the FCP interface is - * required - * - * @param fcpFullAccessRequired - * The action level - * @return This preferences - */ - public Preferences setFcpFullAccessRequired( - FullAccessRequired fcpFullAccessRequired) { - this.fcpFullAccessRequired.set(fcpFullAccessRequired); - eventBus.post(new FullAccessRequiredChanged(getFcpFullAccessRequired())); - return this; - } - - public void saveTo(Configuration configuration) throws ConfigurationException { - configuration.getIntValue("Option/ConfigurationVersion").setValue(0); - configuration.getIntValue("Option/InsertionDelay").setValue(insertionDelay.getReal()); - configuration.getIntValue("Option/PostsPerPage").setValue(postsPerPage.getReal()); - configuration.getIntValue("Option/ImagesPerPage").setValue(imagesPerPage.getReal()); - configuration.getIntValue("Option/CharactersPerPost").setValue(charactersPerPost.getReal()); - configuration.getIntValue("Option/PostCutOffLength").setValue(postCutOffLength.getReal()); - configuration.getBooleanValue("Option/RequireFullAccess").setValue(requireFullAccess.getReal()); - configuration.getIntValue("Option/PositiveTrust").setValue(positiveTrust.getReal()); - configuration.getIntValue("Option/NegativeTrust").setValue(negativeTrust.getReal()); - configuration.getStringValue("Option/TrustComment").setValue(trustComment.getReal()); - configuration.getBooleanValue("Option/ActivateFcpInterface").setValue(activateFcpInterface.getReal()); - configuration.getIntValue("Option/FcpFullAccessRequired").setValue(toInt(fcpFullAccessRequired.getReal())); - } - - private Integer toInt(FullAccessRequired fullAccessRequired) { - return (fullAccessRequired == null) ? null : fullAccessRequired.ordinal(); - } - -} diff --git a/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java b/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java index fab3148..a730983 100644 --- a/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java +++ b/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java @@ -31,31 +31,31 @@ public class PreferencesLoader { } private void loadInsertionDelay(Configuration configuration) { - preferences.setInsertionDelay(configuration.getIntValue( + preferences.setNewInsertionDelay(configuration.getIntValue( "Option/InsertionDelay").getValue(null)); } private void loadPostsPerPage(Configuration configuration) { - preferences.setPostsPerPage( + preferences.setNewPostsPerPage( configuration.getIntValue("Option/PostsPerPage") .getValue(null)); } private void loadImagesPerPage(Configuration configuration) { - preferences.setImagesPerPage( + preferences.setNewImagesPerPage( configuration.getIntValue("Option/ImagesPerPage") .getValue(null)); } private void loadCharactersPerPost(Configuration configuration) { - preferences.setCharactersPerPost( + preferences.setNewCharactersPerPost( configuration.getIntValue("Option/CharactersPerPost") .getValue(null)); } private void loadPostCutOffLength(Configuration configuration) { try { - preferences.setPostCutOffLength( + preferences.setNewPostCutOffLength( configuration.getIntValue("Option/PostCutOffLength") .getValue(null)); } catch (IllegalArgumentException iae1) { @@ -64,38 +64,38 @@ public class PreferencesLoader { } private void loadRequireFullAccess(Configuration configuration) { - preferences.setRequireFullAccess( + preferences.setNewRequireFullAccess( configuration.getBooleanValue("Option/RequireFullAccess") .getValue(null)); } private void loadPositiveTrust(Configuration configuration) { - preferences.setPositiveTrust( + preferences.setNewPositiveTrust( configuration.getIntValue("Option/PositiveTrust") .getValue(null)); } private void loadNegativeTrust(Configuration configuration) { - preferences.setNegativeTrust( + preferences.setNewNegativeTrust( configuration.getIntValue("Option/NegativeTrust") .getValue(null)); } private void loadTrustComment(Configuration configuration) { - preferences.setTrustComment( + preferences.setNewTrustComment( configuration.getStringValue("Option/TrustComment") .getValue(null)); } private void loadFcpInterfaceActive(Configuration configuration) { - preferences.setFcpInterfaceActive(configuration.getBooleanValue( + preferences.setNewFcpInterfaceActive(configuration.getBooleanValue( "Option/ActivateFcpInterface").getValue(null)); } private void loadFcpFullAccessRequired(Configuration configuration) { Integer fullAccessRequiredInteger = configuration .getIntValue("Option/FcpFullAccessRequired").getValue(null); - preferences.setFcpFullAccessRequired( + preferences.setNewFcpFullAccessRequired( (fullAccessRequiredInteger == null) ? null : FullAccessRequired.values()[fullAccessRequiredInteger]); } diff --git a/src/main/kotlin/net/pterodactylus/sone/core/Preferences.kt b/src/main/kotlin/net/pterodactylus/sone/core/Preferences.kt new file mode 100644 index 0000000..c445ed1 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/Preferences.kt @@ -0,0 +1,141 @@ +/* + * Sone - Preferences.java - Copyright © 2013–2019 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.core + +import com.google.common.base.Predicates.* +import com.google.common.eventbus.* +import net.pterodactylus.sone.core.event.* +import net.pterodactylus.sone.fcp.FcpInterface.* +import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.* +import net.pterodactylus.sone.fcp.event.* +import net.pterodactylus.sone.utils.* +import net.pterodactylus.sone.utils.IntegerRangePredicate.* +import net.pterodactylus.util.config.* +import java.lang.Integer.* + +/** + * Convenience interface for external classes that want to access the core’s + * configuration. + */ +class Preferences(private val eventBus: EventBus) { + + private val _insertionDelay = DefaultOption(60, range(0, MAX_VALUE)) + val insertionDelay: Int get() = _insertionDelay.get() + var newInsertionDelay: Int? + get() = unsupported + set(value) { + _insertionDelay.set(value) + eventBus.post(InsertionDelayChangedEvent(insertionDelay)) + eventBus.post(PreferenceChangedEvent("InsertionDelay", insertionDelay)) + } + + private val _postsPerPage = DefaultOption(10, range(1, MAX_VALUE)) + val postsPerPage: Int get() = _postsPerPage.get() + var newPostsPerPage: Int? + get() = unsupported + set(value) { + _postsPerPage.set(value) + eventBus.post(PreferenceChangedEvent("PostsPerPage", postsPerPage)) + } + + private val _imagesPerPage = DefaultOption(9, range(1, MAX_VALUE)) + val imagesPerPage: Int get() = _imagesPerPage.get() + var newImagesPerPage: Int? + get() = unsupported + set (value: Int?) = _imagesPerPage.set(value) + + private val _charactersPerPost = DefaultOption(400, or(range(50, MAX_VALUE), equalTo(-1))) + val charactersPerPost: Int get() = _charactersPerPost.get() + var newCharactersPerPost: Int? + get() = unsupported + set(value) = _charactersPerPost.set(value) + + private val _postCutOffLength = DefaultOption(200, range(50, MAX_VALUE)) + val postCutOffLength: Int get() = _postCutOffLength.get() + var newPostCutOffLength: Int? + get() = unsupported + set(value) = _postCutOffLength.set(value) + + private val _requireFullAccess = DefaultOption(false) + val requireFullAccess: Boolean get() = _requireFullAccess.get() + var newRequireFullAccess: Boolean? + get() = unsupported + set(value) = _requireFullAccess.set(value) + + private val _positiveTrust = DefaultOption(75, range(0, 100)) + val positiveTrust: Int get() = _positiveTrust.get() + var newPositiveTrust: Int? + get() = unsupported + set(value) = _positiveTrust.set(value) + + private val _negativeTrust = DefaultOption(-25, range(-100, 100)) + val negativeTrust: Int get() = _negativeTrust.get() + var newNegativeTrust: Int? + get() = unsupported + set(value) = _negativeTrust.set(value) + + private val _trustComment = DefaultOption("Set from Sone Web Interface") + val trustComment: String get() = _trustComment.get() + var newTrustComment: String? + get() = unsupported + set(value) = _trustComment.set(value) + + private val _fcpInterfaceActive = DefaultOption(false) + val fcpInterfaceActive: Boolean get() = _fcpInterfaceActive.get() + var newFcpInterfaceActive: Boolean? + get() = unsupported + set(value) { + _fcpInterfaceActive.set(value) + when (value) { + true -> eventBus.post(FcpInterfaceActivatedEvent()) + else -> eventBus.post(FcpInterfaceDeactivatedEvent()) + } + } + + private val _fcpFullAccessRequired = DefaultOption(ALWAYS) + val fcpFullAccessRequired: FullAccessRequired get() = _fcpFullAccessRequired.get() + var newFcpFullAccessRequired: FullAccessRequired? + get() = unsupported + set(value) { + _fcpFullAccessRequired.set(value) + eventBus.post(FullAccessRequiredChanged(fcpFullAccessRequired)) + } + + @Throws(ConfigurationException::class) + fun saveTo(configuration: Configuration) { + configuration.getIntValue("Option/ConfigurationVersion").value = 0 + configuration.getIntValue("Option/InsertionDelay").value = _insertionDelay.real + configuration.getIntValue("Option/PostsPerPage").value = _postsPerPage.real + configuration.getIntValue("Option/ImagesPerPage").value = _imagesPerPage.real + configuration.getIntValue("Option/CharactersPerPost").value = _charactersPerPost.real + configuration.getIntValue("Option/PostCutOffLength").value = _postCutOffLength.real + configuration.getBooleanValue("Option/RequireFullAccess").value = _requireFullAccess.real + configuration.getIntValue("Option/PositiveTrust").value = _positiveTrust.real + configuration.getIntValue("Option/NegativeTrust").value = _negativeTrust.real + configuration.getStringValue("Option/TrustComment").value = _trustComment.real + configuration.getBooleanValue("Option/ActivateFcpInterface").value = _fcpInterfaceActive.real + configuration.getIntValue("Option/FcpFullAccessRequired").value = toInt(_fcpFullAccessRequired.real) + } + + private fun toInt(fullAccessRequired: FullAccessRequired?): Int? { + return fullAccessRequired?.ordinal + } + +} + +private val unsupported: Nothing get() = throw UnsupportedOperationException() 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 2da5edc..5b56031 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt @@ -35,7 +35,7 @@ abstract class JsonPage(private val path: String, protected val webInterface: We sessionProvider.getCurrentSone(toadletContext, createSession) override fun handleRequest(request: FreenetRequest, response: Response): Response { - if (core.preferences.isRequireFullAccess && !request.toadletContext.isAllowedFullAccess) { + if (core.preferences.requireFullAccess && !request.toadletContext.isAllowedFullAccess) { return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString()) } if (needsFormPassword && request.parameters["formPassword"] != webInterface.formPassword) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt index 27b5ad4..a0fe7cb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -37,7 +37,7 @@ class CreateSonePage @Inject constructor(template: Template, webInterface: WebIn } override fun isEnabled(toadletContext: ToadletContext) = - if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) { + if (webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess) { false } else { (getCurrentSone(toadletContext) == null) || (webInterface.core.localSones.size == 1) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt index c6c50bb..4313a59 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt @@ -33,7 +33,7 @@ class LoginPage @Inject constructor(template: Template, webInterface: WebInterfa getCurrentSone(freenetRequest.toadletContext)?.let { "index.html" } override fun isEnabled(toadletContext: ToadletContext) = when { - webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess -> false + webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess -> false else -> getCurrentSone(toadletContext, false) == null } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt index 5adefad..4659d03 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt @@ -20,7 +20,7 @@ class LogoutPage @Inject constructor(template: Template, webInterface: WebInterf } override fun isEnabled(toadletContext: ToadletContext): Boolean = - if (webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess) { + if (webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess) { false } else getCurrentSone(toadletContext) != null && webInterface.core.localSones.size != 1 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt index 31a65c1..27d85c2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -41,8 +41,8 @@ class OptionsPage @Inject constructor(template: Template, webInterface: WebInter val fullAccessRequired = "require-full-access" in freenetRequest.parameters val fcpInterfaceActive = "fcp-interface-active" in freenetRequest.parameters - webInterface.core.preferences.isRequireFullAccess = fullAccessRequired - webInterface.core.preferences.isFcpInterfaceActive = fcpInterfaceActive + webInterface.core.preferences.newRequireFullAccess = fullAccessRequired + webInterface.core.preferences.newFcpInterfaceActive = fcpInterfaceActive val postsPerPage = freenetRequest.parameters["posts-per-page"]?.toIntOrNull() val charactersPerPost = freenetRequest.parameters["characters-per-post"]?.toIntOrNull() @@ -54,15 +54,15 @@ class OptionsPage @Inject constructor(template: Template, webInterface: WebInter val positiveTrust = freenetRequest.parameters["positive-trust"]?.toIntOrNull() val trustComment = freenetRequest.parameters["trust-comment"]?.emptyToNull - if (cantSetOption { it.setPostsPerPage(postsPerPage) }) fieldsWithErrors += "posts-per-page" - if (cantSetOption { it.setCharactersPerPost(charactersPerPost) }) fieldsWithErrors += "characters-per-post" - if (cantSetOption { it.setPostCutOffLength(postCutOffLength) }) fieldsWithErrors += "post-cut-off-length" - if (cantSetOption { it.setImagesPerPage(imagesPerPage) }) fieldsWithErrors += "images-per-page" - if (cantSetOption { it.setInsertionDelay(insertionDelay) }) fieldsWithErrors += "insertion-delay" - fcpFullAccessRequired?.also { if (cantSetOption { it.fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" } - if (cantSetOption { it.setNegativeTrust(negativeTrust) }) fieldsWithErrors += "negative-trust" - if (cantSetOption { it.setPositiveTrust(positiveTrust) }) fieldsWithErrors += "positive-trust" - if (cantSetOption { it.trustComment = trustComment }) fieldsWithErrors += "trust-comment" + if (cantSetOption { it.newPostsPerPage = postsPerPage }) fieldsWithErrors += "posts-per-page" + if (cantSetOption { it.newCharactersPerPost = charactersPerPost }) fieldsWithErrors += "characters-per-post" + if (cantSetOption { it.newPostCutOffLength = postCutOffLength }) fieldsWithErrors += "post-cut-off-length" + if (cantSetOption { it.newImagesPerPage = imagesPerPage }) fieldsWithErrors += "images-per-page" + if (cantSetOption { it.newInsertionDelay = insertionDelay }) fieldsWithErrors += "insertion-delay" + fcpFullAccessRequired?.also { if (cantSetOption { it.newFcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" } + if (cantSetOption { it.newNegativeTrust = negativeTrust }) fieldsWithErrors += "negative-trust" + if (cantSetOption { it.newPositiveTrust = positiveTrust }) fieldsWithErrors += "positive-trust" + if (cantSetOption { it.newTrustComment = trustComment }) fieldsWithErrors += "trust-comment" if (fieldsWithErrors.isEmpty()) { webInterface.core.touchConfiguration() @@ -84,8 +84,8 @@ class OptionsPage @Inject constructor(template: Template, webInterface: WebInter templateContext["characters-per-post"] = preferences.charactersPerPost templateContext["fcp-full-access-required"] = preferences.fcpFullAccessRequired.ordinal templateContext["images-per-page"] = preferences.imagesPerPage - templateContext["fcp-interface-active"] = preferences.isFcpInterfaceActive - templateContext["require-full-access"] = preferences.isRequireFullAccess + templateContext["fcp-interface-active"] = preferences.fcpInterfaceActive + templateContext["require-full-access"] = preferences.requireFullAccess templateContext["negative-trust"] = preferences.negativeTrust templateContext["positive-trust"] = preferences.positiveTrust templateContext["post-cut-off-length"] = preferences.postCutOffLength diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt index b4178cc..54cd5cc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt @@ -87,7 +87,7 @@ open class SoneTemplatePage @JvmOverloads constructor( override fun isEnabled(toadletContext: ToadletContext) = when { requiresLogin && getCurrentSone(toadletContext) == null -> false - core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess -> false + core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess -> false else -> true } diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java index 3ba56a8..d550f25 100644 --- a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java @@ -61,11 +61,11 @@ public class PreferencesLoaderTest { assertThat(preferences.getImagesPerPage(), is(12)); assertThat(preferences.getCharactersPerPost(), is(150)); assertThat(preferences.getPostCutOffLength(), is(300)); - assertThat(preferences.isRequireFullAccess(), is(true)); + assertThat(preferences.getRequireFullAccess(), is(true)); assertThat(preferences.getPositiveTrust(), is(50)); assertThat(preferences.getNegativeTrust(), is(-50)); assertThat(preferences.getTrustComment(), is("Trusted")); - assertThat(preferences.isFcpInterfaceActive(), is(true)); + assertThat(preferences.getFcpInterfaceActive(), is(true)); assertThat(preferences.getFcpFullAccessRequired(), is(WRITING)); } diff --git a/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt index f4f4818..ca58c40 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt @@ -25,26 +25,26 @@ class PreferencesTest { @Test fun `preferences retain insertion delay`() { - preferences.insertionDelay = 15 + preferences.newInsertionDelay = 15 assertThat(preferences.insertionDelay, equalTo(15)) } @Test fun `preferences sends event on setting insertion delay`() { - preferences.insertionDelay = 15 + preferences.newInsertionDelay = 15 verify(eventBus, atLeastOnce()).post(eventsCaptor.capture()) assertThat(eventsCaptor.allValues, hasItem(InsertionDelayChangedEvent(15))) } @Test(expected = IllegalArgumentException::class) fun `invalid insertion delay is rejected`() { - preferences.insertionDelay = -15 + preferences.newInsertionDelay = -15 } @Test fun `no event is sent when invalid insertion delay is set`() { try { - preferences.insertionDelay = -15 + preferences.newInsertionDelay = -15 } catch (iae: IllegalArgumentException) { /* ignore. */ } @@ -54,7 +54,7 @@ class PreferencesTest { @Test fun `preferences return default value when insertion delay is set to null`() { - preferences.setInsertionDelay(null) + preferences.newInsertionDelay = null assertThat(preferences.insertionDelay, equalTo(60)) } @@ -65,18 +65,18 @@ class PreferencesTest { @Test fun `preferences retain posts per page`() { - preferences.postsPerPage = 15 + preferences.newPostsPerPage = 15 assertThat(preferences.postsPerPage, equalTo(15)) } @Test(expected = IllegalArgumentException::class) fun `invalid posts per page is rejected`() { - preferences.postsPerPage = -15 + preferences.newPostsPerPage = -15 } @Test fun `preferences return default value when posts per page is set to null`() { - preferences.setPostsPerPage(null) + preferences.newPostsPerPage = null assertThat(preferences.postsPerPage, equalTo(10)) } @@ -87,18 +87,18 @@ class PreferencesTest { @Test fun `preferences retain images per page`() { - preferences.imagesPerPage = 15 + preferences.newImagesPerPage = 15 assertThat(preferences.imagesPerPage, equalTo(15)) } @Test(expected = IllegalArgumentException::class) fun `invalid images per page is rejected`() { - preferences.imagesPerPage = -15 + preferences.newImagesPerPage = -15 } @Test fun `preferences return default value when images per page is set to null`() { - preferences.setImagesPerPage(null) + preferences.newImagesPerPage = null assertThat(preferences.imagesPerPage, equalTo(9)) } @@ -109,18 +109,18 @@ class PreferencesTest { @Test fun `preferences retain characters per post`() { - preferences.charactersPerPost = 150 + preferences.newCharactersPerPost = 150 assertThat(preferences.charactersPerPost, equalTo(150)) } @Test(expected = IllegalArgumentException::class) fun `invalid characters per post is rejected`() { - preferences.charactersPerPost = -15 + preferences.newCharactersPerPost = -15 } @Test fun `preferences return default value when characters per post is set to null`() { - preferences.setCharactersPerPost(null) + preferences.newCharactersPerPost = null assertThat(preferences.charactersPerPost, equalTo(400)) } @@ -131,23 +131,23 @@ class PreferencesTest { @Test fun `preferences retain post cut off length`() { - preferences.postCutOffLength = 150 + preferences.newPostCutOffLength = 150 assertThat(preferences.postCutOffLength, equalTo(150)) } @Test(expected = IllegalArgumentException::class) fun `invalid post cut off length is rejected`() { - preferences.postCutOffLength = -15 + preferences.newPostCutOffLength = -15 } @Test(expected = IllegalArgumentException::class) fun `cut off length of minus one is not allowed`() { - preferences.postCutOffLength = -1 + preferences.newPostCutOffLength = -1 } @Test fun `preferences return default value when post cut off length is set to null`() { - preferences.setPostCutOffLength(null) + preferences.newPostCutOffLength = null assertThat(preferences.postCutOffLength, equalTo(200)) } @@ -158,41 +158,41 @@ class PreferencesTest { @Test fun `preferences retain require full access of true`() { - preferences.isRequireFullAccess = true - assertThat(preferences.isRequireFullAccess, equalTo(true)) + preferences.newRequireFullAccess = true + assertThat(preferences.requireFullAccess, equalTo(true)) } @Test fun `preferences retain require full access of false`() { - preferences.isRequireFullAccess = false - assertThat(preferences.isRequireFullAccess, equalTo(false)) + preferences.newRequireFullAccess = false + assertThat(preferences.requireFullAccess, equalTo(false)) } @Test fun `preferences return default value when require full access is set to null`() { - preferences.setRequireFullAccess(null) - assertThat(preferences.isRequireFullAccess, equalTo(false)) + preferences.newRequireFullAccess = null + assertThat(preferences.requireFullAccess, equalTo(false)) } @Test fun `preferences start with require full access default value`() { - assertThat(preferences.isRequireFullAccess, equalTo(false)) + assertThat(preferences.requireFullAccess, equalTo(false)) } @Test fun `preferences retain positive trust`() { - preferences.positiveTrust = 15 + preferences.newPositiveTrust = 15 assertThat(preferences.positiveTrust, equalTo(15)) } @Test(expected = IllegalArgumentException::class) fun `invalid positive trust is rejected`() { - preferences.positiveTrust = -15 + preferences.newPositiveTrust = -15 } @Test fun `preferences return default value when positive trust is set to null`() { - preferences.setPositiveTrust(null) + preferences.newPositiveTrust = null assertThat(preferences.positiveTrust, equalTo(75)) } @@ -203,18 +203,18 @@ class PreferencesTest { @Test fun `preferences retain negative trust`() { - preferences.negativeTrust = -15 + preferences.newNegativeTrust = -15 assertThat(preferences.negativeTrust, equalTo(-15)) } @Test(expected = IllegalArgumentException::class) fun `invalid negative trust is rejected`() { - preferences.negativeTrust = 150 + preferences.newNegativeTrust = 150 } @Test fun `preferences return default value when negative trust is set to null`() { - preferences.setNegativeTrust(null) + preferences.newNegativeTrust = null assertThat(preferences.negativeTrust, equalTo(-25)) } @@ -225,13 +225,13 @@ class PreferencesTest { @Test fun `preferences retain trust comment`() { - preferences.trustComment = "Trust" + preferences.newTrustComment = "Trust" assertThat(preferences.trustComment, equalTo("Trust")) } @Test fun `preferences return default value when trust comment is set to null`() { - preferences.trustComment = null + preferences.newTrustComment = null assertThat(preferences.trustComment, equalTo("Set from Sone Web Interface")) } @@ -244,33 +244,33 @@ class PreferencesTest { @Test fun `preferences retain fcp interface active of true`() { - preferences.isFcpInterfaceActive = true - assertThat(preferences.isFcpInterfaceActive, equalTo(true)) + preferences.newFcpInterfaceActive = true + assertThat(preferences.fcpInterfaceActive, equalTo(true)) verify(eventBus).post(any(FcpInterfaceActivatedEvent::class.java)) } @Test fun `preferences retain fcp interface active of false`() { - preferences.isFcpInterfaceActive = false - assertThat(preferences.isFcpInterfaceActive, equalTo(false)) + preferences.newFcpInterfaceActive = false + assertThat(preferences.fcpInterfaceActive, equalTo(false)) verify(eventBus).post(any(FcpInterfaceDeactivatedEvent::class.java)) } @Test fun `preferences return default value when fcp interface active is set to null`() { - preferences.setFcpInterfaceActive(null) - assertThat(preferences.isFcpInterfaceActive, equalTo(false)) + preferences.newFcpInterfaceActive = null + assertThat(preferences.fcpInterfaceActive, equalTo(false)) verify(eventBus).post(any(FcpInterfaceDeactivatedEvent::class.java)) } @Test fun `preferences start with fcp interface active default value`() { - assertThat(preferences.isFcpInterfaceActive, equalTo(false)) + assertThat(preferences.fcpInterfaceActive, equalTo(false)) } @Test fun `preferences retain fcp full access required of no`() { - preferences.fcpFullAccessRequired = NO + preferences.newFcpFullAccessRequired = NO assertThat(preferences.fcpFullAccessRequired, equalTo(NO)) verifyFullAccessRequiredChangedEvent(NO) } @@ -285,21 +285,21 @@ class PreferencesTest { @Test fun `preferences retain fcp full access required of writing`() { - preferences.fcpFullAccessRequired = WRITING + preferences.newFcpFullAccessRequired = WRITING assertThat(preferences.fcpFullAccessRequired, equalTo(WRITING)) verifyFullAccessRequiredChangedEvent(WRITING) } @Test fun `preferences retain fcp full access required of always`() { - preferences.fcpFullAccessRequired = ALWAYS + preferences.newFcpFullAccessRequired = ALWAYS assertThat(preferences.fcpFullAccessRequired, equalTo(ALWAYS)) verifyFullAccessRequiredChangedEvent(ALWAYS) } @Test fun `preferences return default value when fcp full access required is set to null`() { - preferences.fcpFullAccessRequired = null + preferences.newFcpFullAccessRequired = null assertThat(preferences.fcpFullAccessRequired, equalTo(ALWAYS)) verifyFullAccessRequiredChangedEvent(ALWAYS) } @@ -311,14 +311,14 @@ class PreferencesTest { @Test fun `setting insertion delay to valid value sends change event`() { - preferences.insertionDelay = 30 + preferences.newInsertionDelay = 30 verify(eventBus, atLeastOnce()).post(eventsCaptor.capture()) assertThat(eventsCaptor.allValues, hasItem(PreferenceChangedEvent("InsertionDelay", 30))) } @Test fun `setting posts per page to valid value sends change event`() { - preferences.postsPerPage = 30 + preferences.newPostsPerPage = 30 verify(eventBus, atLeastOnce()).post(eventsCaptor.capture()) assertThat(eventsCaptor.allValues, hasItem(PreferenceChangedEvent("PostsPerPage", 30))) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt index 1cfa63e..868819e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt @@ -37,7 +37,7 @@ class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = :: @Test fun `request with valid sone results in correct trust value being sent back`() { - core.preferences.negativeTrust = -33 + core.preferences.newNegativeTrust = -33 val sone = mock() addSone(sone, "sone-id") addRequestParameter("sone", "sone-id") 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 75a0cd4..5e32a7d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt @@ -49,7 +49,7 @@ class JsonPageBaseTest : TestObjects() { @Test fun `page returns 403 is full access is required but request is not full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(403)) assertThat(response.statusText, equalTo("Forbidden")) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt index b4fd212..d557790 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt @@ -34,7 +34,7 @@ class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, n fun `request with valid sone returns positive trust value`() { addSone(sone, "sone-id") addRequestParameter("sone", "sone-id") - core.preferences.positiveTrust = 31 + core.preferences.newPositiveTrust = 31 assertThatJsonIsSuccessful() assertThat(json["trustValue"]?.asInt(), equalTo(31)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt index a488e25..2186f61 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt @@ -30,7 +30,7 @@ class BookmarksPageTest: WebPageTest(::BookmarksPage) { @Before fun setupBookmarkedPostsAndPagination() { whenever(core.bookmarkedPosts).thenReturn(setOf(post1, post2, post3)) - core.preferences.postsPerPage = 5 + core.preferences.newPostsPerPage = 5 } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt index 445579f..547347a 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt @@ -114,7 +114,7 @@ class CreateSonePageTest : WebPageTest(::CreateSonePage) { @Test fun `create sone is not shown in menu if full access is required but client doesn’t have full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true assertThat(page.isEnabled(toadletContext), equalTo(false)) } @@ -139,7 +139,7 @@ class CreateSonePageTest : WebPageTest(::CreateSonePage) { @Test fun `create sone is shown in menu if no sone is logged in and client has full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true whenever(toadletContext.isAllowedFullAccess).thenReturn(true) unsetCurrentSone() assertThat(page.isEnabled(toadletContext), equalTo(true)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt index c306b3e..0411030 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt @@ -90,7 +90,7 @@ class ImageBrowserPageTest: WebPageTest(::ImageBrowserPage) { @Test fun `get request for gallery can show second page`() { - core.preferences.imagesPerPage = 2 + core.preferences.newImagesPerPage = 2 val firstSone = createSone("first album", "second album") addSone("sone1", firstSone) val secondSone = createSone("third album", "fourth album") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt index b5dc447..1e200c1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt @@ -137,7 +137,7 @@ class IndexPageTest: WebPageTest({ template, webInterface -> IndexPage(template, fun `index page sets page correctly`() { val posts = listOf(createPost(3000), createPost(2000), createPost(1000)) whenever(currentSone.posts).thenReturn(posts) - core.preferences.postsPerPage = 1 + core.preferences.newPostsPerPage = 1 addHttpRequestParameter("page", "2") page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") @@ -146,7 +146,7 @@ class IndexPageTest: WebPageTest({ template, webInterface -> IndexPage(template, @Test fun `index page without posts sets correct pagination`() { - core.preferences.postsPerPage = 1 + core.preferences.newPostsPerPage = 1 page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") (templateContext["pagination"] as Pagination).let { pagination -> diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt index ae5b7af..9d29a55 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt @@ -111,7 +111,7 @@ class LoginPageTest: WebPageTest(::LoginPage) { @Test fun `page is not enabled if full access required and request is not full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true assertThat(page.isEnabled(toadletContext), equalTo(false)) } @@ -128,7 +128,7 @@ class LoginPageTest: WebPageTest(::LoginPage) { @Test fun `page is enabled if full access required and request is full access and there is no current sone`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true unsetCurrentSone() whenever(toadletContext.isAllowedFullAccess).thenReturn(true) assertThat(page.isEnabled(toadletContext), equalTo(true)) @@ -136,7 +136,7 @@ class LoginPageTest: WebPageTest(::LoginPage) { @Test fun `page is not enabled if full access required and request is full access but there is a current sone`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true whenever(toadletContext.isAllowedFullAccess).thenReturn(true) assertThat(page.isEnabled(toadletContext), equalTo(false)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LogoutPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LogoutPageTest.kt index 1ecbb1f..2efae9e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LogoutPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LogoutPageTest.kt @@ -39,7 +39,7 @@ class LogoutPageTest: WebPageTest(::LogoutPage) { @Test fun `page is not enabled if sone requires full access and request does not have full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true assertThat(page.isEnabled(toadletContext), equalTo(false)) } @@ -63,7 +63,7 @@ class LogoutPageTest: WebPageTest(::LogoutPage) { @Test fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true whenever(toadletContext.isAllowedFullAccess).thenReturn(true) whenever(core.localSones).thenReturn(listOf(currentSone, currentSone)) assertThat(page.isEnabled(toadletContext), equalTo(true)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt index 5c71e5d..fd654c1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt @@ -24,7 +24,7 @@ class NewPageTest: WebPageTest(::NewPage) { @Before fun setupNumberOfPostsPerPage() { - webInterface.core.preferences.postsPerPage = 5 + webInterface.core.preferences.newPostsPerPage = 5 } @Test @@ -64,7 +64,7 @@ class NewPageTest: WebPageTest(::NewPage) { @Test @Suppress("UNCHECKED_CAST") fun `posts are paginated properly`() { - webInterface.core.preferences.postsPerPage = 2 + webInterface.core.preferences.newPostsPerPage = 2 val posts = listOf(mock().withTime(2000), mock().withTime(3000), mock().withTime(1000)) whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts) verifyNoRedirect { @@ -75,7 +75,7 @@ class NewPageTest: WebPageTest(::NewPage) { @Test @Suppress("UNCHECKED_CAST") fun `posts are paginated properly on second page`() { - webInterface.core.preferences.postsPerPage = 2 + webInterface.core.preferences.newPostsPerPage = 2 addHttpRequestParameter("page", "1") val posts = listOf(mock().withTime(2000), mock().withTime(3000), mock().withTime(1000)) whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index 94ae905..a9dba9e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -25,17 +25,17 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { @Before fun setupPreferences() { - core.preferences.insertionDelay = 1 - core.preferences.charactersPerPost = 50 - core.preferences.fcpFullAccessRequired = WRITING - core.preferences.imagesPerPage = 4 - core.preferences.isFcpInterfaceActive = true - core.preferences.isRequireFullAccess = true - core.preferences.negativeTrust = 7 - core.preferences.positiveTrust = 8 - core.preferences.postCutOffLength = 51 - core.preferences.postsPerPage = 10 - core.preferences.trustComment = "11" + core.preferences.newInsertionDelay = 1 + core.preferences.newCharactersPerPost = 50 + core.preferences.newFcpFullAccessRequired = WRITING + core.preferences.newImagesPerPage = 4 + core.preferences.newFcpInterfaceActive = true + core.preferences.newRequireFullAccess = true + core.preferences.newNegativeTrust = 7 + core.preferences.newPositiveTrust = 8 + core.preferences.newPostCutOffLength = 51 + core.preferences.newPostsPerPage = 10 + core.preferences.newTrustComment = "11" } @Before @@ -271,22 +271,22 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { @Test fun `fcp interface can be set to true`() { - verifyThatPreferencesCanBeSet("fcp-interface-active", "checked", true) { core.preferences.isFcpInterfaceActive } + verifyThatPreferencesCanBeSet("fcp-interface-active", "checked", true) { core.preferences.fcpInterfaceActive } } @Test fun `fcp interface can be set to false`() { - verifyThatPreferencesCanBeSet("fcp-interface-active", null, false) { core.preferences.isFcpInterfaceActive } + verifyThatPreferencesCanBeSet("fcp-interface-active", null, false) { core.preferences.fcpInterfaceActive } } @Test fun `require full access can be set to true`() { - verifyThatPreferencesCanBeSet("require-full-access", "checked", true) { core.preferences.isRequireFullAccess } + verifyThatPreferencesCanBeSet("require-full-access", "checked", true) { core.preferences.requireFullAccess } } @Test fun `require full access can be set to false`() { - verifyThatPreferencesCanBeSet("require-full-access", null, false) { core.preferences.isRequireFullAccess } + verifyThatPreferencesCanBeSet("require-full-access", null, false) { core.preferences.requireFullAccess } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt index 2da2b24..00fa5cf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt @@ -285,7 +285,7 @@ class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(templat @Test fun `sone hits are paginated correctly`() { - core.preferences.postsPerPage = 2 + core.preferences.newPostsPerPage = 2 val sones = listOf(createSone("1Sone"), createSone("Other1"), createSone("22Sone"), createSone("333Sone"), createSone("Other2")) .onEach { addSone(it.id, it) } addHttpRequestParameter("query", "sone") @@ -297,7 +297,7 @@ class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(templat @Test fun `sone hits page 2 is shown correctly`() { - core.preferences.postsPerPage = 2 + core.preferences.newPostsPerPage = 2 val sones = listOf(createSone("1Sone"), createSone("Other1"), createSone("22Sone"), createSone("333Sone"), createSone("Other2")) .onEach { addSone(it.id, it) } addHttpRequestParameter("query", "sone") @@ -310,7 +310,7 @@ class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(templat @Test fun `post hits are paginated correctly`() { - core.preferences.postsPerPage = 2 + core.preferences.newPostsPerPage = 2 val sones = listOf(createSoneWithPost("match1", "1Sone"), createSoneWithPost("no-match1", "Other1"), createSoneWithPost("match2", "22Sone"), createSoneWithPost("match3", "333Sone"), createSoneWithPost("no-match2", "Other2")) addHttpRequestParameter("query", "sone") verifyNoRedirect { @@ -321,7 +321,7 @@ class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(templat @Test fun `post hits page 2 is shown correctly`() { - core.preferences.postsPerPage = 2 + core.preferences.newPostsPerPage = 2 val sones = listOf(createSoneWithPost("match1", "1Sone"), createSoneWithPost("no-match1", "Other1"), createSoneWithPost("match2", "22Sone"), createSoneWithPost("match3", "333Sone"), createSoneWithPost("no-match2", "Other2")) addHttpRequestParameter("query", "sone") addHttpRequestParameter("postPage", "1") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt index 7e92224..0206053 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt @@ -185,7 +185,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `page is disabled if full access is required but request does not have full access`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true assertThat(page.isEnabled(toadletContext), equalTo(false)) } @@ -202,7 +202,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `page is enabled if full access is required and request has full access and login is required and there is a current sone`() { - core.preferences.isRequireFullAccess = true + core.preferences.newRequireFullAccess = true whenever(toadletContext.isAllowedFullAccess).thenReturn(true) assertThat(page.isEnabled(toadletContext), equalTo(true)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt index ea1f528..a8e59be 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt @@ -40,7 +40,7 @@ class ViewSonePageTest: WebPageTest(::ViewSonePage) { fun setup() { whenever(currentSone.posts).thenReturn(mutableListOf(post2, post1)) whenever(core.getDirectedPosts("sone-id")).thenReturn(setOf(directed1, directed2)) - core.preferences.postsPerPage = 2 + core.preferences.newPostsPerPage = 2 } @Test -- 2.7.4