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:
parent
a88b984b9a
commit
f06f2f585a
@ -179,6 +179,7 @@ func defaultItemPager(
|
|||||||
"package",
|
"package",
|
||||||
"parentReference",
|
"parentReference",
|
||||||
"root",
|
"root",
|
||||||
|
"sharepointIds",
|
||||||
"size",
|
"size",
|
||||||
"deleted",
|
"deleted",
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
"github.com/pkg/errors"
|
"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/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
"github.com/alcionai/corso/src/internal/connector/uploadsession"
|
"github.com/alcionai/corso/src/internal/connector/uploadsession"
|
||||||
@ -194,9 +195,9 @@ func oneDriveItemInfo(di models.DriveItemable, itemSize int64) *details.OneDrive
|
|||||||
|
|
||||||
return &details.OneDriveInfo{
|
return &details.OneDriveInfo{
|
||||||
ItemType: details.OneDriveItem,
|
ItemType: details.OneDriveItem,
|
||||||
ItemName: *di.GetName(),
|
ItemName: ptr.Val(di.GetName()),
|
||||||
Created: *di.GetCreatedDateTime(),
|
Created: ptr.Val(di.GetCreatedDateTime()),
|
||||||
Modified: *di.GetLastModifiedDateTime(),
|
Modified: ptr.Val(di.GetLastModifiedDateTime()),
|
||||||
DriveName: parent,
|
DriveName: parent,
|
||||||
Size: itemSize,
|
Size: itemSize,
|
||||||
Owner: email,
|
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,
|
// TODO: we rely on this info for details/restore lookups,
|
||||||
// so if it's nil we have an issue, and will need an alternative
|
// so if it's nil we have an issue, and will need an alternative
|
||||||
// way to source the data.
|
// way to source the data.
|
||||||
|
|
||||||
gsi := di.GetSharepointIds()
|
gsi := di.GetSharepointIds()
|
||||||
if gsi != nil {
|
if gsi != nil {
|
||||||
if gsi.GetSiteId() != nil {
|
id = ptr.Val(gsi.GetSiteId())
|
||||||
id = *gsi.GetSiteId()
|
url = ptr.Val(gsi.GetSiteUrl())
|
||||||
}
|
|
||||||
|
|
||||||
if gsi.GetSiteUrl() != nil {
|
if len(url) == 0 {
|
||||||
url = *gsi.GetSiteUrl()
|
url = constructWebURL(di.GetAdditionalData())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if reference != nil {
|
if reference != nil {
|
||||||
parent = *reference.GetDriveId()
|
parent = ptr.Val(reference.GetDriveId())
|
||||||
|
temp := ptr.Val(reference.GetName())
|
||||||
|
temp = strings.TrimSpace(temp)
|
||||||
|
|
||||||
if reference.GetName() != nil {
|
if temp != "" {
|
||||||
// EndPoint is not always populated from external apps
|
parent = temp
|
||||||
temp := *reference.GetName()
|
|
||||||
temp = strings.TrimSpace(temp)
|
|
||||||
|
|
||||||
if temp != "" {
|
|
||||||
parent = temp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &details.SharePointInfo{
|
return &details.SharePointInfo{
|
||||||
ItemType: details.OneDriveItem,
|
ItemType: details.OneDriveItem,
|
||||||
ItemName: *di.GetName(),
|
ItemName: ptr.Val(di.GetName()),
|
||||||
Created: *di.GetCreatedDateTime(),
|
Created: ptr.Val(di.GetCreatedDateTime()),
|
||||||
Modified: *di.GetLastModifiedDateTime(),
|
Modified: ptr.Val(di.GetLastModifiedDateTime()),
|
||||||
DriveName: parent,
|
DriveName: parent,
|
||||||
Size: itemSize,
|
Size: itemSize,
|
||||||
Owner: id,
|
Owner: id,
|
||||||
@ -344,3 +341,36 @@ func driveItemWriter(
|
|||||||
|
|
||||||
return uploadsession.NewWriter(itemID, url, itemSize), nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user