Skip to content

Commit

Permalink
fix(backend): fix list documents with no account ID
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Dec 20, 2024
1 parent c9779db commit b98b001
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
39 changes: 20 additions & 19 deletions backend/api/documents/v3alpha/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,6 @@ func (srv *Server) ListRootDocuments(ctx context.Context, in *documents.ListRoot

// ListDocuments implements Documents API v3.
func (srv *Server) ListDocuments(ctx context.Context, in *documents.ListDocumentsRequest) (*documents.ListDocumentsResponse, error) {
{
if in.Account == "" {
return nil, errutil.MissingArgument("account")
}
}

ns, err := core.DecodePrincipal(in.Account)
if err != nil {
return nil, fmt.Errorf("failed to decode account: %w", err)
}

var cursor = struct {
IRI string `json:"i"`
ActivityTime int64 `json:"t"`
Expand Down Expand Up @@ -314,17 +303,29 @@ func (srv *Server) ListDocuments(ctx context.Context, in *documents.ListDocument

lookup := blob.NewLookupCache(conn)

iri, err := blob.NewIRI(ns, "")
if err != nil {
return nil, err
}

var (
baseIRIGlob = string(iri)
directoryGlob = string(iri) + "/*"
notGlob = ""
baseIRIGlob string
directoryGlob string
notGlob string
)

if in.Account != "" {
ns, err := core.DecodePrincipal(in.Account)
if err != nil {
return nil, fmt.Errorf("failed to decode account: %w", err)
}

iri, err := blob.NewIRI(ns, "")
if err != nil {
return nil, err
}

baseIRIGlob = string(iri) + "*"
directoryGlob = baseIRIGlob + "/*"
} else {
baseIRIGlob = "hm://*"
}

var count int32
rows, check := sqlitex.Query(conn, qListDocumentsByActivityDesc(), baseIRIGlob, directoryGlob, notGlob, cursor.ActivityTime, cursor.IRI, in.PageSize)
for row := range rows {
Expand Down
7 changes: 6 additions & 1 deletion backend/api/documents/v3alpha/documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestListRootDocuments(t *testing.T) {
Compare(t, "alice's root document must match and be second")
}

func TestListDocument(t *testing.T) {
func TestListDocuments(t *testing.T) {
t.Parallel()

alice := newTestDocsAPI(t, "alice")
Expand Down Expand Up @@ -239,6 +239,11 @@ func TestListDocument(t *testing.T) {
testutil.StructsEqual(want[2], list.Documents[2]).
IgnoreFields(documents.DocumentListItem{}, "Breadcrumbs", "ActivitySummary").
Compare(t, "profile doc must be the last element in the list")

list2, err := alice.ListDocuments(ctx, &documents.ListDocumentsRequest{})
require.NoError(t, err)

testutil.StructsEqual(list, list2).Compare(t, "list with no account ID must be allowed")
}

func TestGetDocumentWithVersion(t *testing.T) {
Expand Down

0 comments on commit b98b001

Please sign in to comment.