From 9f05e83d433fd9eff54ef70c6962f11e109ad864 Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 11 Jan 2023 07:49:20 -0500 Subject: [PATCH] CLI: Adds to the displayable headers for OneDrive and SharePoint. (#2090) ## Description The update adds `DriveName` to SharePoint details. Values are currently the M365ID ## Does this PR need a docs update or release note? - [x] :no_entry: No ## Type of change - [x] :sunflower: Feature ## Issue(s) * related to #1938 * related to #2064 ## Test Plan - [x] :zap: Unit test --- src/internal/connector/onedrive/item.go | 35 ++++++++++++++++++------- src/pkg/backup/details/details.go | 8 +++--- src/pkg/backup/details/details_test.go | 14 ++++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 7f377d2cd..73391033b 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "strings" msdrives "github.com/microsoftgraph/msgraph-sdk-go/drives" "github.com/microsoftgraph/msgraph-sdk-go/models" @@ -128,10 +129,11 @@ func oneDriveItemInfo(di models.DriveItemable, itemSize int64) *details.OneDrive // separately for restore processes because the local itemable // doesn't have its size value updated as a side effect of creation, // and kiota drops any SetSize update. +// TODO: Update drive name during Issue #2071 func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.SharePointInfo { var ( - id string - url string + id, parent, url string + reference = di.GetParentReference() ) // TODO: we rely on this info for details/restore lookups, @@ -148,14 +150,29 @@ func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.ShareP } } + if reference != nil { + parent = *reference.GetDriveId() + + if reference.GetName() != nil { + // EndPoint is not always populated from external apps + temp := *reference.GetName() + temp = strings.TrimSpace(temp) + + if temp != "" { + parent = temp + } + } + } + return &details.SharePointInfo{ - ItemType: details.OneDriveItem, - ItemName: *di.GetName(), - Created: *di.GetCreatedDateTime(), - Modified: *di.GetLastModifiedDateTime(), - Size: itemSize, - Owner: id, - WebURL: url, + ItemType: details.OneDriveItem, + ItemName: *di.GetName(), + Created: *di.GetCreatedDateTime(), + Modified: *di.GetLastModifiedDateTime(), + DriveName: parent, + Size: itemSize, + Owner: id, + WebURL: url, } } diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index 923410dde..d407ca690 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -477,6 +477,7 @@ func (i ExchangeInfo) Values() []string { type SharePointInfo struct { Created time.Time `json:"created,omitempty"` ItemName string `json:"itemName,omitempty"` + DriveName string `json:"driveName,omitempty"` ItemType ItemType `json:"itemType,omitempty"` Modified time.Time `josn:"modified,omitempty"` Owner string `json:"owner,omitempty"` @@ -488,7 +489,7 @@ type SharePointInfo struct { // Headers returns the human-readable names of properties in a SharePointInfo // for printing out to a terminal in a columnar display. func (i SharePointInfo) Headers() []string { - return []string{"ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"} + return []string{"ItemName", "Drive", "ParentPath", "Size", "WebURL", "Created", "Modified"} } // Values returns the values matching the Headers list for printing @@ -496,6 +497,7 @@ func (i SharePointInfo) Headers() []string { func (i SharePointInfo) Values() []string { return []string{ i.ItemName, + i.DriveName, i.ParentPath, humanize.Bytes(uint64(i.Size)), i.WebURL, @@ -518,8 +520,8 @@ func (i *SharePointInfo) UpdateParentPath(newPath path.Path) error { // OneDriveInfo describes a oneDrive item type OneDriveInfo struct { Created time.Time `json:"created,omitempty"` - ItemName string `json:"itemName"` - DriveName string `json:"driveName"` + ItemName string `json:"itemName,omitempty"` + DriveName string `json:"driveName,omitempty"` ItemType ItemType `json:"itemType,omitempty"` Modified time.Time `json:"modified,omitempty"` Owner string `json:"owner,omitempty"` diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index 328576e99..efc654246 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -107,13 +107,23 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { ParentPath: "parentPath", Size: 1000, WebURL: "https://not.a.real/url", + DriveName: "aDrive", Created: now, Modified: now, }, }, }, - expectHs: []string{"ID", "ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"}, - expectVs: []string{"deadbeef", "itemName", "parentPath", "1.0 kB", "https://not.a.real/url", nowStr, nowStr}, + expectHs: []string{"ID", "ItemName", "Drive", "ParentPath", "Size", "WebURL", "Created", "Modified"}, + expectVs: []string{ + "deadbeef", + "itemName", + "aDrive", + "parentPath", + "1.0 kB", + "https://not.a.real/url", + nowStr, + nowStr, + }, }, { name: "oneDrive info",