GC: Sharepoint: Pages info extended (#2461)

## Description
SharePoint details has a field `ParentPath`. This PR populates that field. 
Requires an additional call per collection to retrieve the Site's webURL. 
<!-- Insert PR description-->

## Does this PR need a docs update or release note?

- [x]  No 

## Type of change
- [x] 🧹 Tech Debt/Cleanup


## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
This commit is contained in:
Danny 2023-02-23 14:43:10 -05:00 committed by GitHub
parent b1dce98710
commit 9793d81670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 1 deletions

View File

@ -19,6 +19,8 @@ import (
D "github.com/alcionai/corso/src/internal/diagnostics"
"github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/fault"
msmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
mssites "github.com/microsoftgraph/msgraph-sdk-go/sites"
)
// GetSitePages retrieves a collection of Pages related to the give Site.
@ -81,6 +83,23 @@ func GetSitePages(
return col, et.Err()
}
// GetSite returns a minimal Site with the SiteID and the WebURL
func GetSite(ctx context.Context, gs graph.Servicer, siteID string) (msmodels.Siteable, error) {
// resp *sites.SiteItemRequestBuilderresp *sites.SiteItemRequestBuilde
options := &mssites.SiteItemRequestBuilderGetRequestConfiguration{
QueryParameters: &mssites.SiteItemRequestBuilderGetQueryParameters{
Select: []string{"webUrl"},
},
}
resp, err := gs.Client().SitesById(siteID).Get(ctx, options)
if err != nil {
return nil, err
}
return resp, nil
}
// fetchPages utility function to return the tuple of item
func FetchPages(ctx context.Context, bs *discover.BetaService, siteID string) ([]NameID, error) {
var (

View File

@ -288,6 +288,13 @@ func (sc *Collection) retrievePages(
return metrics, clues.New("beta service required").WithClues(ctx)
}
parent, err := sapi.GetSite(ctx, sc.service, sc.fullPath.ResourceOwner())
if err != nil {
return metrics, err
}
root := ptr.Val(parent.GetWebUrl())
pages, err := sapi.GetSitePages(ctx, betaService, sc.fullPath.ResourceOwner(), sc.jobs, errs)
if err != nil {
return metrics, err
@ -316,7 +323,7 @@ func (sc *Collection) retrievePages(
sc.data <- &Item{
id: *pg.GetId(),
data: io.NopCloser(bytes.NewReader(byteArray)),
info: sapi.PageInfo(pg, size),
info: sharePointPageInfo(pg, root, size),
modTime: ptr.OrNow(pg.GetLastModifiedDateTime()),
}

View File

@ -0,0 +1,48 @@
package sharepoint
import (
"time"
"github.com/alcionai/corso/src/internal/connector/graph/betasdk/models"
"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 models.SitePageable, root string, size int64) *details.SharePointInfo {
var (
name, prefix, webURL string
created, modified time.Time
)
if page.GetTitle() != nil {
name = *page.GetTitle()
}
if page.GetWebUrl() != nil {
if len(root) > 0 {
prefix = root + "/"
}
webURL = prefix + *page.GetWebUrl()
}
if page.GetCreatedDateTime() != nil {
created = *page.GetCreatedDateTime()
}
if page.GetLastModifiedDateTime() != nil {
modified = *page.GetLastModifiedDateTime()
}
return &details.SharePointInfo{
ItemType: details.SharePointItem,
ItemName: name,
ParentPath: root,
Created: created,
Modified: modified,
WebURL: webURL,
Size: size,
}
}

View File

@ -0,0 +1,48 @@
package sharepoint
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/alcionai/corso/src/internal/connector/graph/betasdk/models"
"github.com/alcionai/corso/src/pkg/backup/details"
)
func (suite *SharePointInfoSuite) TestSharePointInfo_Pages() {
tests := []struct {
name string
pageAndDeets func() (models.SitePageable, *details.SharePointInfo)
}{
{
name: "Empty Page",
pageAndDeets: func() (models.SitePageable, *details.SharePointInfo) {
deets := &details.SharePointInfo{ItemType: details.SharePointItem}
return models.NewSitePage(), deets
},
},
{
name: "Only Name",
pageAndDeets: func() (models.SitePageable, *details.SharePointInfo) {
title := "Blank Page"
sPage := models.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)
})
}
}