Skip to content

Commit f58f5bb

Browse files
authored
Avoid duplicate SetContextValue call (#33564)
And fix FIXME and TODO
1 parent 06f1065 commit f58f5bb

File tree

6 files changed

+3
-7
lines changed

6 files changed

+3
-7
lines changed

routers/install/install.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func Contexter() func(next http.Handler) http.Handler {
6464
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
6565
base := context.NewBaseContext(resp, req)
6666
ctx := context.NewWebContext(base, rnd, session.GetSession(req))
67-
ctx.SetContextValue(context.WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
6867
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
6968
ctx.Data.MergeFrom(reqctx.ContextData{
7069
"Title": ctx.Locale.Tr("install.install"),

routers/private/internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func Routes() *web.Router {
8787
// FIXME: it is not right to use context.Contexter here because all routes here should use PrivateContext
8888
// Fortunately, the LFS handlers are able to handle requests without a complete web context
8989
common.AddOwnerRepoGitLFSRoutes(r, func(ctx *context.PrivateContext) {
90-
webContext := &context.Context{Base: ctx.Base}
90+
webContext := &context.Context{Base: ctx.Base} // see above, it shouldn't manually construct the web context
9191
ctx.SetContextValue(context.WebContextKey, webContext) // FIXME: this is not ideal but no other way at the moment
9292
})
9393
})

services/context/context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ func Contexter() func(next http.Handler) http.Handler {
166166
ctx.PageData = map[string]any{}
167167
ctx.Data["PageData"] = ctx.PageData
168168

169-
ctx.Base.SetContextValue(WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
170169
ctx.Csrf = NewCSRFProtector(csrfOpts)
171170

172171
// get the last flash message from cookie

services/context/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ func PackageContexter() func(next http.Handler) http.Handler {
154154
return func(next http.Handler) http.Handler {
155155
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
156156
base := NewBaseContext(resp, req)
157-
// it is still needed when rendering 500 page in a package handler
157+
// FIXME: web Context is still needed when rendering 500 page in a package handler
158+
// It should be refactored to use new error handling mechanisms
158159
ctx := NewWebContext(base, renderer, nil)
159-
ctx.SetContextValue(WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
160160
next.ServeHTTP(ctx.Resp, ctx.Req)
161161
})
162162
}

services/contexttest/context_tests.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*cont
6767

6868
chiCtx := chi.NewRouteContext()
6969
ctx := context.NewWebContext(base, opt.Render, nil)
70-
ctx.SetContextValue(context.WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
7170
ctx.SetContextValue(chi.RouteCtxKey, chiCtx)
7271
if opt.SessionStore != nil {
7372
ctx.SetContextValue(session.MockStoreContextKey, opt.SessionStore)

templates/org/home.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<span class="text">{{svg "octicon-eye"}} {{ctx.Locale.Tr "org.view_as_role" $viewAsRole}}</span>
3333
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
3434
<div class="menu">
35-
{{/* TODO: does it really need to use CurrentURL with query parameters? Why not construct a new link with clear parameters */}}
3635
<a href="?view_as=public" class="item {{if not .IsViewingOrgAsMember}}selected{{end}}">
3736
{{svg "octicon-check" 14 (Iif (not .IsViewingOrgAsMember) "" "tw-invisible")}} {{ctx.Locale.Tr "settings.visibility.public"}}
3837
</a>

0 commit comments

Comments
 (0)