mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-07-12 20:48:40 +00:00
fix(ui): bring back non-empty check to ThemeName (#13175)
Followup to https://codeberg.org/forgejo/forgejo/pulls/13110, which introduced a regression.
`SignedUser` is not guaranteed to be nil for guest users. Instead, we're setting it to non-nil user with ID 0 in some places, like:
e7c45cd9c8/services/context/org.go (L168-L171)
In https://codeberg.org/forgejo/forgejo/pulls/13110, I removed the check assuming it was for handling cases where real user's theme is set to "", after making sure it can't happen. This broke display of org pages to guest users and no tests caught it.
This unreliability of `SignedUser` doesn't seem ideal but I've assessed my chances of improving this without introducing more regressions as low, so I just brought the check back.
Noticed on v16.next. Demonstration:

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13175
Reviewed-by: Robert Wolff <mahlzahn@posteo.de>
This commit is contained in:
parent
e7c45cd9c8
commit
b4c8a8dbb2
2 changed files with 11 additions and 1 deletions
|
|
@ -173,7 +173,8 @@ func NewFuncMap() template.FuncMap {
|
|||
return !setting.ImportLocalPaths
|
||||
},
|
||||
"ThemeName": func(user *user_model.User) string {
|
||||
if user == nil {
|
||||
// Guest user may not be nil on some pages, e.g. in org pages, so user.Theme check is also needed
|
||||
if user == nil || user.Theme == "" {
|
||||
return setting.UI.DefaultTheme
|
||||
}
|
||||
return user.Theme
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
|
@ -54,6 +55,14 @@ func TestOrgRepos(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPublicOrgHome(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// Verify that in org pages, default theme get properly assigned to guest users
|
||||
page := NewHTMLParser(t, MakeRequest(t, NewRequest(t, "GET", "/org41"), http.StatusOK).Body)
|
||||
page.AssertElement(t, "html head link[rel='stylesheet'][href^='/assets/css/theme-forgejo-auto.css']", true)
|
||||
}
|
||||
|
||||
func TestLimitedOrg(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue