Skip to content

Commit 127274d

Browse files
committed
fix
1 parent 2f9231d commit 127274d

File tree

8 files changed

+46
-57
lines changed

8 files changed

+46
-57
lines changed

routers/common/pagetmpl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ func notificationUnreadCount(ctx *context.Context) int64 {
6565
return count
6666
}
6767

68-
type pageHeadNavbarDataType struct {
68+
type pageGlobalDataType struct {
6969
IsSigned bool
7070
IsSiteAdmin bool
7171

7272
GetNotificationUnreadCount func() int64
7373
GetActiveStopwatch func() *StopwatchTmplInfo
7474
}
7575

76-
func PageHeadNavbarData(ctx *context.Context) {
77-
var data pageHeadNavbarDataType
76+
func PageGlobalData(ctx *context.Context) {
77+
var data pageGlobalDataType
7878
data.IsSigned = ctx.Doer != nil
7979
data.IsSiteAdmin = ctx.Doer != nil && ctx.Doer.IsAdmin
8080
data.GetNotificationUnreadCount = sync.OnceValue(func() int64 { return notificationUnreadCount(ctx) })
8181
data.GetActiveStopwatch = sync.OnceValue(func() *StopwatchTmplInfo { return getActiveStopwatch(ctx) })
82-
ctx.Data["HeadNavbarData"] = data
82+
ctx.Data["PageGlobalData"] = data
8383
}

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func Routes() *web.Router {
281281
}
282282

283283
mid = append(mid, goGet)
284-
mid = append(mid, common.PageHeadNavbarData)
284+
mid = append(mid, common.PageGlobalData)
285285

286286
webRoutes := web.NewRouter()
287287
webRoutes.Use(mid...)

templates/base/head_navbar.tmpl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<!-- mobile right menu, it must be here because in mobile view, each item is a flex column, the first item is a full row column -->
99
<div class="ui secondary menu navbar-mobile-right only-mobile">
10-
{{template "base/head_navbar_icons" dict "HeadNavbarData" .HeadNavbarData}}
10+
{{template "base/head_navbar_icons" dict "PageGlobalData" .PageGlobalData}}
1111
<button class="item ui icon mini button tw-m-0" id="navbar-expand-toggle" aria-label="{{ctx.Locale.Tr "home.nav_menu"}}">{{svg "octicon-three-bars"}}</button>
1212
</div>
1313

@@ -62,7 +62,7 @@
6262
</div><!-- end content avatar menu -->
6363
</div><!-- end dropdown avatar menu -->
6464
{{else if .IsSigned}}
65-
{{template "base/head_navbar_icons" dict "ItemExtraClass" "not-mobile" "HeadNavbarData" .HeadNavbarData}}
65+
{{template "base/head_navbar_icons" dict "ItemExtraClass" "not-mobile" "PageGlobalData" .PageGlobalData}}
6666
<div class="ui dropdown jump item" data-tooltip-content="{{ctx.Locale.Tr "create_new"}}">
6767
<span class="text">
6868
{{svg "octicon-plus"}}
@@ -120,14 +120,6 @@
120120
{{svg "octicon-question"}}
121121
{{ctx.Locale.Tr "help"}}
122122
</a>
123-
{{if .IsAdmin}}
124-
<div class="divider"></div>
125-
<a class="{{if .PageIsAdmin}}active {{end}}item" href="{{AppSubUrl}}/-/admin">
126-
{{svg "octicon-server"}}
127-
{{ctx.Locale.Tr "admin_panel"}}
128-
</a>
129-
{{end}}
130-
131123
<div class="divider"></div>
132124
<a class="item link-action" href data-url="{{AppSubUrl}}/user/logout">
133125
{{svg "octicon-sign-out"}}
@@ -149,7 +141,7 @@
149141
{{end}}
150142
</div><!-- end full right menu -->
151143

152-
{{$activeStopwatch := and .HeadNavbarData (call .HeadNavbarData.GetActiveStopwatch)}}
144+
{{$activeStopwatch := and .PageGlobalData (call .PageGlobalData.GetActiveStopwatch)}}
153145
{{if $activeStopwatch}}
154146
<div class="active-stopwatch-popup tippy-target">
155147
<div class="tw-flex tw-items-center tw-gap-2 tw-p-3">

templates/base/head_navbar_icons.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $itemExtraClass := .ItemExtraClass -}}
2-
{{- $data := .HeadNavbarData -}}
3-
{{if and $data $data.IsSigned}}{{/* data may not exist, for example: rendering 503 page before the HeadNavbarData middleware */}}
2+
{{- $data := .PageGlobalData -}}
3+
{{if and $data $data.IsSigned}}{{/* data may not exist, for example: rendering 503 page before the PageGlobalData middleware */}}
44
{{- $activeStopwatch := call $data.GetActiveStopwatch -}}
55
{{- $notificationUnreadCount := call $data.GetNotificationUnreadCount -}}
66
{{if $activeStopwatch}}

