@@ -118,12 +118,12 @@ type OrganizationMember struct {
118
118
119
119
// ExtractOrganizationMemberParam grabs a user membership from the "organization" and "user" URL parameter.
120
120
// This middleware requires the ExtractUser and ExtractOrganization middleware higher in the stack
121
- func ExtractOrganizationMemberParam (db database.Store , auth func ( r * http. Request , action policy. Action , object rbac. Objecter ) bool ) func (http.Handler ) http.Handler {
121
+ func ExtractOrganizationMemberParam (db database.Store ) func (http.Handler ) http.Handler {
122
122
return func (next http.Handler ) http.Handler {
123
123
return http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
124
124
ctx := r .Context ()
125
125
organization := OrganizationParam (r )
126
- _ , members , done := ExtractOrganizationMember (ctx , auth , rw , r , db , organization .ID )
126
+ _ , members , done := ExtractOrganizationMember (ctx , nil , rw , r , db , organization .ID )
127
127
if done {
128
128
return
129
129
}
@@ -194,12 +194,12 @@ func ExtractOrganizationMember(ctx context.Context, auth func(r *http.Request, a
194
194
return nil , nil , true
195
195
}
196
196
197
- if auth (r , policy .ActionRead , user ) {
197
+ if auth != nil && auth (r , policy .ActionRead , user ) {
198
198
return & user , organizationMembers , true
199
199
}
200
200
201
201
// If the user cannot be read and 0 memberships exist, throw a 404 to not
202
- // leak the user existance .
202
+ // leak the user existence .
203
203
if len (organizationMembers ) == 0 {
204
204
httpapi .ResourceNotFound (rw )
205
205
return nil , nil , true
@@ -209,7 +209,11 @@ func ExtractOrganizationMember(ctx context.Context, auth func(r *http.Request, a
209
209
}
210
210
211
211
type OrganizationMembers struct {
212
- User * database.User
212
+ // User is `nil` if the caller is not allowed access to the site wide
213
+ // user object.
214
+ User * database.User
215
+ // Memberships can only be length 0 if `user != nil`. If `user == nil`, then
216
+ // memberships will be at least length 1.
213
217
Memberships []OrganizationMember
214
218
}
215
219
@@ -226,6 +230,9 @@ func (om OrganizationMembers) UserID() uuid.UUID {
226
230
227
231
// ExtractOrganizationMembersParam grabs all user organization memberships.
228
232
// Only requires the "user" URL parameter.
233
+ //
234
+ // Use this if you want to grab as much information for a user as you can.
235
+ // From an organization context, site wide user information might not available.
229
236
func ExtractOrganizationMembersParam (db database.Store , auth func (r * http.Request , action policy.Action , object rbac.Objecter ) bool ) func (http.Handler ) http.Handler {
230
237
return func (next http.Handler ) http.Handler {
231
238
return http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
0 commit comments