ExtractOrganizationMembersParam grabs all user organization memberships. Only requires the "user" URL parameter. Use this if you want to grab as much information for a user as you can. From an organization context, site wide user information might not available.
(db database.Store, auth func(r *http.Request, action policy.Action, object rbac.Objecter) bool)
| 236 | // Use this if you want to grab as much information for a user as you can. |
| 237 | // From an organization context, site wide user information might not available. |
| 238 | func ExtractOrganizationMembersParam(db database.Store, auth func(r *http.Request, action policy.Action, object rbac.Objecter) bool) func(http.Handler) http.Handler { |
| 239 | return func(next http.Handler) http.Handler { |
| 240 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 241 | ctx := r.Context() |
| 242 | |
| 243 | // Fetch all memberships |
| 244 | user, members, done := ExtractOrganizationMember(ctx, auth, rw, r, db, uuid.Nil) |
| 245 | if done { |
| 246 | return |
| 247 | } |
| 248 | |
| 249 | orgMembers := make([]OrganizationMember, 0, len(members)) |
| 250 | for _, organizationMember := range members { |
| 251 | orgMembers = append(orgMembers, OrganizationMember{ |
| 252 | OrganizationMember: organizationMember.OrganizationMember, |
| 253 | Username: organizationMember.Username, |
| 254 | AvatarURL: organizationMember.AvatarURL, |
| 255 | }) |
| 256 | } |
| 257 | |
| 258 | ctx = context.WithValue(ctx, organizationMembersParamContextKey{}, OrganizationMembers{ |
| 259 | User: user, |
| 260 | Memberships: orgMembers, |
| 261 | }) |
| 262 | next.ServeHTTP(rw, r.WithContext(ctx)) |
| 263 | }) |
| 264 | } |
| 265 | } |