MCPcopy Index your code
hub / github.com/coder/coder / chatACLGroups

Method chatACLGroups

coderd/exp_chats_acl.go:234–274  ·  view source on GitHub ↗
(ctx context.Context, rw http.ResponseWriter, chat database.Chat, entries database.ChatACL)

Source from the content-addressed store, hash-verified

232}
233
234func (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
276func (api *API) allowChatSharing(ctx context.Context, rw http.ResponseWriter) bool {
277 if !api.chatSharingDisabled() {

Callers 1

getChatACLMethod · 0.95

Calls 10

AsSystemRestrictedFunction · 0.92
InternalServerErrorFunction · 0.92
GroupFunction · 0.92
convertToChatRoleFunction · 0.85
ParseMethod · 0.65
GetGroupsMethod · 0.65
ErrorMethod · 0.45
IsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected