From e499860785d74ecd30f5b8d675096b6f134fb1a3 Mon Sep 17 00:00:00 2001 From: ramfox Date: Thu, 2 Dec 2021 12:23:33 -0500 Subject: [PATCH] fix(lib): use `username` parameter in `lib.List` Also, allows fetching a dataset from the collection that is not in your own collection --- lib/collection.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/collection.go b/lib/collection.go index 5065ec8d8..879cf969c 100644 --- a/lib/collection.go +++ b/lib/collection.go @@ -94,7 +94,17 @@ func (collectionImpl) List(scope scope, p *ListParams) ([]dsref.VersionInfo, Cur Offset: p.Offset, Limit: p.Limit, } - infos, err := s.List(scope.ctx, scope.ActiveProfile().ID, lp) + + id := scope.ActiveProfile().ID + if p.Username != "" { + pro, err := getProfile(scope.Context(), scope.Profiles(), "", p.Username) + if err != nil { + return nil, nil, err + } + id = pro.ID + } + + infos, err := s.List(scope.ctx, id, lp) if err != nil { return nil, nil, err } @@ -246,12 +256,28 @@ func (collectionImpl) Get(scope scope, p *CollectionGetParams) (*dsref.VersionIn if s == nil { return nil, fmt.Errorf("no collection") } - if p.InitID == "" { - ref, _, err := scope.ParseAndResolveRef(scope.Context(), p.Ref) + + var err error + + ref := dsref.Ref{ + InitID: p.InitID, + } + + if ref.InitID != "" { + _, err = scope.ResolveReference(scope.Context(), &ref) + if err != nil { + return nil, err + } + } else { + ref, _, err = scope.ParseAndResolveRef(scope.Context(), p.Ref) if err != nil { return nil, err } - p.InitID = ref.InitID } - return s.Get(scope.Context(), scope.ActiveProfile().ID, p.InitID) + + id, err := profile.IDB58Decode(ref.ProfileID) + if err != nil { + return nil, err + } + return s.Get(scope.Context(), id, ref.InitID) }