diff --git a/backend/api/documents/v3alpha/documents.go b/backend/api/documents/v3alpha/documents.go index c570e7f7..7b8f384b 100644 --- a/backend/api/documents/v3alpha/documents.go +++ b/backend/api/documents/v3alpha/documents.go @@ -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"` @@ -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 { diff --git a/backend/api/documents/v3alpha/documents_test.go b/backend/api/documents/v3alpha/documents_test.go index b5e4028e..5ea43dd2 100644 --- a/backend/api/documents/v3alpha/documents_test.go +++ b/backend/api/documents/v3alpha/documents_test.go @@ -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") @@ -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) {