templates/swagger/ui.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<body>
88
<a class="swagger-back-link" href="{{AppSubUrl}}/">{{svg "octicon-reply"}}{{ctx.Locale.Tr "return_to_gitea"}}</a>
99
<div id="swagger-ui" data-source="{{AppSubUrl}}/swagger.{{.APIJSONVersion}}.json"></div>
10+
<footer class="page-footer"></footer>
1011
<script src="{{AssetUrlPrefix}}/js/swagger.js?v={{AssetVersion}}"></script>
1112
</body>
1213
</html>

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div role="main" aria-label="{{.Title}}" class="page-content user notification" id="notification_div" data-sequence-number="{{.SequenceNumber}}">
22
<div class="ui container">
3-
{{$notificationUnreadCount := call .NotificationUnreadCount ctx}}
3+
{{$notificationUnreadCount := call .PageGlobalData.GetNotificationUnreadCount}}
44
<div class="tw-flex tw-items-center tw-justify-between tw-mb-[--page-spacing]">
55
<div class="small-menu-items ui compact tiny menu">
66
<a class="{{if eq .Status 1}}active {{end}}item" href="{{AppSubUrl}}/notifications?q=unread">

tests/integration/integration_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ func (s *TestSession) GetCookieFlashMessage() *middleware.Flash {
148148

149149
func (s *TestSession) MakeRequest(t testing.TB, rw *RequestWrapper, expectedStatus int) *httptest.ResponseRecorder {
150150
t.Helper()
151+
if s == nil {
152+
return MakeRequest(t, rw, expectedStatus)
153+
}
151154
req := rw.Request
152155
baseURL, err := url.Parse(setting.AppURL)
153156
assert.NoError(t, err)

tests/integration/links_test.go

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,48 @@ import (
1717
"github.com/stretchr/testify/assert"
1818
)
1919

20-
func TestLinksNoLogin(t *testing.T) {
20+
func assertLinkPageComplete(t *testing.T, session *TestSession, link string) {
21+
req := NewRequest(t, "GET", link)
22+
resp := session.MakeRequest(t, req, http.StatusOK)
23+
assert.True(t, test.IsNormalPageCompleted(resp.Body.String()), "Page did not complete: "+link)
24+
}
25+
26+
func TestLinks(t *testing.T) {
2127
defer tests.PrepareTestEnv(t)()
2228

29+
t.Run("NoLogin", testLinksNoLogin)
30+
t.Run("RedirectsNoLogin", testLinksRedirectsNoLogin)
31+
t.Run("NoLoginNotExist", testLinksNoLoginNotExist)
32+
t.Run("AsUser", testLinksAsUser)
33+
t.Run("RepoCommon", testLinksRepoCommon)
34+
}
35+
36+
func testLinksNoLogin(t *testing.T) {
2337
links := []string{
38+
"/",
2439
"/explore/repos",
2540
"/explore/repos?q=test",
2641
"/explore/users",
2742
"/explore/users?q=test",
2843
"/explore/organizations",
2944
"/explore/organizations?q=test",
30-
"/",
3145
"/user/sign_up",
3246
"/user/login",
3347
"/user/forgot_password",
34-
"/api/swagger",
3548
"/user2/repo1",
3649
"/user2/repo1/",
3750
"/user2/repo1/projects",
3851
"/user2/repo1/projects/1",
3952
"/user2/repo1/releases/tag/delete-tag", // It's the only one existing record on release.yml which has is_tag: true
40-
"/.well-known/security.txt",
53+
"/api/swagger",
4154
}
42-
4355
for _, link := range links {
44-
req := NewRequest(t, "GET", link)
45-
MakeRequest(t, req, http.StatusOK)
56+
assertLinkPageComplete(t, nil, link)
4657
}
58+
MakeRequest(t, NewRequest(t, "GET", "/.well-known/security.txt"), http.StatusOK)
4759
}
4860

49-
func TestRedirectsNoLogin(t *testing.T) {
50-
defer tests.PrepareTestEnv(t)()
51-
61+
func testLinksRedirectsNoLogin(t *testing.T) {
5262
redirects := []struct{ from, to string }{
5363
{"/user2/repo1/commits/master", "/user2/repo1/commits/branch/master"},
5464
{"/user2/repo1/src/master", "/user2/repo1/src/branch/master"},
@@ -68,9 +78,7 @@ func TestRedirectsNoLogin(t *testing.T) {
6878
}
6979
}
7080

71-
func TestNoLoginNotExist(t *testing.T) {
72-
defer tests.PrepareTestEnv(t)()
73-
81+
func testLinksNoLoginNotExist(t *testing.T) {
7482
links := []string{
7583
"/user5/repo4/projects",
7684
"/user5/repo4/projects/3",
@@ -82,7 +90,8 @@ func TestNoLoginNotExist(t *testing.T) {
8290
}
8391
}
8492

85-
func testLinksAsUser(userName string, t *testing.T) {
93+
func testLinksAsUser(t *testing.T) {
94+
session := loginUser(t, "user2")
8695
links := []string{
8796
"/explore/repos",
8897
"/explore/repos?q=test",
@@ -130,18 +139,14 @@ func testLinksAsUser(userName string, t *testing.T) {
130139
"/user/settings/repos",
131140
}
132141

133-
session := loginUser(t, userName)
134142
for _, link := range links {
135-
req := NewRequest(t, "GET", link)
136-
session.MakeRequest(t, req, http.StatusOK)
143+
assertLinkPageComplete(t, session, link)
137144
}
138145

139-
reqAPI := NewRequestf(t, "GET", "/api/v1/users/%s/repos", userName)
146+
reqAPI := NewRequestf(t, "GET", "/api/v1/users/user2/repos")
140147
respAPI := MakeRequest(t, reqAPI, http.StatusOK)
141-
142148
var apiRepos []*api.Repository
143149
DecodeJSON(t, respAPI, &apiRepos)
144-
145150
repoLinks := []string{
146151
"",
147152
"/issues",
@@ -164,24 +169,15 @@ func testLinksAsUser(userName string, t *testing.T) {
164169
"/wiki/?action=_new",
165170
"/activity",
166171
}
167-
168172
for _, repo := range apiRepos {
169173
for _, link := range repoLinks {
170-
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s%s", userName, repo.Name, link))
171-
session.MakeRequest(t, req, http.StatusOK)
174+
link = fmt.Sprintf("/user2/%s%s", repo.Name, link)
175+
assertLinkPageComplete(t, session, link)
172176
}
173177
}
174178
}
175179

176-
func TestLinksLogin(t *testing.T) {
177-
defer tests.PrepareTestEnv(t)()
178-
179-
testLinksAsUser("user2", t)
180-
}
181-
182-
func TestRepoLinks(t *testing.T) {
183-
defer tests.PrepareTestEnv(t)()
184-
180+
func testLinksRepoCommon(t *testing.T) {
185181
// repo1 has enabled almost features, so we can test most links
186182
repoLink := "/user2/repo1"
187183
links := []string{
@@ -192,21 +188,18 @@ func TestRepoLinks(t *testing.T) {
192188

193189
// anonymous user
194190
for _, link := range links {
195-
req := NewRequest(t, "GET", repoLink+link)
196-
MakeRequest(t, req, http.StatusOK)
191+
assertLinkPageComplete(t, nil, repoLink+link)
197192
}
198193

199194
// admin/owner user
200195
session := loginUser(t, "user1")
201196
for _, link := range links {
202-
req := NewRequest(t, "GET", repoLink+link)
203-
session.MakeRequest(t, req, http.StatusOK)
197+
assertLinkPageComplete(t, session, repoLink+link)
204198
}
205199

206200
// non-admin non-owner user
207201
session = loginUser(t, "user2")
208202
for _, link := range links {
209-
req := NewRequest(t, "GET", repoLink+link)
210-
session.MakeRequest(t, req, http.StatusOK)
203+
assertLinkPageComplete(t, session, repoLink+link)
211204
}
212205
}

0 commit comments

Comments
 (0)