GC: OneDrive/SharePoint WebURL Fix (#2596)

## Description
Changes: 
- Use of `ptr` package to ensure safe dereferencing of pointers
- Update to query to ensure that `sharepointIds` are part of the response
- Alternate method created to obtain originating sharepoint site url 
<!-- Insert PR description-->

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

- [x]  No 

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [x] 🐛 Bugfix


## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* closes #1747<issue>

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
This commit is contained in:
Danny 2023-02-21 18:29:31 -05:00 committed by GitHub
parent a88b984b9a
commit f06f2f585a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 20 deletions

View File

@ -179,6 +179,7 @@ func defaultItemPager(
"package",
"parentReference",
"root",
"sharepointIds",
"size",
"deleted",
},

View File

@ -14,6 +14,7 @@ import (
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/support"
"github.com/alcionai/corso/src/internal/connector/uploadsession"
@ -194,9 +195,9 @@ func oneDriveItemInfo(di models.DriveItemable, itemSize int64) *details.OneDrive
return &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ItemName: *di.GetName(),
Created: *di.GetCreatedDateTime(),
Modified: *di.GetLastModifiedDateTime(),
ItemName: ptr.Val(di.GetName()),
Created: ptr.Val(di.GetCreatedDateTime()),
Modified: ptr.Val(di.GetLastModifiedDateTime()),
DriveName: parent,
Size: itemSize,
Owner: email,
@ -280,36 +281,32 @@ func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.ShareP
// TODO: we rely on this info for details/restore lookups,
// so if it's nil we have an issue, and will need an alternative
// way to source the data.
gsi := di.GetSharepointIds()
if gsi != nil {
if gsi.GetSiteId() != nil {
id = *gsi.GetSiteId()
}
id = ptr.Val(gsi.GetSiteId())
url = ptr.Val(gsi.GetSiteUrl())
if gsi.GetSiteUrl() != nil {
url = *gsi.GetSiteUrl()
if len(url) == 0 {
url = constructWebURL(di.GetAdditionalData())
}
}
if reference != nil {
parent = *reference.GetDriveId()
parent = ptr.Val(reference.GetDriveId())
temp := ptr.Val(reference.GetName())
temp = strings.TrimSpace(temp)
if reference.GetName() != nil {
// EndPoint is not always populated from external apps
temp := *reference.GetName()
temp = strings.TrimSpace(temp)
if temp != "" {
parent = temp
}
if temp != "" {
parent = temp
}
}
return &details.SharePointInfo{
ItemType: details.OneDriveItem,
ItemName: *di.GetName(),
Created: *di.GetCreatedDateTime(),
Modified: *di.GetLastModifiedDateTime(),
ItemName: ptr.Val(di.GetName()),
Created: ptr.Val(di.GetCreatedDateTime()),
Modified: ptr.Val(di.GetLastModifiedDateTime()),
DriveName: parent,
Size: itemSize,
Owner: id,
@ -344,3 +341,36 @@ func driveItemWriter(
return uploadsession.NewWriter(itemID, url, itemSize), nil
}
// constructWebURL helper function for recreating the webURL
// for the originating SharePoint site. Uses additional data map
// from a models.DriveItemable that possesses a downloadURL within the map.
// Returns "" if map nil or key is not present.
func constructWebURL(adtl map[string]any) string {
var (
desiredKey = "@microsoft.graph.downloadUrl"
sep = `/_layouts`
url string
)
if adtl == nil {
return url
}
r := adtl[desiredKey]
point, ok := r.(*string)
if !ok {
return url
}
value := ptr.Val(point)
if len(value) == 0 {
return url
}
temp := strings.Split(value, sep)
url = temp[0]
return url
}