From 8f556c59a4fe0564893a9d5f841854d62f6bafdc Mon Sep 17 00:00:00 2001 From: Danny Adams Date: Sat, 21 Jan 2023 17:41:21 -0500 Subject: [PATCH 1/5] Update to /pkg/selectors/sharepoint.go Bug fix: SharePoint selector misalignmet that causes panic on details command. --- src/pkg/selectors/sharepoint.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/selectors/sharepoint.go b/src/pkg/selectors/sharepoint.go index 3c47c847b..7138acd6c 100644 --- a/src/pkg/selectors/sharepoint.go +++ b/src/pkg/selectors/sharepoint.go @@ -224,7 +224,7 @@ func (s *sharePoint) AllData() []SharePointScope { scopes, makeScope[SharePointScope](SharePointLibrary, Any()), makeScope[SharePointScope](SharePointList, Any()), - makeScope[SharePointScope](SharePointPage, Any()), + makeScope[SharePointScope](SharePointPageFolder, Any()), ) return scopes @@ -323,7 +323,7 @@ func (s *sharePoint) PageItems(pages, items []string, opts ...option) []SharePoi scopes = append( scopes, makeScope[SharePointScope](SharePointPage, items). - set(SharePointPage, pages, opts...), + set(SharePointPageFolder, pages, opts...), ) return scopes From d22d943befb815bf90e2f2c97ae19a2da86773aa Mon Sep 17 00:00:00 2001 From: Danny Adams Date: Sat, 21 Jan 2023 18:07:06 -0500 Subject: [PATCH 2/5] Updates to pkg/selectors/sharepoint_test.go Adds tests to ensure function is checked for details command. --- src/pkg/selectors/sharepoint_test.go | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/pkg/selectors/sharepoint_test.go b/src/pkg/selectors/sharepoint_test.go index b9334a492..10a985033 100644 --- a/src/pkg/selectors/sharepoint_test.go +++ b/src/pkg/selectors/sharepoint_test.go @@ -196,6 +196,8 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { item = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderA/folderB", "item") item2 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderA/folderC", "item2") item3 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderD/folderE", "item3") + item4 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", "folderG/folderH", "item4") + item5 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", "folderG/folderH", "item5") ) deets := &details.Details{ @@ -225,6 +227,22 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { }, }, }, + { + RepoRef: item4, + ItemInfo: details.ItemInfo{ + SharePoint: &details.SharePointInfo{ + ItemType: details.SharePointItem, + }, + }, + }, + { + RepoRef: item5, + ItemInfo: details.ItemInfo{ + SharePoint: &details.SharePointInfo{ + ItemType: details.SharePointItem, + }, + }, + }, }, }, } @@ -247,7 +265,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { odr.Include(odr.AllData()) return odr }, - expect: arr(item, item2, item3), + expect: arr(item, item2, item3, item4, item5), }, { name: "only match item", @@ -269,6 +287,16 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { }, expect: arr(item, item2), }, + { + name: "pages match folder", + deets: deets, + makeSelector: func() *SharePointRestore { + odr := NewSharePointRestore([]string{"sid"}) + odr.Include(odr.Pages([]string{"folderG/folderH", "folderA/folderC"})) + return odr + }, + expect: arr(item4, item5), + }, } for _, test := range table { suite.T().Run(test.name, func(t *testing.T) { From 0b7d22581b3030cc070fd89dfbc61378ee078679 Mon Sep 17 00:00:00 2001 From: Danny Adams Date: Sat, 21 Jan 2023 18:30:15 -0500 Subject: [PATCH 3/5] Update to pkg/selectors/sharepoint_test.go Use of constant for literal. --- src/pkg/selectors/sharepoint_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pkg/selectors/sharepoint_test.go b/src/pkg/selectors/sharepoint_test.go index 10a985033..34aabb2c5 100644 --- a/src/pkg/selectors/sharepoint_test.go +++ b/src/pkg/selectors/sharepoint_test.go @@ -193,8 +193,9 @@ func (suite *SharePointSelectorSuite) TestToSharePointRestore() { func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { var ( + pairA = "folderA/folderC" item = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderA/folderB", "item") - item2 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderA/folderC", "item2") + item2 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", pairA, "item2") item3 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", "folderD/folderE", "item3") item4 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", "folderG/folderH", "item4") item5 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", "folderG/folderH", "item5") @@ -282,7 +283,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { deets: deets, makeSelector: func() *SharePointRestore { odr := NewSharePointRestore([]string{"sid"}) - odr.Include(odr.Libraries([]string{"folderA/folderB", "folderA/folderC"})) + odr.Include(odr.Libraries([]string{"folderA/folderB", pairA})) return odr }, expect: arr(item, item2), @@ -292,7 +293,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { deets: deets, makeSelector: func() *SharePointRestore { odr := NewSharePointRestore([]string{"sid"}) - odr.Include(odr.Pages([]string{"folderG/folderH", "folderA/folderC"})) + odr.Include(odr.Pages([]string{"folderG/folderH", pairA})) return odr }, expect: arr(item4, item5), From 156e01b8dd328d5fb0ed5126cde5df8f97f644d5 Mon Sep 17 00:00:00 2001 From: Danny Adams Date: Sun, 22 Jan 2023 02:12:21 -0500 Subject: [PATCH 4/5] Updates to /cli/restore/sharepoint.go Issue #2218: Connects CLI for SharePoint restore. --- src/cli/restore/sharepoint.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index 1c3a81e89..c21a152ea 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -18,6 +18,8 @@ import ( var ( listItems []string listPaths []string + pageFolders []string + pages []string libraryItems []string libraryPaths []string site []string @@ -76,6 +78,18 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { utils.ListItemFN, nil, "Restore list items by ID") + fs.StringSliceVar( + &pageFolders, + utils.PageFN, nil, + "Restore Site pages by SharePoint Site ID", + ) + + fs.StringSliceVar( + &pages, + utils.PageItemFN, nil, + "Restore site pages by file name(s)", + ) + // sharepoint info flags // fs.StringVar( @@ -131,6 +145,8 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error { ListPaths: listPaths, LibraryItems: libraryItems, LibraryPaths: libraryPaths, + PageFolders: pageFolders, + Pages: pages, Sites: site, WebURLs: weburl, // FileCreatedAfter: fileCreatedAfter, From 5414c71581c3cd12499e4eb6cf934bbd78464a1f Mon Sep 17 00:00:00 2001 From: Danny Adams Date: Wed, 25 Jan 2023 05:49:29 -0500 Subject: [PATCH 5/5] Updates to cli package per PR Request. Flags changed to page-folders and pages respectively. --- src/cli/backup/sharepoint.go | 4 ++-- src/cli/restore/sharepoint.go | 4 ++-- src/cli/utils/sharepoint.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/backup/sharepoint.go b/src/cli/backup/sharepoint.go index 4eb62dca0..ddfca934f 100644 --- a/src/cli/backup/sharepoint.go +++ b/src/cli/backup/sharepoint.go @@ -139,12 +139,12 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { fs.StringSliceVar( &pageFolders, - utils.PageFN, nil, + utils.PageFolderFN, nil, "Select backup data by site ID; accepts '"+utils.Wildcard+"' to select all sites.") fs.StringSliceVar( &page, - utils.PageItemFN, nil, + utils.PagesFN, nil, "Select backup data by file name; accepts '"+utils.Wildcard+"' to select all pages within the site.", ) diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index c21a152ea..1ce4b2b91 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -80,13 +80,13 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { fs.StringSliceVar( &pageFolders, - utils.PageFN, nil, + utils.PageFolderFN, nil, "Restore Site pages by SharePoint Site ID", ) fs.StringSliceVar( &pages, - utils.PageItemFN, nil, + utils.PagesFN, nil, "Restore site pages by file name(s)", ) diff --git a/src/cli/utils/sharepoint.go b/src/cli/utils/sharepoint.go index 291858b30..fb9d39533 100644 --- a/src/cli/utils/sharepoint.go +++ b/src/cli/utils/sharepoint.go @@ -11,8 +11,8 @@ const ( LibraryFN = "library" ListItemFN = "list-item" ListFN = "list" - PageFN = "page" - PageItemFN = "page-item" + PageFolderFN = "page-folders" + PagesFN = "pages" WebURLFN = "web-url" )