@Inject lateinit var deleteReplyPage: DeleteReplyPage
@Inject lateinit var deleteSonePage: DeleteSonePage
@Inject lateinit var dismissNotificationPage: DismissNotificationPage
- @Inject lateinit var distrustPage: DistrustPage
@Inject lateinit var editAlbumPage: EditAlbumPage
@Inject lateinit var editImagePage: EditImagePage
@Inject lateinit var editProfileFieldPage: EditProfileFieldPage
@Inject lateinit var optionsPage: OptionsPage
@Inject lateinit var rescuePage: RescuePage
@Inject lateinit var searchPage: SearchPage
- @Inject lateinit var trustPage: TrustPage
@Inject lateinit var unbookmarkPage: UnbookmarkPage
@Inject lateinit var unfollowSonePage: UnfollowSonePage
@Inject lateinit var unlikePage: UnlikePage
@Inject lateinit var unlockSonePage: UnlockSonePage
- @Inject lateinit var untrustPage: UntrustPage
@Inject lateinit var uploadImagePage: UploadImagePage
@Inject lateinit var viewPostPage: ViewPostPage
@Inject lateinit var viewSonePage: ViewSonePage
import net.pterodactylus.sone.web.ajax.DeleteProfileFieldAjaxPage;
import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
-import net.pterodactylus.sone.web.ajax.DistrustAjaxPage;
import net.pterodactylus.sone.web.ajax.EditAlbumAjaxPage;
import net.pterodactylus.sone.web.ajax.EditImageAjaxPage;
import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage;
import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
import net.pterodactylus.sone.web.ajax.MarkAsKnownAjaxPage;
import net.pterodactylus.sone.web.ajax.MoveProfileFieldAjaxPage;
-import net.pterodactylus.sone.web.ajax.TrustAjaxPage;
import net.pterodactylus.sone.web.ajax.UnbookmarkAjaxPage;
import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
-import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.page.TemplateRenderer;
import net.pterodactylus.sone.web.pages.*;
pageToadletRegistry.addPage(new UploadImagePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new EditImagePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new DeleteImagePage(this, loaders, templateRenderer));
- pageToadletRegistry.addPage(new TrustPage(this, loaders, templateRenderer));
- pageToadletRegistry.addPage(new DistrustPage(this, loaders, templateRenderer));
- pageToadletRegistry.addPage(new UntrustPage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new MarkAsKnownPage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new BookmarkPage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new UnbookmarkPage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new UnfollowSoneAjaxPage(this));
pageToadletRegistry.addPage(new EditAlbumAjaxPage(this));
pageToadletRegistry.addPage(new EditImageAjaxPage(this, parserFilter, shortenFilter, renderFilter));
- pageToadletRegistry.addPage(new TrustAjaxPage(this));
- pageToadletRegistry.addPage(new DistrustAjaxPage(this));
- pageToadletRegistry.addPage(new UntrustAjaxPage(this));
pageToadletRegistry.addPage(new LikeAjaxPage(this));
pageToadletRegistry.addPage(new UnlikeAjaxPage(this));
pageToadletRegistry.addPage(new GetLikesAjaxPage(this));
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.core.*
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.utils.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.sone.web.page.*
-import javax.inject.*
-
-/**
- * AJAX page that lets the user distrust a Sone.
- *
- * @see Core.distrustSone(Sone, Sone)
- */
-@ToadletPath("distrustSone.ajax")
-class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
-
- override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
- request.parameters["sone"]
- ?.let(core::getSone)
- ?.let { sone ->
- createSuccessJsonObject()
- .put("trustValue", core.preferences.negativeTrust)
- .also {
- core.distrustSone(currentSone, sone)
- }
- } ?: createErrorJsonObject("invalid-sone-id")
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.utils.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.sone.web.page.*
-import javax.inject.*
-
-/**
- * AJAX page that lets the user trust a Sone.
- *
- * @see net.pterodactylus.sone.core.Core.trustSone
- */
-@ToadletPath("trustSone.ajax")
-class TrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
-
- override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
- request.parameters["sone"]
- ?.let(core::getSone)
- ?.let { core.trustSone(currentSone, it) }
- ?.let { createSuccessJsonObject().put("trustValue", core.preferences.positiveTrust) }
- ?: createErrorJsonObject("invalid-sone-id")
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.data.Sone
-import net.pterodactylus.sone.utils.parameters
-import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.*
-import javax.inject.Inject
-
-/**
- * AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone].
- */
-@ToadletPath("untrustSone.ajax")
-class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
-
- override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
- request.parameters["sone"]
- ?.let(core::getSone)
- ?.also { core.untrustSone(currentSone, it) }
- ?.let { createSuccessJsonObject() }
- ?: createErrorJsonObject("invalid-sone-id")
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.main.*
-import net.pterodactylus.sone.utils.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.sone.web.page.*
-import net.pterodactylus.util.template.*
-import javax.inject.*
-
-/**
- * Page that lets the user distrust another Sone. This will assign a
- * configurable (negative) amount of trust to an identity.
- *
- * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone)
- */
-@ToadletPath("distrust.html")
-class DistrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
- LoggedInPage("Page.Distrust.Title", webInterface, loaders, templateRenderer) {
-
- override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (soneRequest.isPOST) {
- soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("sone", 44))
- ?.run { soneRequest.core.distrustSone(currentSone, this) }
- redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
- }
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.main.*
-import net.pterodactylus.sone.utils.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.sone.web.page.*
-import net.pterodactylus.util.template.*
-import javax.inject.*
-
-/**
- * Page that lets the user trust another Sone. This will assign a configurable
- * amount of trust to an identity.
- */
-@ToadletPath("trust.html")
-class TrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
- LoggedInPage("Page.Trust.Title", webInterface, loaders, templateRenderer) {
-
- override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (soneRequest.isPOST) {
- soneRequest.core.getSone(soneRequest.parameters["sone"]!!)?.let { sone ->
- soneRequest.core.trustSone(currentSone, sone)
- }
- redirectTo(soneRequest.parameters["returnPage", 256])
- }
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.main.*
-import net.pterodactylus.sone.utils.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.sone.web.page.*
-import net.pterodactylus.util.template.*
-import javax.inject.*
-
-/**
- * Page that lets the user untrust another Sone. This will remove all trust
- * assignments for an identity.
- */
-@ToadletPath("untrust.html")
-class UntrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
- LoggedInPage("Page.Untrust.Title", webInterface, loaders, templateRenderer) {
-
- override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (soneRequest.isPOST) {
- soneRequest.parameters["sone", 44]!!
- .let(soneRequest.core::getSone)
- ?.also { soneRequest.core.untrustSone(currentSone, it) }
- redirectTo(soneRequest.parameters["returnPage", 256])
- }
- }
-
-}
}
@Test
- fun `distrust page can be injected`() {
- assertThat(allPages.distrustPage, instanceOf<DistrustPage>())
- }
-
- @Test
fun `edit album page can be injected`() {
assertThat(allPages.editAlbumPage, instanceOf<EditAlbumPage>())
}
}
@Test
- fun `trust page can be injected`() {
- assertThat(allPages.trustPage, instanceOf<TrustPage>())
- }
-
- @Test
fun `unbookmark page can be injected`() {
assertThat(allPages.unbookmarkPage, instanceOf<UnbookmarkPage>())
}
}
@Test
- fun `untrust page can be injected`() {
- assertThat(allPages.untrustPage, instanceOf<UntrustPage>())
- }
-
- @Test
fun `upload image page can be injected`() {
assertThat(allPages.uploadImagePage, instanceOf<UploadImagePage>())
}
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.data.Sone
-import net.pterodactylus.sone.test.getInstance
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.baseInjector
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.junit.Test
-import org.mockito.Mockito.verify
-
-/**
- * Unit test for [DistrustAjaxPage].
- */
-class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::DistrustAjaxPage) {
-
- @Test
- fun `request with missing sone results in invalid-sone-id`() {
- assertThatJsonFailed("invalid-sone-id")
- }
-
- @Test
- fun `request with invalid sone results in invalid-sone-id`() {
- addRequestParameter("sone", "invalid-sone")
- assertThatJsonFailed("invalid-sone-id")
- }
-
- @Test
- fun `request with valid sone results in distrusted sone`() {
- val sone = mock<Sone>()
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- assertThatJsonIsSuccessful()
- verify(core).distrustSone(currentSone, sone)
- }
-
- @Test
- fun `request with valid sone results in correct trust value being sent back`() {
- core.preferences.newNegativeTrust = -33
- val sone = mock<Sone>()
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- assertThatJsonIsSuccessful()
- assertThat(json["trustValue"]?.asInt(), equalTo(-33))
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<DistrustAjaxPage>(), notNullValue())
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.data.Sone
-import net.pterodactylus.sone.test.getInstance
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.baseInjector
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.junit.Test
-import org.mockito.Mockito.verify
-
-/**
- * Unit test for [TrustAjaxPage].
- */
-class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, needsFormPassword = true, pageSupplier = ::TrustAjaxPage) {
-
- private val sone = mock<Sone>()
-
- @Test
- fun `request with invalid sone results in invalid-sone-id`() {
- assertThatJsonFailed("invalid-sone-id")
- }
-
- @Test
- fun `request with valid sone trust sone`() {
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- assertThatJsonIsSuccessful()
- verify(core).trustSone(currentSone, sone)
- }
-
- @Test
- fun `request with valid sone returns positive trust value`() {
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- core.preferences.newPositiveTrust = 31
- assertThatJsonIsSuccessful()
- assertThat(json["trustValue"]?.asInt(), equalTo(31))
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<TrustAjaxPage>(), notNullValue())
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.ajax
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.test.*
-import net.pterodactylus.sone.web.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import org.mockito.Mockito.*
-
-/**
- * Unit test for [UntrustAjaxPage].
- */
-class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::UntrustAjaxPage) {
-
- @Test
- fun `request without sone results in invalid-sone-id`() {
- assertThatJsonFailed("invalid-sone-id")
- }
-
- @Test
- fun `request with invalid sone results in invalid-sone-id`() {
- addRequestParameter("sone", "invalid")
- assertThatJsonFailed("invalid-sone-id")
- }
-
- @Test
- fun `request with valid sone results in sone being untrusted`() {
- val sone = mock<Sone>()
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- assertThatJsonIsSuccessful()
- verify(core).untrustSone(currentSone, sone)
- }
-
- @Test
- fun `request with valid sone results in null trust value being returned`() {
- val sone = mock<Sone>()
- addSone(sone, "sone-id")
- addRequestParameter("sone", "sone-id")
- assertThatJsonIsSuccessful()
- assertThat(json["trustValue"], nullValue())
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<UntrustAjaxPage>(), notNullValue())
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.test.*
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.util.web.Method.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import org.mockito.Mockito.*
-
-/**
- * Unit test for [DistrustPage].
- */
-class DistrustPageTest : WebPageTest(::DistrustPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("distrust.html"))
- }
-
- @Test
- fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
- }
-
- @Test
- fun `page returns correct title`() {
- addTranslation("Page.Distrust.Title", "distrust page title")
- assertThat(page.getPageTitle(soneRequest), equalTo("distrust page title"))
- }
-
- @Test
- fun `get request does not redirect`() {
- page.processTemplate(freenetRequest, templateContext)
- }
-
- @Test
- fun `post request with invalid sone redirects to return page`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- verifyRedirect("return.html")
- }
-
- @Test
- fun `post request with valid sone distrusts sone and redirects to return page`() {
- setMethod(POST)
- val remoteSone = mock<Sone>()
- addSone("remote-sone-id", remoteSone)
- addHttpRequestPart("returnPage", "return.html")
- addHttpRequestPart("sone", "remote-sone-id")
- verifyRedirect("return.html") {
- verify(core).distrustSone(currentSone, remoteSone)
- }
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<DistrustPage>(), notNullValue())
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.test.getInstance
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.util.web.Method.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.eq
-import org.mockito.Mockito.never
-import org.mockito.Mockito.verify
-
-/**
- * Unit test for [TrustPage].
- */
-class TrustPageTest : WebPageTest(::TrustPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("trust.html"))
- }
-
- @Test
- fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
- }
-
- @Test
- fun `page returns correct title`() {
- addTranslation("Page.Trust.Title", "title trust page")
- assertThat(page.getPageTitle(soneRequest), equalTo("title trust page"))
- }
-
- @Test
- fun `get method does not redirect`() {
- verifyNoRedirect { }
- }
-
- @Test
- fun `post request without sone redirects to return page`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- verifyRedirect("return.html") {
- verify(core, never()).trustSone(eq(currentSone), any())
- }
- }
-
- @Test
- fun `post request with missing sone redirects to return page`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- addHttpRequestPart("sone", "sone-id")
- verifyRedirect("return.html") {
- verify(core, never()).trustSone(eq(currentSone), any())
- }
- }
-
- @Test
- fun `post request with existing sone trusts the identity and redirects to return page`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- addHttpRequestPart("sone", "sone-id")
- val sone = mock<Sone>()
- addSone("sone-id", sone)
- verifyRedirect("return.html") {
- verify(core).trustSone(eq(currentSone), eq(sone))
- }
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<TrustPage>(), notNullValue())
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.web.pages
-
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.test.getInstance
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.*
-import net.pterodactylus.util.web.Method.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.eq
-import org.mockito.Mockito.never
-import org.mockito.Mockito.verify
-
-/**
- * Unit test for [UntrustPage].
- */
-class UntrustPageTest : WebPageTest(::UntrustPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("untrust.html"))
- }
-
- @Test
- fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
- }
-
- @Test
- fun `page returns correct title`() {
- addTranslation("Page.Untrust.Title", "untrust page title")
- assertThat(page.getPageTitle(soneRequest), equalTo("untrust page title"))
- }
-
- @Test
- fun `get request does not redirect`() {
- verifyNoRedirect {
- verify(core, never()).untrustSone(eq(currentSone), any())
- }
- }
-
- @Test
- fun `post request without sone parameter does not untrust but redirects`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- verifyRedirect("return.html") {
- verify(core, never()).untrustSone(eq(currentSone), any())
- }
- }
-
- @Test
- fun `post request with invalid sone parameter does not untrust but redirects`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- addHttpRequestPart("sone", "no-sone")
- verifyRedirect("return.html") {
- verify(core, never()).untrustSone(eq(currentSone), any())
- }
- }
-
- @Test
- fun `post request with valid sone parameter untrusts and redirects`() {
- setMethod(POST)
- addHttpRequestPart("returnPage", "return.html")
- addHttpRequestPart("sone", "sone-id")
- val sone = mock<Sone>()
- addSone("sone-id", sone)
- verifyRedirect("return.html") {
- verify(core).untrustSone(currentSone, sone)
- }
- }
-
- @Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<UntrustPage>(), notNullValue())
- }
-
-}