Skip to content

Avoid duplicate SetContextValue call #33564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func Contexter() func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
base := context.NewBaseContext(resp, req)
ctx := context.NewWebContext(base, rnd, session.GetSession(req))
ctx.SetContextValue(context.WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
ctx.Data.MergeFrom(reqctx.ContextData{
"Title": ctx.Locale.Tr("install.install"),
Expand Down
2 changes: 1 addition & 1 deletion routers/private/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Routes() *web.Router {
// FIXME: it is not right to use context.Contexter here because all routes here should use PrivateContext
// Fortunately, the LFS handlers are able to handle requests without a complete web context
common.AddOwnerRepoGitLFSRoutes(r, func(ctx *context.PrivateContext) {
webContext := &context.Context{Base: ctx.Base}
webContext := &context.Context{Base: ctx.Base} // see above, it shouldn't manually construct the web context
ctx.SetContextValue(context.WebContextKey, webContext) // FIXME: this is not ideal but no other way at the moment
})
})
Expand Down
1 change: 0 additions & 1 deletion services/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func Contexter() func(next http.Handler) http.Handler {
ctx.PageData = map[string]any{}
ctx.Data["PageData"] = ctx.PageData

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

// get the last flash message from cookie
Expand Down
4 changes: 2 additions & 2 deletions services/context/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ func PackageContexter() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
base := NewBaseContext(resp, req)
// it is still needed when rendering 500 page in a package handler
// FIXME: web Context is still needed when rendering 500 page in a package handler
// It should be refactored to use new error handling mechanisms
ctx := NewWebContext(base, renderer, nil)
ctx.SetContextValue(WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
next.ServeHTTP(ctx.Resp, ctx.Req)
})
}
Expand Down
1 change: 0 additions & 1 deletion services/contexttest/context_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*cont

chiCtx := chi.NewRouteContext()
ctx := context.NewWebContext(base, opt.Render, nil)
ctx.SetContextValue(context.WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
ctx.SetContextValue(chi.RouteCtxKey, chiCtx)
if opt.SessionStore != nil {
ctx.SetContextValue(session.MockStoreContextKey, opt.SessionStore)
Expand Down
1 change: 0 additions & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<span class="text">{{svg "octicon-eye"}} {{ctx.Locale.Tr "org.view_as_role" $viewAsRole}}</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
{{/* TODO: does it really need to use CurrentURL with query parameters? Why not construct a new link with clear parameters */}}
<a href="?view_as=public" class="item {{if not .IsViewingOrgAsMember}}selected{{end}}">
{{svg "octicon-check" 14 (Iif (not .IsViewingOrgAsMember) "" "tw-invisible")}} {{ctx.Locale.Tr "settings.visibility.public"}}
</a>
Expand Down
Loading