Folders: Able to fetch folders available for user as "shared" folder (#77774)

* Folders: Show folders user has access to at the root level

* Refactor

* Refactor

* Hide parent folders user has no access to

* Skip expensive computation if possible

* Fix tests

* Fix potential nil access

* Fix duplicated folders

* Fix linter error

* Fix querying folders if no managed permissions set

* Update benchmark

* Add special shared with me folder and fetch available non-root folders on demand

* Fix parents query

* Improve db query for folders

* Reset benchmark changes

* Fix permissions for shared with me folder

* Simplify dedup

* Add option to include shared folder permission to user's permissions

* Fix nil UID

* Remove duplicated folders from shared list

* Only left the base part

* Apply suggestions from code review

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>

* Add tests

* Fix linter errors

---------

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
Alexander Zobnin
2023-11-08 15:28:49 +01:00
committed by GitHub
parent 5fc3ab801b
commit a39242890e
6 changed files with 173 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package folderimpl
import (
"context"
"fmt"
"slices"
"sort"
"testing"
@@ -705,6 +706,62 @@ func TestIntegrationGetHeight(t *testing.T) {
})
}
func TestIntegrationGetFolders(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
foldersNum := 10
db := sqlstore.InitTestDB(t)
folderStore := ProvideStore(db, db.Cfg, featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders))
orgID := CreateOrg(t, db)
// create folders
uids := make([]string, 0)
folders := make([]*folder.Folder, 0)
for i := 0; i < foldersNum; i++ {
uid := util.GenerateShortUID()
f, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
Title: folderTitle,
Description: folderDsc,
OrgID: orgID,
UID: uid,
})
require.NoError(t, err)
uids = append(uids, uid)
folders = append(folders, f)
}
t.Cleanup(func() {
for _, uid := range uids {
err := folderStore.Delete(context.Background(), uid, orgID)
require.NoError(t, err)
}
})
t.Run("get folders by UIDs should succeed", func(t *testing.T) {
ff, err := folderStore.GetFolders(context.Background(), orgID, uids)
require.NoError(t, err)
assert.Equal(t, len(uids), len(ff))
for _, f := range folders {
folderInResponseIdx := slices.IndexFunc(ff, func(rf *folder.Folder) bool {
return rf.UID == f.UID
})
assert.NotEqual(t, -1, folderInResponseIdx)
rf := ff[folderInResponseIdx]
assert.Equal(t, f.ID, rf.ID)
assert.Equal(t, f.OrgID, rf.OrgID)
assert.Equal(t, f.Title, rf.Title)
assert.Equal(t, f.Description, rf.Description)
assert.NotEmpty(t, rf.Created)
assert.NotEmpty(t, rf.Updated)
assert.NotEmpty(t, rf.URL)
}
})
}
func CreateOrg(t *testing.T, db *sqlstore.SQLStore) int64 {
t.Helper()