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 

## Type of change

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


## Issue(s)

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


## Test Plan
- [x]  Unit test
This commit is contained in:
Danny 2023-01-11 07:49:20 -05:00 committed by GitHub
parent 3869baac64
commit 9f05e83d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 14 deletions

View File

@ -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,11 +150,26 @@ 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(),
DriveName: parent,
Size: itemSize,
Owner: id,
WebURL: url,

View File

@ -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"`

View File

@ -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",