From 51caba694af5967056239055953cbdc96bd7f6cc Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 30 Mar 2025 05:04:36 +0000 Subject: [PATCH] fix(ui): prepend AppSubURL to visibility hint URLs (#7379) - If configured, add `AppSubUrl` to the visibility hint URLs shown to the user on the profile activity page. - Resolves https://codeberg.org/forgejo/forgejo/issues/7327 - Integration testing adjusted. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7379 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Gusted Co-committed-by: Gusted --- templates/user/profile.tmpl | 6 +++--- tests/integration/user_profile_activity_test.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 1f39576ac2..1d62f3eea9 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -12,12 +12,12 @@ {{if eq .SignedUserID .ContextUser.ID}}

{{if .ContextUser.KeepActivityPrivate}} - {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private" "/user/settings#keep-activity-private"}} + {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private" (print AppSubUrl "/user/settings#keep-activity-private")}} {{else}} {{if eq .ContextUser.Visibility 2}} - {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private_profile" "/user/settings#visibility-setting"}} + {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private_profile" (print AppSubUrl "/user/settings#visibility-setting")}} {{else}} - {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_public" "/user/settings#keep-activity-private"}} + {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_public" (print AppSubUrl "/user/settings#keep-activity-private")}} {{end}} {{end}}

diff --git a/tests/integration/user_profile_activity_test.go b/tests/integration/user_profile_activity_test.go index 26563fe2db..47a8df94b2 100644 --- a/tests/integration/user_profile_activity_test.go +++ b/tests/integration/user_profile_activity_test.go @@ -8,7 +8,9 @@ import ( "strconv" "testing" + "forgejo.org/modules/setting" "forgejo.org/modules/structs" + "forgejo.org/modules/test" "forgejo.org/tests" "github.com/stretchr/testify/assert" @@ -23,6 +25,7 @@ import ( // - Profile visibility // - Public activity visibility func TestUserProfileActivity(t *testing.T) { + defer test.MockVariableValue(&setting.AppSubURL, "/sub")() defer tests.PrepareTestEnv(t)() // This test needs multiple users with different access statuses to check for all possible states userAdmin := loginUser(t, "user1") @@ -52,7 +55,7 @@ func TestUserProfileActivity(t *testing.T) { // When profile activity is configured as public, but the profile is private, tell the user about this and link to visibility settings. hintLink := testUser2ActivityVisibility(t, userRegular, "Your activity is only visible to you and the instance administrators because your profile is private. Configure.", true) - assert.Equal(t, "/user/settings#visibility-setting", hintLink) + assert.Equal(t, "/sub/user/settings#visibility-setting", hintLink) // When the profile is private, tell the admin about this. testUser2ActivityVisibility(t, userAdmin, "This activity is visible to you because you're an administrator, but the user wants it to remain private.", true) @@ -76,7 +79,7 @@ func TestUserProfileActivity(t *testing.T) { testUser2ActivityVisibility(t, userGuest, "This user has disabled the public visibility of the activity.", false) // Verify that Configure link is correct - assert.Equal(t, "/user/settings#keep-activity-private", hintLink) + assert.Equal(t, "/sub/user/settings#keep-activity-private", hintLink) } // testChangeUserActivityVisibility allows to easily change visibility of public activity for a user @@ -112,11 +115,11 @@ func testUser2ActivityVisibility(t *testing.T, session *TestSession, hint string assert.Equal(t, availability, page.Find("#activity-feed").Length() > 0) // Check availability of RSS feed button too - assert.Equal(t, availability, page.Find("#profile-avatar-card a[href='/user2.rss']").Length() > 0) + assert.Equal(t, availability, page.Find("#profile-avatar-card a[href='/sub/user2.rss']").Length() > 0) // Check that the current tab is displayed and is active regardless of it's actual availability // For example, on / it wouldn't be available to guest, but it should be still present on /?tab=activity - assert.Positive(t, page.Find("overflow-menu .active.item[href='/user2?tab=activity']").Length()) + assert.Positive(t, page.Find("overflow-menu .active.item[href='/sub/user2?tab=activity']").Length()) if hintLinkExists { return hintLink } @@ -128,5 +131,5 @@ func testUser2ActivityButtonsAvailability(t *testing.T, session *TestSession, bu t.Helper() response := session.MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK) page := NewHTMLParser(t, response.Body) - assert.Equal(t, buttons, page.Find("overflow-menu .item[href='/user2?tab=activity']").Length() > 0) + assert.Equal(t, buttons, page.Find("overflow-menu .item[href='/sub/user2?tab=activity']").Length() > 0) }