Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into beta-page-connector
Browse files Browse the repository at this point in the history
  • Loading branch information
dadams39 committed Jan 19, 2023
2 parents 39155c6 + 70ebaa6 commit 6b1e847
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 17 deletions.
13 changes: 10 additions & 3 deletions src/internal/connector/onedrive/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
OneDriveSource
SharePointSource
)
const restrictedDirectory = "Site Pages"

func (ds driveSource) toPathServiceCat() (path.ServiceType, path.CategoryType) {
switch ds {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/internal/connector/onedrive/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions src/internal/connector/onedrive/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/connector/onedrive/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/internal/connector/sharepoint/data_collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions src/internal/connector/sharepoint/listInfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ func TestSharePointInfoSuite(t *testing.T) {

func (suite *SharePointInfoSuite) TestSharePointInfo() {
tests := []struct {
name string
listAndRP func() (models.Listable, *details.SharePointInfo)
name string
listAndDeets func() (models.Listable, *details.SharePointInfo)
}{
{
name: "Empty List",
listAndRP: func() (models.Listable, *details.SharePointInfo) {
listAndDeets: func() (models.Listable, *details.SharePointInfo) {
i := &details.SharePointInfo{ItemType: details.SharePointItem}
return models.NewList(), i
},
}, {
name: "Only Name",
listAndRP: func() (models.Listable, *details.SharePointInfo) {
listAndDeets: func() (models.Listable, *details.SharePointInfo) {
aTitle := "Whole List"
listing := models.NewList()
listing.SetDisplayName(&aTitle)
i := &details.SharePointInfo{
ItemType: details.SharePointItem,
ItemName: aTitle,
Size: 10,
}

return listing, i
},
},
}
for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) {
list, expected := test.listAndRP()
list, expected := test.listAndDeets()
info := sharePointListInfo(list, 10)
assert.Equal(t, expected.ItemType, info.ItemType)
assert.Equal(t, expected.ItemName, info.ItemName)
Expand Down
42 changes: 42 additions & 0 deletions src/internal/connector/sharepoint/pageInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package sharepoint

import (
"time"

"github.com/alcionai/corso/src/pkg/backup/details"
)

// sharePointPageInfo propagates metadata from the SharePoint Page data type
// into searchable content.
// Page Details: https://learn.microsoft.com/en-us/graph/api/resources/sitepage?view=graph-rest-beta
func sharePointPageInfo(page SitePageable, size int64) *details.SharePointInfo {
var (
name, webURL string
created, modified time.Time
)

if page.GetTitle() != nil {
name = *page.GetTitle()
}

if page.GetWebUrl() != nil {
webURL = *page.GetWebUrl()
}

if page.GetCreatedDateTime() != nil {
created = *page.GetCreatedDateTime()
}

if page.GetLastModifiedDateTime() != nil {
modified = *page.GetLastModifiedDateTime()
}

return &details.SharePointInfo{
ItemType: details.SharePointItem,
ItemName: name,
Created: created,
Modified: modified,
WebURL: webURL,
Size: size,
}
}
47 changes: 47 additions & 0 deletions src/internal/connector/sharepoint/pageInfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package sharepoint

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/alcionai/corso/src/pkg/backup/details"
)

func (suite *SharePointInfoSuite) TestSharePointInfo_Pages() {
tests := []struct {
name string
pageAndDeets func() (SitePageable, *details.SharePointInfo)
}{
{
name: "Empty Page",
pageAndDeets: func() (SitePageable, *details.SharePointInfo) {
deets := &details.SharePointInfo{ItemType: details.SharePointItem}
return NewSitePage(), deets
},
},
{
name: "Only Name",
pageAndDeets: func() (SitePageable, *details.SharePointInfo) {
title := "Blank Page"
sPage := NewSitePage()
sPage.SetTitle(&title)
deets := &details.SharePointInfo{
ItemType: details.SharePointItem,
ItemName: title,
}

return sPage, deets
},
},
}
for _, test := range tests {
suite.T().Run(test.name, func(t *testing.T) {
paged, expected := test.pageAndDeets()
info := sharePointPageInfo(paged, 0)
assert.Equal(t, expected.ItemType, info.ItemType)
assert.Equal(t, expected.ItemName, info.ItemName)
assert.Equal(t, expected.WebURL, info.WebURL)
})
}
}
6 changes: 6 additions & 0 deletions src/internal/connector/sharepoint/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func RestoreCollections(
deets,
errUpdater,
)
case path.PagesCategory:
errorMessage := fmt.Sprintf("restore of %s not supported", dc.FullPath().Category())
logger.Ctx(ctx).Error(errorMessage)

return nil, errors.New(errorMessage)

default:
return nil, errors.Errorf("category %s not supported", dc.FullPath().Category())
}
Expand Down
Loading

0 comments on commit 6b1e847

Please sign in to comment.