loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(ui): better activity messages for cases of private profiles (#5638)

* added a message for the case where the user's profile is private but the Public activity is not hidden
The activity is still hidden anyway because the profile is private, but previously the message would say:
`Your activity is visible to everyone, except for interactions in private spaces...`
which I would consider as a flaw of the original implementation. Now it will say:
`Your activity is only visible to you and the instance administrators because your profile is private...`
* started showing the message for admins that the activity they see should remain private in the case
where the whole profile is private, not just the activity tab. Previously it would say:
This activity is visible to everyone, but as an administrator you can also see interactions in private spaces.`
which I would also consider as a flaw of the original implementation. Now it will say:
`This activity is visible to you because you're an administrator, but the user wants it to remain private.`
* added test cases
* bumped up the number of our GPL-licensed files

Preview
For both screenshots, Forgejo would previously display misinformation.

Change 1: User viewing their private profile, but activity isn't configured as hidden
https://codeberg.org/attachments/6659c80c-15dd-48be-a379-db737fd1dd5e

Change 2: Admin viewing user's private profile
https://codeberg.org/attachments/220da57f-b658-4474-9ad2-049e8438a0af

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5638
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

0ko 3e1d5cc4 f298bf12

+41 -6
+1
options/locale/locale_en-US.ini
··· 712 712 public_activity.visibility_hint.admin_public = This activity is visible to everyone, but as an administrator you can also see interactions in private spaces. 713 713 public_activity.visibility_hint.self_private = Your activity is only visible to you and the instance administrators. <a href="%s">Configure</a>. 714 714 public_activity.visibility_hint.admin_private = This activity is visible to you because you're an administrator, but the user wants it to remain private. 715 + public_activity.visibility_hint.self_private_profile = Your activity is only visible to you and the instance administrators because your profile is private. <a href="%s">Configure</a>. 715 716 716 717 form.name_reserved = The username "%s" is reserved. 717 718 form.name_pattern_not_allowed = The pattern "%s" is not allowed in a username.
+6 -2
templates/user/profile.tmpl
··· 14 14 {{if .ContextUser.KeepActivityPrivate}} 15 15 {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private" "/user/settings#keep-activity-private"}} 16 16 {{else}} 17 - {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_public" "/user/settings#keep-activity-private"}} 17 + {{if eq .ContextUser.Visibility 2}} 18 + {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_private_profile" "/user/settings#visibility-setting"}} 19 + {{else}} 20 + {{ctx.Locale.Tr "user.public_activity.visibility_hint.self_public" "/user/settings#keep-activity-private"}} 21 + {{end}} 18 22 {{end}} 19 23 </p> 20 24 {{else}} 21 25 {{if .IsAdmin}} 22 26 <div id="visibility-hint" class="ui info message"> 23 - {{if .ContextUser.KeepActivityPrivate}} 27 + {{if or .ContextUser.KeepActivityPrivate (eq .ContextUser.Visibility 2)}} 24 28 {{ctx.Locale.Tr "user.public_activity.visibility_hint.admin_private"}} 25 29 {{else}} 26 30 {{ctx.Locale.Tr "user.public_activity.visibility_hint.admin_public"}}
+1 -1
templates/user/settings/profile.tmpl
··· 76 76 </div> 77 77 78 78 <div class="inline field {{if .Err_Visibility}}error{{end}}"> 79 - <span class="inline required field"><label>{{ctx.Locale.Tr "settings.visibility"}}</label></span> 79 + <span class="inline required field" id="visibility-setting"><label>{{ctx.Locale.Tr "settings.visibility"}}</label></span> 80 80 <div class="ui selection type dropdown"> 81 81 {{if .SignedUser.Visibility.IsPublic}}<input type="hidden" id="visibility" name="visibility" value="0">{{end}} 82 82 {{if .SignedUser.Visibility.IsLimited}}<input type="hidden" id="visibility" name="visibility" value="1">{{end}}
+33 -3
tests/integration/user_profile_activity_test.go
··· 1 1 // Copyright 2024 The Forgejo Authors. All rights reserved. 2 - // SPDX-License-Identifier: MIT 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 3 4 4 package integration 5 5 6 6 import ( 7 7 "net/http" 8 8 "net/url" 9 + "strconv" 9 10 "testing" 11 + 12 + "code.gitea.io/gitea/modules/structs" 10 13 11 14 "github.com/stretchr/testify/assert" 12 15 ) ··· 16 19 // - Public activity tab 17 20 // - Banner/hint in the tab 18 21 // - "Configure" link in the hint 22 + // These elements might depend on the following: 23 + // - Profile visibility 24 + // - Public activity visibility 19 25 func TestUserProfileActivity(t *testing.T) { 20 26 onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 21 27 // This test needs multiple users with different access statuses to check for all possible states ··· 24 30 // Activity availability should be the same for guest and another non-admin user, so this is not tested separately 25 31 userGuest := emptyTestSession(t) 26 32 27 - // = Public = 33 + // = Public profile, public activity = 28 34 29 35 // Set activity visibility of user2 to public. This is the default, but won't hurt to set it before testing. 30 36 testChangeUserActivityVisibility(t, userRegular, "off") ··· 48 54 assert.EqualValues(t, "/user2?tab=activity", activityLink) 49 55 } 50 56 51 - // = Private = 57 + // = Private profile, but public activity = 58 + 59 + // Set profile visibility of user2 to private 60 + testChangeUserProfileVisibility(t, userRegular, structs.VisibleTypePrivate) 61 + 62 + // When profile activity is configured as public, but the profile is private, tell the user about this and link to visibility settings. 63 + hintLink = testUser2ActivityVisibility(t, userRegular, "Your activity is only visible to you and the instance administrators because your profile is private. Configure.", true) 64 + assert.EqualValues(t, "/user/settings#visibility-setting", hintLink) 65 + 66 + // When the profile is private, tell the admin about this. 67 + testUser2ActivityVisibility(t, userAdmin, "This activity is visible to you because you're an administrator, but the user wants it to remain private.", true) 68 + 69 + // Set profile visibility of user2 back to public 70 + testChangeUserProfileVisibility(t, userRegular, structs.VisibleTypePublic) 71 + 72 + // = Private acitivty = 52 73 53 74 // Set activity visibility of user2 to private 54 75 testChangeUserActivityVisibility(t, userRegular, "on") ··· 76 97 "_csrf": GetCSRF(t, session, "/user/settings"), 77 98 "keep_activity_private": newState, 78 99 }), http.StatusSeeOther) 100 + } 101 + 102 + // testChangeUserProfileVisibility allows to easily change visibility of user's profile 103 + func testChangeUserProfileVisibility(t *testing.T, session *TestSession, newValue structs.VisibleType) { 104 + t.Helper() 105 + session.MakeRequest(t, NewRequestWithValues(t, "POST", "/user/settings", map[string]string{ 106 + "_csrf": GetCSRF(t, session, "/user/settings"), 107 + "visibility": strconv.Itoa(int(newValue)), 108 + }), http.StatusSeeOther) 79 109 } 80 110 81 111 // testUser2ActivityVisibility checks visibility of UI elements on /<user>?tab=activity