(ctx context.Context, rw http.ResponseWriter, chat database.Chat, entries database.ChatACL)
| 232 | } |
| 233 | |
| 234 | func (api *API) chatACLGroups(ctx context.Context, rw http.ResponseWriter, chat database.Chat, entries database.ChatACL) ([]codersdk.ChatGroup, bool) { |
| 235 | groupIDs := make([]uuid.UUID, 0, len(entries)) |
| 236 | for groupID := range entries { |
| 237 | id, err := uuid.Parse(groupID) |
| 238 | if err != nil { |
| 239 | api.Logger.Warn(ctx, "found invalid group uuid in chat acl", slog.Error(err), slog.F("chat_id", chat.ID)) |
| 240 | continue |
| 241 | } |
| 242 | groupIDs = append(groupIDs, id) |
| 243 | } |
| 244 | |
| 245 | dbGroups := make([]database.GetGroupsRow, 0) |
| 246 | if len(groupIDs) > 0 { |
| 247 | var err error |
| 248 | //nolint:gocritic // Users who can read the chat ACL should see shared groups even without group read permission. |
| 249 | dbGroups, err = api.Database.GetGroups(dbauthz.AsSystemRestricted(ctx), database.GetGroupsParams{GroupIds: groupIDs}) |
| 250 | if err != nil && !xerrors.Is(err, sql.ErrNoRows) { |
| 251 | httpapi.InternalServerError(rw, err) |
| 252 | return nil, false |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | groups := make([]codersdk.ChatGroup, 0, len(dbGroups)) |
| 257 | for _, group := range dbGroups { |
| 258 | //nolint:gocritic // Users who can read the chat ACL should see shared group sizes even without group read permission. |
| 259 | memberCount, err := api.Database.GetGroupMembersCountByGroupID(dbauthz.AsSystemRestricted(ctx), database.GetGroupMembersCountByGroupIDParams{ |
| 260 | GroupID: group.Group.ID, |
| 261 | IncludeSystem: false, |
| 262 | }) |
| 263 | if err != nil { |
| 264 | httpapi.InternalServerError(rw, err) |
| 265 | return nil, false |
| 266 | } |
| 267 | entry := entries[group.Group.ID.String()] |
| 268 | groups = append(groups, codersdk.ChatGroup{ |
| 269 | Group: db2sdk.Group(group, nil, int(memberCount)), |
| 270 | Role: convertToChatRole(entry.Permissions), |
| 271 | }) |
| 272 | } |
| 273 | return groups, true |
| 274 | } |
| 275 | |
| 276 | func (api *API) allowChatSharing(ctx context.Context, rw http.ResponseWriter) bool { |
| 277 | if !api.chatSharingDisabled() { |
no test coverage detected