|
9 | 9 | "github.com/google/uuid"
|
10 | 10 |
|
11 | 11 | "github.com/coder/coder/v2/coderd/database"
|
12 |
| - "github.com/coder/coder/v2/coderd/database/dbauthz" |
13 | 12 | "github.com/coder/coder/v2/coderd/httpapi"
|
14 | 13 | "github.com/coder/coder/v2/codersdk"
|
15 | 14 | )
|
@@ -129,57 +128,3 @@ func ExtractUserContext(ctx context.Context, db database.Store, rw http.Response
|
129 | 128 | }
|
130 | 129 | return user, true
|
131 | 130 | }
|
132 |
| - |
133 |
| -// ExtractUserID will work if the requester can access any OrganizationMember that |
134 |
| -// belongs to the user. |
135 |
| -func ExtractUserID(db database.Store) func(http.Handler) http.Handler { |
136 |
| - return func(next http.Handler) http.Handler { |
137 |
| - return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
138 |
| - ctx := r.Context() |
139 |
| - // We need to resolve the `{user}` URL parameter so that we can get the userID and |
140 |
| - // username. We do this as SystemRestricted since the caller might have permission |
141 |
| - // to access the OrganizationMember object, but *not* the User object. So, it is |
142 |
| - // very important that we do not add the User object to the request context or otherwise |
143 |
| - // leak it to the API handler. |
144 |
| - // nolint:gocritic |
145 |
| - user, ok := ExtractUserContext(dbauthz.AsSystemRestricted(ctx), db, rw, r) |
146 |
| - if !ok { |
147 |
| - return |
148 |
| - } |
149 |
| - organization := OrganizationParam(r) |
150 |
| - |
151 |
| - organizationMember, err := database.ExpectOne(db.OrganizationMembers(ctx, database.OrganizationMembersParams{ |
152 |
| - OrganizationID: organization.ID, |
153 |
| - UserID: user.ID, |
154 |
| - IncludeSystem: false, |
155 |
| - })) |
156 |
| - if httpapi.Is404Error(err) { |
157 |
| - httpapi.ResourceNotFound(rw) |
158 |
| - return |
159 |
| - } |
160 |
| - if err != nil { |
161 |
| - httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
162 |
| - Message: "Internal error fetching organization member.", |
163 |
| - Detail: err.Error(), |
164 |
| - }) |
165 |
| - return |
166 |
| - } |
167 |
| - |
168 |
| - ctx = context.WithValue(ctx, organizationMemberParamContextKey{}, OrganizationMember{ |
169 |
| - OrganizationMember: organizationMember.OrganizationMember, |
170 |
| - // Here we're making two exceptions to the rule about not leaking data about the user |
171 |
| - // to the API handler, which is to include the username and avatar URL. |
172 |
| - // If the caller has permission to read the OrganizationMember, then we're explicitly |
173 |
| - // saying here that they also have permission to see the member's username and avatar. |
174 |
| - // This is OK! |
175 |
| - // |
176 |
| - // API handlers need this information for audit logging and returning the owner's |
177 |
| - // username in response to creating a workspace. Additionally, the frontend consumes |
178 |
| - // the Avatar URL and this allows the FE to avoid an extra request. |
179 |
| - Username: user.Username, |
180 |
| - AvatarURL: user.AvatarURL, |
181 |
| - }) |
182 |
| - next.ServeHTTP(rw, r.WithContext(ctx)) |
183 |
| - }) |
184 |
| - } |
185 |
| -} |
0 commit comments