(ctx context.Context, id uuid.UUID)
| 2996 | } |
| 2997 | |
| 2998 | func (q *querier) GetChatFileByID(ctx context.Context, id uuid.UUID) (database.ChatFile, error) { |
| 2999 | file, err := q.db.GetChatFileByID(ctx, id) |
| 3000 | if err != nil { |
| 3001 | return database.ChatFile{}, err |
| 3002 | } |
| 3003 | fileAuthErr := q.authorizeContext(ctx, policy.ActionRead, file) |
| 3004 | if fileAuthErr == nil { |
| 3005 | return file, nil |
| 3006 | } |
| 3007 | |
| 3008 | prepared, err := prepareSQLFilter(ctx, q.auth, policy.ActionRead, rbac.ResourceChat.Type) |
| 3009 | if err != nil { |
| 3010 | return database.ChatFile{}, xerrors.Errorf("(dev error) prepare sql filter: %w", err) |
| 3011 | } |
| 3012 | chats, err := q.db.GetAuthorizedChatsByChatFileID(ctx, id, prepared) |
| 3013 | if err != nil { |
| 3014 | return database.ChatFile{}, err |
| 3015 | } |
| 3016 | if len(chats) == 0 { |
| 3017 | return database.ChatFile{}, fileAuthErr |
| 3018 | } |
| 3019 | return file, nil |
| 3020 | } |
| 3021 | |
| 3022 | func (q *querier) GetChatFileMetadataByChatID(ctx context.Context, chatID uuid.UUID) ([]database.GetChatFileMetadataByChatIDRow, error) { |
| 3023 | if _, err := q.GetChatByID(ctx, chatID); err != nil { |
nothing calls this directly
no test coverage detected