From 9abb95a8441e227874fe156095349a3173cc5a81 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 27 Aug 2023 14:29:18 +0200 Subject: [PATCH] [MODERATION] Fix network error (squash) - Fix network error toast messages on user actions such as follow and unfollow. This happened because the javascript code now expects an JSON to be returned, but this wasn't the case due to cfa539e590127b4953b010fba3dea21c82a1714. - The integration testing has been adjusted to instead test for the returned flash cookie. (cherry picked from commit 112bc25e548d317a4ee00f9efa9068794a733e3b) (cherry picked from commit 1194fe4899eb39dcb9a2410032ad0cc67a62b92b) --- routers/web/user/profile.go | 2 +- tests/integration/block_test.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index c20af0c83c..a88562b895 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -333,5 +333,5 @@ func Action(ctx *context.Context) { }) return } - ctx.RedirectToFirst(ctx.FormString("redirect_to"), ctx.ContextUser.HomeLink()) + ctx.JSONOK() } diff --git a/tests/integration/block_test.go b/tests/integration/block_test.go index 926ca46905..fee6d4b6f9 100644 --- a/tests/integration/block_test.go +++ b/tests/integration/block_test.go @@ -65,10 +65,8 @@ func TestBlockUser(t *testing.T) { "_csrf": GetCSRF(t, session, "/"+blockedUser.Name), "action": "unblock", }) - resp := session.MakeRequest(t, req, http.StatusSeeOther) + session.MakeRequest(t, req, http.StatusOK) - loc := resp.Header().Get("Location") - assert.EqualValues(t, "/"+blockedUser.Name, loc) unittest.AssertNotExistsBean(t, &user_model.BlockedUser{BlockID: blockedUser.ID, UserID: doer.ID}) }) @@ -296,7 +294,11 @@ func TestBlockActions(t *testing.T) { "_csrf": GetCSRF(t, session, "/"+blockedUser.Name), "action": "follow", }) - session.MakeRequest(t, req, http.StatusSeeOther) + session.MakeRequest(t, req, http.StatusOK) + + flashCookie := session.GetCookie(forgejo_context.CookieNameFlash) + assert.NotNil(t, flashCookie) + assert.EqualValues(t, "error%3DYou%2Bcannot%2Bfollow%2Bthis%2Buser%2Bbecause%2Byou%2Bhave%2Bblocked%2Bthis%2Buser%2Bor%2Bthis%2Buser%2Bhas%2Bblocked%2Byou.", flashCookie.Value) // Assert it still doesn't exist. unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: doer.ID, FollowID: blockedUser.ID}) @@ -312,7 +314,11 @@ func TestBlockActions(t *testing.T) { "_csrf": GetCSRF(t, session, "/"+doer.Name), "action": "follow", }) - session.MakeRequest(t, req, http.StatusSeeOther) + session.MakeRequest(t, req, http.StatusOK) + + flashCookie := session.GetCookie(forgejo_context.CookieNameFlash) + assert.NotNil(t, flashCookie) + assert.EqualValues(t, "error%3DYou%2Bcannot%2Bfollow%2Bthis%2Buser%2Bbecause%2Byou%2Bhave%2Bblocked%2Bthis%2Buser%2Bor%2Bthis%2Buser%2Bhas%2Bblocked%2Byou.", flashCookie.Value) unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: blockedUser.ID, FollowID: doer.ID}) })