Skip to content

Commit e3d29c9

Browse files
committed
chore: drop unused redirectToLoginOnMe parameter
1 parent fdd3ad3 commit e3d29c9

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

coderd/coderd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ func New(options *Options) *API {
652652
r.Get("/roles", api.assignableOrgRoles)
653653
r.Route("/{user}", func(r chi.Router) {
654654
r.Use(
655-
httpmw.ExtractUserParam(options.Database, false),
655+
httpmw.ExtractUserParam(options.Database),
656656
httpmw.ExtractOrganizationMemberParam(options.Database),
657657
)
658658
r.Put("/roles", api.putMemberRoles)
@@ -741,7 +741,7 @@ func New(options *Options) *API {
741741
r.Get("/", api.assignableSiteRoles)
742742
})
743743
r.Route("/{user}", func(r chi.Router) {
744-
r.Use(httpmw.ExtractUserParam(options.Database, false))
744+
r.Use(httpmw.ExtractUserParam(options.Database))
745745
r.Post("/convert-login", api.postConvertLoginType)
746746
r.Delete("/", api.deleteUser)
747747
r.Get("/", api.userByName)

coderd/httpmw/organizationparam_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestOrganizationParam(t *testing.T) {
125125
DB: db,
126126
RedirectToLogin: false,
127127
}),
128-
httpmw.ExtractUserParam(db, false),
128+
httpmw.ExtractUserParam(db),
129129
httpmw.ExtractOrganizationParam(db),
130130
httpmw.ExtractOrganizationMemberParam(db),
131131
)
@@ -157,7 +157,7 @@ func TestOrganizationParam(t *testing.T) {
157157
RedirectToLogin: false,
158158
}),
159159
httpmw.ExtractOrganizationParam(db),
160-
httpmw.ExtractUserParam(db, false),
160+
httpmw.ExtractUserParam(db),
161161
httpmw.ExtractOrganizationMemberParam(db),
162162
)
163163
rtr.Get("/", func(rw http.ResponseWriter, r *http.Request) {

coderd/httpmw/userparam.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ func UserParam(r *http.Request) database.User {
3636
// parameter.
3737
//
3838
//nolint:revive
39-
func ExtractUserParam(db database.Store, redirectToLoginOnMe bool) func(http.Handler) http.Handler {
39+
func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
4040
return func(next http.Handler) http.Handler {
4141
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
4242
ctx := r.Context()
4343
// We need to call as SystemRestricted because this middleware is called from
4444
// organizations/{organization}/members/{user}/ paths, and we need to allow
4545
// org-admins to call these paths --- they might not have sitewide read permissions on users.
4646
// nolint:gocritic
47-
user, ok := extractUserContext(dbauthz.AsSystemRestricted(ctx), db, rw, r, redirectToLoginOnMe)
47+
user, ok := extractUserContext(dbauthz.AsSystemRestricted(ctx), db, rw, r)
4848
if !ok {
4949
// response already handled
5050
return
@@ -56,7 +56,7 @@ func ExtractUserParam(db database.Store, redirectToLoginOnMe bool) func(http.Han
5656
}
5757

5858
// extractUserContext queries the database for the parameterized `{user}` from the request URL.
59-
func extractUserContext(ctx context.Context, db database.Store, rw http.ResponseWriter, r *http.Request, redirectToLoginOnMe bool) (user database.User, ok bool) {
59+
func extractUserContext(ctx context.Context, db database.Store, rw http.ResponseWriter, r *http.Request) (user database.User, ok bool) {
6060
// userQuery is either a uuid, a username, or 'me'
6161
userQuery := chi.URLParam(r, "user")
6262
if userQuery == "" {
@@ -69,11 +69,6 @@ func extractUserContext(ctx context.Context, db database.Store, rw http.Response
6969
if userQuery == "me" {
7070
apiKey, ok := APIKeyOptional(r)
7171
if !ok {
72-
if redirectToLoginOnMe {
73-
RedirectToLogin(rw, r, nil, SignedOutErrorMessage)
74-
return database.User{}, false
75-
}
76-
7772
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
7873
Message: "Cannot use \"me\" without a valid session.",
7974
})

coderd/httpmw/userparam_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestUserParam(t *testing.T) {
4444
r = returnedRequest
4545
})).ServeHTTP(rw, r)
4646

47-
httpmw.ExtractUserParam(db, false)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
47+
httpmw.ExtractUserParam(db)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
4848
rw.WriteHeader(http.StatusOK)
4949
})).ServeHTTP(rw, r)
5050
res := rw.Result()
@@ -66,7 +66,7 @@ func TestUserParam(t *testing.T) {
6666
routeContext := chi.NewRouteContext()
6767
routeContext.URLParams.Add("user", "ben")
6868
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeContext))
69-
httpmw.ExtractUserParam(db, false)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
69+
httpmw.ExtractUserParam(db)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
7070
rw.WriteHeader(http.StatusOK)
7171
})).ServeHTTP(rw, r)
7272
res := rw.Result()
@@ -88,7 +88,7 @@ func TestUserParam(t *testing.T) {
8888
routeContext := chi.NewRouteContext()
8989
routeContext.URLParams.Add("user", "me")
9090
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeContext))
91-
httpmw.ExtractUserParam(db, false)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
91+
httpmw.ExtractUserParam(db)(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
9292
_ = httpmw.UserParam(r)
9393
rw.WriteHeader(http.StatusOK)
9494
})).ServeHTTP(rw, r)

coderd/httpmw/workspaceparam_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
315315
DB: db,
316316
RedirectToLogin: true,
317317
}),
318-
httpmw.ExtractUserParam(db, false),
318+
httpmw.ExtractUserParam(db),
319319
httpmw.ExtractWorkspaceAndAgentParam(db),
320320
)
321321
rtr.Get("/", func(w http.ResponseWriter, r *http.Request) {

enterprise/coderd/coderd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
269269
apiKeyMiddleware,
270270
)
271271
r.Route("/{user}", func(r chi.Router) {
272-
r.Use(httpmw.ExtractUserParam(options.Database, false))
272+
r.Use(httpmw.ExtractUserParam(options.Database))
273273
r.Get("/", api.workspaceQuota)
274274
})
275275
})
@@ -296,7 +296,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
296296
r.Use(
297297
api.autostopRequirementEnabledMW,
298298
apiKeyMiddleware,
299-
httpmw.ExtractUserParam(options.Database, false),
299+
httpmw.ExtractUserParam(options.Database),
300300
)
301301

302302
r.Get("/", api.userQuietHoursSchedule)

0 commit comments

Comments
 (0)