add foldermatcher to handler (#3565)
Missed adding the foldermatcher to the handlers for onedrive and sharepoint during the api refactor. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #1996 #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
c0f428ddc8
commit
5184920b52
@ -19,20 +19,6 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
type odFolderMatcher struct {
|
||||
scope selectors.OneDriveScope
|
||||
}
|
||||
|
||||
func (fm odFolderMatcher) IsAny() bool {
|
||||
return fm.scope.IsAny(selectors.OneDriveFolder)
|
||||
}
|
||||
|
||||
func (fm odFolderMatcher) Matches(dir string) bool {
|
||||
return fm.scope.Matches(selectors.OneDriveFolder, dir)
|
||||
}
|
||||
|
||||
// ProduceBackupCollections returns a set of DataCollection which represents the OneDrive data
|
||||
// for the specified user
|
||||
func ProduceBackupCollections(
|
||||
ctx context.Context,
|
||||
ac api.Client,
|
||||
@ -68,10 +54,9 @@ func ProduceBackupCollections(
|
||||
logger.Ctx(ctx).Debug("creating OneDrive collections")
|
||||
|
||||
nc := NewCollections(
|
||||
&itemBackupHandler{ac.Drives()},
|
||||
&itemBackupHandler{ac.Drives(), scope},
|
||||
tenant,
|
||||
user.ID(),
|
||||
odFolderMatcher{scope},
|
||||
su,
|
||||
ctrlOpts)
|
||||
|
||||
|
||||
@ -42,11 +42,6 @@ const (
|
||||
|
||||
const restrictedDirectory = "Site Pages"
|
||||
|
||||
type folderMatcher interface {
|
||||
IsAny() bool
|
||||
Matches(string) bool
|
||||
}
|
||||
|
||||
// Collections is used to retrieve drive data for a
|
||||
// resource owner, which can be either a user or a sharepoint site.
|
||||
type Collections struct {
|
||||
@ -54,7 +49,7 @@ type Collections struct {
|
||||
|
||||
tenantID string
|
||||
resourceOwner string
|
||||
matcher folderMatcher
|
||||
|
||||
statusUpdater support.StatusUpdater
|
||||
|
||||
ctrl control.Options
|
||||
@ -74,7 +69,6 @@ func NewCollections(
|
||||
bh BackupHandler,
|
||||
tenantID string,
|
||||
resourceOwner string,
|
||||
matcher folderMatcher,
|
||||
statusUpdater support.StatusUpdater,
|
||||
ctrlOpts control.Options,
|
||||
) *Collections {
|
||||
@ -82,7 +76,6 @@ func NewCollections(
|
||||
handler: bh,
|
||||
tenantID: tenantID,
|
||||
resourceOwner: resourceOwner,
|
||||
matcher: matcher,
|
||||
CollectionMap: map[string]map[string]*Collection{},
|
||||
statusUpdater: statusUpdater,
|
||||
ctrl: ctrlOpts,
|
||||
@ -697,7 +690,7 @@ func (c *Collections) UpdateCollections(
|
||||
}
|
||||
|
||||
// Skip items that don't match the folder selectors we were given.
|
||||
if shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) {
|
||||
if shouldSkip(ctx, collectionPath, c.handler, driveName) {
|
||||
logger.Ctx(ictx).Debugw("path not selected", "skipped_path", collectionPath.String())
|
||||
continue
|
||||
}
|
||||
@ -827,12 +820,17 @@ func (c *Collections) UpdateCollections(
|
||||
return el.Failure()
|
||||
}
|
||||
|
||||
func shouldSkipDrive(ctx context.Context, drivePath path.Path, m folderMatcher, driveName string) bool {
|
||||
return !includePath(ctx, m, drivePath) ||
|
||||
type dirScopeChecker interface {
|
||||
IsAllPass() bool
|
||||
IncludesDir(dir string) bool
|
||||
}
|
||||
|
||||
func shouldSkip(ctx context.Context, drivePath path.Path, dsc dirScopeChecker, driveName string) bool {
|
||||
return !includePath(ctx, dsc, drivePath) ||
|
||||
(drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName)
|
||||
}
|
||||
|
||||
func includePath(ctx context.Context, m folderMatcher, folderPath path.Path) bool {
|
||||
func includePath(ctx context.Context, dsc dirScopeChecker, folderPath path.Path) bool {
|
||||
// Check if the folder is allowed by the scope.
|
||||
pb, err := path.GetDriveFolderPath(folderPath)
|
||||
if err != nil {
|
||||
@ -842,11 +840,11 @@ func includePath(ctx context.Context, m folderMatcher, folderPath path.Path) boo
|
||||
|
||||
// Hack for the edge case where we're looking at the root folder and can
|
||||
// select any folder. Right now the root folder has an empty folder path.
|
||||
if len(pb.Elements()) == 0 && m.IsAny() {
|
||||
if len(pb.Elements()) == 0 && dsc.IsAllPass() {
|
||||
return true
|
||||
}
|
||||
|
||||
return m.Matches(pb.String())
|
||||
return dsc.IncludesDir(pb.String())
|
||||
}
|
||||
|
||||
func updatePath(paths map[string]string, id, newPath string) {
|
||||
|
||||
@ -743,10 +743,9 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() {
|
||||
maps.Copy(outputFolderMap, tt.inputFolderMap)
|
||||
|
||||
c := NewCollections(
|
||||
&itemBackupHandler{api.Drives{}},
|
||||
&itemBackupHandler{api.Drives{}, tt.scope},
|
||||
tenant,
|
||||
user,
|
||||
testFolderMatcher{tt.scope},
|
||||
nil,
|
||||
control.Options{ToggleFeatures: control.Toggles{}})
|
||||
|
||||
@ -1238,7 +1237,6 @@ func (p *mockItemPager) ValuesIn(api.DeltaPageLinker) ([]models.DriveItemable, e
|
||||
|
||||
func (suite *OneDriveCollectionsUnitSuite) TestGet() {
|
||||
var (
|
||||
anyFolder = (&selectors.OneDriveBackup{}).Folders(selectors.Any())[0]
|
||||
tenant = "a-tenant"
|
||||
user = "a-user"
|
||||
empty = ""
|
||||
@ -2345,7 +2343,6 @@ func (suite *OneDriveCollectionsUnitSuite) TestGet() {
|
||||
mbh,
|
||||
tenant,
|
||||
user,
|
||||
testFolderMatcher{anyFolder},
|
||||
func(*support.ControllerOperationStatus) {},
|
||||
control.Options{ToggleFeatures: control.Toggles{}})
|
||||
|
||||
|
||||
@ -54,6 +54,10 @@ type BackupHandler interface {
|
||||
// provided path.
|
||||
FormatDisplayPath(driveName string, parentPath *path.Builder) string
|
||||
NewLocationIDer(driveID string, elems ...string) details.LocationIDer
|
||||
|
||||
// scope wrapper funcs
|
||||
IsAllPass() bool
|
||||
IncludesDir(dir string) bool
|
||||
}
|
||||
|
||||
type GetItemPermissioner interface {
|
||||
|
||||
@ -390,7 +390,10 @@ func (suite *OneDriveIntgSuite) TestCreateGetDeleteFolder() {
|
||||
for _, test := range table {
|
||||
suite.Run(test.name, func() {
|
||||
t := suite.T()
|
||||
bh := itemBackupHandler{suite.ac.Drives()}
|
||||
bh := itemBackupHandler{
|
||||
suite.ac.Drives(),
|
||||
(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0],
|
||||
}
|
||||
pager := suite.ac.Drives().NewUserDrivePager(suite.userID, nil)
|
||||
|
||||
ctx, flush := tester.NewContext(t)
|
||||
@ -415,18 +418,6 @@ func (suite *OneDriveIntgSuite) TestCreateGetDeleteFolder() {
|
||||
}
|
||||
}
|
||||
|
||||
type testFolderMatcher struct {
|
||||
scope selectors.OneDriveScope
|
||||
}
|
||||
|
||||
func (fm testFolderMatcher) IsAny() bool {
|
||||
return fm.scope.IsAny(selectors.OneDriveFolder)
|
||||
}
|
||||
|
||||
func (fm testFolderMatcher) Matches(p string) bool {
|
||||
return fm.scope.Matches(selectors.OneDriveFolder, p)
|
||||
}
|
||||
|
||||
func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() {
|
||||
creds, err := tester.NewM365Account(suite.T()).M365Config()
|
||||
require.NoError(suite.T(), err, clues.ToCore(err))
|
||||
@ -459,10 +450,9 @@ func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() {
|
||||
)
|
||||
|
||||
colls := NewCollections(
|
||||
&itemBackupHandler{suite.ac.Drives()},
|
||||
&itemBackupHandler{suite.ac.Drives(), scope},
|
||||
creds.AzureTenantID,
|
||||
test.user,
|
||||
testFolderMatcher{scope},
|
||||
service.updateStatus,
|
||||
control.Options{
|
||||
ToggleFeatures: control.Toggles{},
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts"
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -23,6 +24,7 @@ var _ BackupHandler = &itemBackupHandler{}
|
||||
|
||||
type itemBackupHandler struct {
|
||||
ac api.Drives
|
||||
scope selectors.OneDriveScope
|
||||
}
|
||||
|
||||
func (h itemBackupHandler) Get(
|
||||
@ -108,6 +110,14 @@ func (h itemBackupHandler) GetItem(
|
||||
return h.ac.GetItem(ctx, driveID, itemID)
|
||||
}
|
||||
|
||||
func (h itemBackupHandler) IsAllPass() bool {
|
||||
return h.scope.IsAny(selectors.OneDriveFolder)
|
||||
}
|
||||
|
||||
func (h itemBackupHandler) IncludesDir(dir string) bool {
|
||||
return h.scope.Matches(selectors.OneDriveFolder, dir)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Restore
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
"github.com/alcionai/corso/src/pkg/control/testdata"
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -118,7 +119,10 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
|
||||
suite.user,
|
||||
suite.userDriveID)
|
||||
|
||||
bh := itemBackupHandler{suite.service.ac.Drives()}
|
||||
bh := itemBackupHandler{
|
||||
suite.service.ac.Drives(),
|
||||
(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0],
|
||||
}
|
||||
|
||||
// Read data for the file
|
||||
itemData, err := downloadItem(ctx, bh, driveItem)
|
||||
|
||||
@ -184,6 +184,14 @@ var defaultSharePointLocationIDer = func(driveID string, elems ...string) detail
|
||||
return details.NewSharePointLocationIDer(driveID, elems...)
|
||||
}
|
||||
|
||||
func (h BackupHandler) IsAllPass() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (h BackupHandler) IncludesDir(string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Get Itemer
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -220,10 +220,9 @@ func collectLibraries(
|
||||
var (
|
||||
collections = []data.BackupCollection{}
|
||||
colls = onedrive.NewCollections(
|
||||
&libraryBackupHandler{ad},
|
||||
&libraryBackupHandler{ad, scope},
|
||||
tenantID,
|
||||
site.ID(),
|
||||
folderMatcher{scope},
|
||||
updater.UpdateStatus,
|
||||
ctrlOpts)
|
||||
)
|
||||
@ -301,15 +300,3 @@ func collectPages(
|
||||
|
||||
return spcs, el.Failure()
|
||||
}
|
||||
|
||||
type folderMatcher struct {
|
||||
scope selectors.SharePointScope
|
||||
}
|
||||
|
||||
func (fm folderMatcher) IsAny() bool {
|
||||
return fm.scope.IsAny(selectors.SharePointLibraryFolder)
|
||||
}
|
||||
|
||||
func (fm folderMatcher) Matches(dir string) bool {
|
||||
return fm.scope.Matches(selectors.SharePointLibraryFolder, dir)
|
||||
}
|
||||
|
||||
@ -29,18 +29,6 @@ var testBaseDrivePath = path.Builder{}.Append(
|
||||
"driveID1",
|
||||
odConsts.RootPathDir)
|
||||
|
||||
type testFolderMatcher struct {
|
||||
scope selectors.SharePointScope
|
||||
}
|
||||
|
||||
func (fm testFolderMatcher) IsAny() bool {
|
||||
return fm.scope.IsAny(selectors.SharePointLibraryFolder)
|
||||
}
|
||||
|
||||
func (fm testFolderMatcher) Matches(p string) bool {
|
||||
return fm.scope.Matches(selectors.SharePointLibraryFolder, p)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// tests
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -113,10 +101,9 @@ func (suite *LibrariesBackupUnitSuite) TestUpdateCollections() {
|
||||
)
|
||||
|
||||
c := onedrive.NewCollections(
|
||||
&libraryBackupHandler{api.Drives{}},
|
||||
&libraryBackupHandler{api.Drives{}, test.scope},
|
||||
tenantID,
|
||||
site,
|
||||
testFolderMatcher{test.scope},
|
||||
nil,
|
||||
control.Defaults())
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts"
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -20,6 +21,7 @@ var _ onedrive.BackupHandler = &libraryBackupHandler{}
|
||||
|
||||
type libraryBackupHandler struct {
|
||||
ac api.Drives
|
||||
scope selectors.SharePointScope
|
||||
}
|
||||
|
||||
func (h libraryBackupHandler) Get(
|
||||
@ -139,6 +141,14 @@ func (h libraryBackupHandler) GetItem(
|
||||
return h.ac.GetItem(ctx, driveID, itemID)
|
||||
}
|
||||
|
||||
func (h libraryBackupHandler) IsAllPass() bool {
|
||||
return h.scope.IsAny(selectors.SharePointLibraryFolder)
|
||||
}
|
||||
|
||||
func (h libraryBackupHandler) IncludesDir(dir string) bool {
|
||||
return h.scope.Matches(selectors.SharePointLibraryFolder, dir)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Restore
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user