diff --git a/src/internal/connector/onedrive/collections.go b/src/internal/connector/onedrive/collections.go index 7bdbfc8f5..6a59104f1 100644 --- a/src/internal/connector/onedrive/collections.go +++ b/src/internal/connector/onedrive/collections.go @@ -24,6 +24,7 @@ const ( OneDriveSource SharePointSource ) +const restrictedDirectory = "Site Pages" func (ds driveSource) toPathServiceCat() (path.ServiceType, path.CategoryType) { switch ds { @@ -102,8 +103,9 @@ func (c *Collections) Get(ctx context.Context) ([]data.Collection, error) { // Update the collection map with items from each drive for _, d := range drives { driveID := *d.GetId() + driveName := *d.GetName() - delta, paths, err := collectItems(ctx, c.service, driveID, c.UpdateCollections) + delta, paths, err := collectItems(ctx, c.service, driveID, driveName, c.UpdateCollections) if err != nil { return nil, err } @@ -162,7 +164,7 @@ func (c *Collections) Get(ctx context.Context) ([]data.Collection, error) { // A new collection is created for every drive folder (or package) func (c *Collections) UpdateCollections( ctx context.Context, - driveID string, + driveID, driveName string, items []models.DriveItemable, paths map[string]string, ) error { @@ -188,7 +190,7 @@ func (c *Collections) UpdateCollections( } // Skip items that don't match the folder selectors we were given. - if !includePath(ctx, c.matcher, collectionPath) { + if shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) { logger.Ctx(ctx).Infof("Skipping path %s", collectionPath.String()) continue } @@ -239,6 +241,11 @@ func (c *Collections) UpdateCollections( return nil } +func shouldSkipDrive(ctx context.Context, drivePath path.Path, m folderMatcher, driveName string) bool { + return !includePath(ctx, m, drivePath) || + (drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName) +} + // GetCanonicalPath constructs the standard path for the given source. func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path.Path, error) { var ( diff --git a/src/internal/connector/onedrive/collections_test.go b/src/internal/connector/onedrive/collections_test.go index f31ae8bab..5a0775edc 100644 --- a/src/internal/connector/onedrive/collections_test.go +++ b/src/internal/connector/onedrive/collections_test.go @@ -326,7 +326,7 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() { nil, control.Options{}) - err := c.UpdateCollections(ctx, "driveID", tt.items, paths) + err := c.UpdateCollections(ctx, "driveID", "General", tt.items, paths) tt.expect(t, err) assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths") assert.Equal(t, tt.expectedItemCount, c.NumItems, "item count") diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index f063eec53..e98e8d35b 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -163,7 +163,7 @@ func userDrives(ctx context.Context, service graph.Servicer, user string) ([]mod // itemCollector functions collect the items found in a drive type itemCollector func( ctx context.Context, - driveID string, + driveID, driveName string, driveItems []models.DriveItemable, paths map[string]string, ) error @@ -173,7 +173,7 @@ type itemCollector func( func collectItems( ctx context.Context, service graph.Servicer, - driveID string, + driveID, driveName string, collector itemCollector, ) (string, map[string]string, error) { var ( @@ -219,7 +219,7 @@ func collectItems( ) } - err = collector(ctx, driveID, r.GetValue(), paths) + err = collector(ctx, driveID, driveName, r.GetValue(), paths) if err != nil { return "", nil, err } @@ -349,9 +349,10 @@ func GetAllFolders( ctx, gs, *d.GetId(), + *d.GetName(), func( innerCtx context.Context, - driveID string, + driveID, driveName string, items []models.DriveItemable, paths map[string]string, ) error { diff --git a/src/internal/connector/onedrive/item_test.go b/src/internal/connector/onedrive/item_test.go index d87878fc4..5c2e8c335 100644 --- a/src/internal/connector/onedrive/item_test.go +++ b/src/internal/connector/onedrive/item_test.go @@ -97,7 +97,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() { // This item collector tries to find "a" drive item that is a file to test the reader function itemCollector := func( ctx context.Context, - driveID string, + driveID, driveName string, items []models.DriveItemable, paths map[string]string, ) error { @@ -110,7 +110,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() { return nil } - _, _, err := collectItems(ctx, suite, suite.userDriveID, itemCollector) + _, _, err := collectItems(ctx, suite, suite.userDriveID, "General", itemCollector) require.NoError(suite.T(), err) // Test Requirement 2: Need a file diff --git a/src/internal/connector/sharepoint/data_collections_test.go b/src/internal/connector/sharepoint/data_collections_test.go index f52a642ba..2934b2fa1 100644 --- a/src/internal/connector/sharepoint/data_collections_test.go +++ b/src/internal/connector/sharepoint/data_collections_test.go @@ -96,7 +96,7 @@ func (suite *SharePointLibrariesSuite) TestUpdateCollections() { &MockGraphService{}, nil, control.Options{}) - err := c.UpdateCollections(ctx, "driveID", test.items, paths) + err := c.UpdateCollections(ctx, "driveID", "General", test.items, paths) test.expect(t, err) assert.Equal(t, len(test.expectedCollectionPaths), len(c.CollectionMap), "collection paths") assert.Equal(t, test.expectedItemCount, c.NumItems, "item count")