GC: SharePoint: Library: Details: Change to Displayed data (#2632)
<!-- Insert PR description--> Updates for `./corso backup details sharepoint --backup <bID>` - Ensures that Drive Name is part of the backup - Adds field DisplayName to backup details #### 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. --> *closes #2601 <issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual
This commit is contained in:
parent
fe1f6ae5fb
commit
ad75540b03
@ -301,6 +301,13 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
|
||||
"backup_item_size", itemSize,
|
||||
)
|
||||
|
||||
pr, err := fetchParentReference(ctx, oc.service, item.GetParentReference())
|
||||
if err != nil {
|
||||
el.AddRecoverable(clues.Wrap(err, "getting parent reference").Label(fault.LabelForceNoBackupCreation))
|
||||
return
|
||||
}
|
||||
|
||||
item.SetParentReference(pr)
|
||||
isFile := item.GetFile() != nil
|
||||
|
||||
if isFile {
|
||||
|
||||
@ -284,7 +284,7 @@ func filterUserPermissions(perms []models.Permissionable) []UserPermission {
|
||||
// TODO: Update drive name during Issue #2071
|
||||
func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.SharePointInfo {
|
||||
var (
|
||||
id, parent, url string
|
||||
id, parentID, displayName, url string
|
||||
reference = di.GetParentReference()
|
||||
)
|
||||
|
||||
@ -303,13 +303,8 @@ func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.ShareP
|
||||
}
|
||||
|
||||
if reference != nil {
|
||||
parent = ptr.Val(reference.GetDriveId())
|
||||
temp := ptr.Val(reference.GetName())
|
||||
temp = strings.TrimSpace(temp)
|
||||
|
||||
if temp != "" {
|
||||
parent = temp
|
||||
}
|
||||
parentID = ptr.Val(reference.GetDriveId())
|
||||
displayName = strings.TrimSpace(ptr.Val(reference.GetName()))
|
||||
}
|
||||
|
||||
return &details.SharePointInfo{
|
||||
@ -317,7 +312,8 @@ func sharePointItemInfo(di models.DriveItemable, itemSize int64) *details.ShareP
|
||||
ItemName: ptr.Val(di.GetName()),
|
||||
Created: ptr.Val(di.GetCreatedDateTime()),
|
||||
Modified: ptr.Val(di.GetLastModifiedDateTime()),
|
||||
DriveName: parent,
|
||||
DriveName: parentID,
|
||||
DisplayName: displayName,
|
||||
Size: itemSize,
|
||||
Owner: id,
|
||||
WebURL: url,
|
||||
@ -382,3 +378,34 @@ func constructWebURL(adtl map[string]any) string {
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
func fetchParentReference(
|
||||
ctx context.Context,
|
||||
service graph.Servicer,
|
||||
orig models.ItemReferenceable,
|
||||
) (models.ItemReferenceable, error) {
|
||||
if orig == nil || service == nil || ptr.Val(orig.GetName()) != "" {
|
||||
return orig, nil
|
||||
}
|
||||
|
||||
options := &msdrives.DriveItemRequestBuilderGetRequestConfiguration{
|
||||
QueryParameters: &msdrives.DriveItemRequestBuilderGetQueryParameters{
|
||||
Select: []string{"name"},
|
||||
},
|
||||
}
|
||||
|
||||
driveID := ptr.Val(orig.GetDriveId())
|
||||
|
||||
if driveID == "" {
|
||||
return orig, nil
|
||||
}
|
||||
|
||||
drive, err := service.Client().DrivesById(driveID).Get(ctx, options)
|
||||
if err != nil {
|
||||
return nil, clues.Stack(err).WithClues(ctx).With(graph.ErrData(err)...)
|
||||
}
|
||||
|
||||
orig.SetName(drive.GetName())
|
||||
|
||||
return orig, nil
|
||||
}
|
||||
|
||||
@ -568,6 +568,7 @@ type SharePointInfo struct {
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
ItemName string `json:"itemName,omitempty"`
|
||||
DriveName string `json:"driveName,omitempty"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
ItemType ItemType `json:"itemType,omitempty"`
|
||||
Modified time.Time `josn:"modified,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
@ -587,7 +588,7 @@ func (i SharePointInfo) Headers() []string {
|
||||
func (i SharePointInfo) Values() []string {
|
||||
return []string{
|
||||
i.ItemName,
|
||||
i.DriveName,
|
||||
i.DisplayName,
|
||||
i.ParentPath,
|
||||
humanize.Bytes(uint64(i.Size)),
|
||||
i.WebURL,
|
||||
|
||||
@ -113,7 +113,7 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||
ParentPath: "parentPath",
|
||||
Size: 1000,
|
||||
WebURL: "https://not.a.real/url",
|
||||
DriveName: "aDrive",
|
||||
DisplayName: "aDrive",
|
||||
Created: now,
|
||||
Modified: now,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user