@@ -13,6 +13,7 @@ import (
13
13
"github.com/coder/coder/coderd/authzquery"
14
14
"github.com/coder/coder/coderd/database"
15
15
"github.com/coder/coder/coderd/httpapi"
16
+ "github.com/coder/coder/coderd/rbac"
16
17
"github.com/coder/coder/codersdk"
17
18
)
18
19
@@ -36,17 +37,16 @@ func UserParam(r *http.Request) database.User {
36
37
37
38
// ExtractUserParam extracts a user from an ID/username in the {user} URL
38
39
// parameter.
39
- // NOTE: Requires the UserAuthorization middleware.
40
40
//
41
41
//nolint:revive
42
42
func ExtractUserParam (db database.Store , redirectToLoginOnMe bool ) func (http.Handler ) http.Handler {
43
43
return func (next http.Handler ) http.Handler {
44
44
return http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
45
45
var (
46
- auth = UserAuthorization ( r )
47
- ctx = authzquery .WithAuthorizeContext ( r . Context (), auth . Actor )
48
- user database.User
49
- err error
46
+ ctx = r . Context ( )
47
+ systemCtx = authzquery .WithAuthorizeSystemContext ( ctx , rbac . RolesAdminSystem () )
48
+ user database.User
49
+ err error
50
50
)
51
51
52
52
// userQuery is either a uuid, a username, or 'me'
@@ -71,7 +71,7 @@ func ExtractUserParam(db database.Store, redirectToLoginOnMe bool) func(http.Han
71
71
})
72
72
return
73
73
}
74
- user , err = db .GetUserByID (ctx , apiKey .UserID )
74
+ user , err = db .GetUserByID (systemCtx , apiKey .UserID )
75
75
if xerrors .Is (err , sql .ErrNoRows ) {
76
76
httpapi .ResourceNotFound (rw )
77
77
return
@@ -85,7 +85,7 @@ func ExtractUserParam(db database.Store, redirectToLoginOnMe bool) func(http.Han
85
85
}
86
86
} else if userID , err := uuid .Parse (userQuery ); err == nil {
87
87
// If the userQuery is a valid uuid
88
- user , err = db .GetUserByID (ctx , userID )
88
+ user , err = db .GetUserByID (systemCtx , userID )
89
89
if err != nil {
90
90
httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
91
91
Message : userErrorMessage ,
@@ -94,7 +94,7 @@ func ExtractUserParam(db database.Store, redirectToLoginOnMe bool) func(http.Han
94
94
}
95
95
} else {
96
96
// Try as a username last
97
- user , err = db .GetUserByEmailOrUsername (ctx , database.GetUserByEmailOrUsernameParams {
97
+ user , err = db .GetUserByEmailOrUsername (systemCtx , database.GetUserByEmailOrUsernameParams {
98
98
Username : userQuery ,
99
99
})
100
100
if err != nil {
0 commit comments