(ctx context.Context, arg GetChatsParams, prepared rbac.PreparedAuthorized)
| 748 | } |
| 749 | |
| 750 | func (q *sqlQuerier) GetAuthorizedChats(ctx context.Context, arg GetChatsParams, prepared rbac.PreparedAuthorized) ([]GetChatsRow, error) { |
| 751 | if arg.OwnedOnly && arg.SharedOnly { |
| 752 | return nil, xerrors.New("owned_only and shared_only cannot both be true") |
| 753 | } |
| 754 | if (arg.OwnedOnly || arg.SharedOnly) && arg.ViewerID == uuid.Nil { |
| 755 | return nil, xerrors.New("viewer_id required when owned_only or shared_only is true") |
| 756 | } |
| 757 | |
| 758 | authorizedFilter, err := prepared.CompileToSQL(ctx, rbac.ConfigChats()) |
| 759 | if err != nil { |
| 760 | return nil, xerrors.Errorf("compile authorized filter: %w", err) |
| 761 | } |
| 762 | |
| 763 | filtered, err := insertAuthorizedFilter(getChats, fmt.Sprintf(" AND %s", authorizedFilter)) |
| 764 | if err != nil { |
| 765 | return nil, xerrors.Errorf("insert authorized filter: %w", err) |
| 766 | } |
| 767 | |
| 768 | // The name comment is for metric tracking |
| 769 | query := fmt.Sprintf("-- name: GetAuthorizedChats :many\n%s", filtered) |
| 770 | rows, err := q.db.QueryContext(ctx, query, |
| 771 | arg.OwnedOnly, |
| 772 | arg.ViewerID, |
| 773 | arg.SharedOnly, |
| 774 | arg.Archived, |
| 775 | arg.AfterID, |
| 776 | arg.LabelFilter, |
| 777 | arg.DiffURL, |
| 778 | arg.TitleQuery, |
| 779 | arg.HasUnread, |
| 780 | pq.Array(arg.PullRequestStatuses), |
| 781 | arg.PrNumber, |
| 782 | arg.RepoQuery, |
| 783 | arg.PrTitleQuery, |
| 784 | arg.OffsetOpt, |
| 785 | arg.LimitOpt, |
| 786 | ) |
| 787 | if err != nil { |
| 788 | return nil, err |
| 789 | } |
| 790 | defer rows.Close() |
| 791 | var items []GetChatsRow |
| 792 | for rows.Next() { |
| 793 | var i GetChatsRow |
| 794 | if err := rows.Scan( |
| 795 | &i.Chat.ID, |
| 796 | &i.Chat.OwnerID, |
| 797 | &i.Chat.WorkspaceID, |
| 798 | &i.Chat.Title, |
| 799 | &i.Chat.Status, |
| 800 | &i.Chat.WorkerID, |
| 801 | &i.Chat.StartedAt, |
| 802 | &i.Chat.HeartbeatAt, |
| 803 | &i.Chat.CreatedAt, |
| 804 | &i.Chat.UpdatedAt, |
| 805 | &i.Chat.ParentChatID, |
| 806 | &i.Chat.RootChatID, |
| 807 | &i.Chat.LastModelConfigID, |
nothing calls this directly
no test coverage detected