enables sharepoint lists backup and export (#5048)

enables sharepoint lists `backup` and `export`.
`restore` is enabled via `--allow-lists-restore` flag and is hidden in
CLI. So that it can be sanity-tested.

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [x] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)
#4754 

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Hitesh Pattanayak 2024-01-24 20:45:21 +05:30 committed by GitHub
parent b073c204c8
commit 19148e177c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 40 deletions

View File

@ -253,14 +253,12 @@ func (suite *SharePointUnitSuite) TestValidateSharePointBackupCreateFlags() {
cats: []string{"invalid category"}, cats: []string{"invalid category"},
expect: assert.Error, expect: assert.Error,
}, },
// [TODO](hitesh): Uncomment when lists are enabled {
name: "site with lists category",
// { site: []string{"smarf"},
// name: "site with lists category", cats: []string{flags.DataLists},
// site: []string{"smarf"}, expect: assert.NoError,
// cats: []string{flags.DataLists}, },
// expect: assert.NoError,
// },
// [TODO]: Uncomment when pages are enabled // [TODO]: Uncomment when pages are enabled

View File

@ -6,7 +6,6 @@ import (
"github.com/alcionai/corso/src/cli/flags" "github.com/alcionai/corso/src/cli/flags"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/pkg/selectors"
) )
// called by export.go to map subcommands to provider-specific handling. // called by export.go to map subcommands to provider-specific handling.
@ -87,9 +86,6 @@ func exportSharePointCmd(cmd *cobra.Command, args []string) error {
sel := utils.IncludeSharePointRestoreDataSelectors(ctx, opts) sel := utils.IncludeSharePointRestoreDataSelectors(ctx, opts)
utils.FilterSharePointRestoreInfoSelectors(sel, opts) utils.FilterSharePointRestoreInfoSelectors(sel, opts)
// Exclude lists from exports since they are not supported yet.
sel.Exclude(sel.Lists(selectors.Any()))
return runExport( return runExport(
ctx, ctx,
cmd, cmd,

View File

@ -18,6 +18,7 @@ const (
ListModifiedBeforeFN = "list-modified-before" ListModifiedBeforeFN = "list-modified-before"
ListCreatedAfterFN = "list-created-after" ListCreatedAfterFN = "list-created-after"
ListCreatedBeforeFN = "list-created-before" ListCreatedBeforeFN = "list-created-before"
AllowListsRestoreFN = "allow-lists-restore"
PageFolderFN = "page-folder" PageFolderFN = "page-folder"
PageFN = "page" PageFN = "page"
@ -34,6 +35,7 @@ var (
ListModifiedBeforeFV string ListModifiedBeforeFV string
ListCreatedAfterFV string ListCreatedAfterFV string
ListCreatedBeforeFV string ListCreatedBeforeFV string
AllowListsRestoreFV bool
PageFolderFV []string PageFolderFV []string
PageFV []string PageFV []string
@ -99,6 +101,11 @@ func AddSharePointDetailsAndRestoreFlags(cmd *cobra.Command) {
&ListCreatedBeforeFV, &ListCreatedBeforeFV,
ListCreatedBeforeFN, "", ListCreatedBeforeFN, "",
"Select lists created before this datetime.") "Select lists created before this datetime.")
fs.BoolVar(
&AllowListsRestoreFV,
AllowListsRestoreFN, false,
"enables lists restore if provided")
cobra.CheckErr(fs.MarkHidden(AllowListsRestoreFN))
// pages // pages

View File

@ -87,8 +87,10 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
sel := utils.IncludeSharePointRestoreDataSelectors(ctx, opts) sel := utils.IncludeSharePointRestoreDataSelectors(ctx, opts)
utils.FilterSharePointRestoreInfoSelectors(sel, opts) utils.FilterSharePointRestoreInfoSelectors(sel, opts)
// Exclude lists from restore since they are not supported yet. if !opts.AllowListsRestore {
sel.Exclude(sel.Lists(selectors.Any())) // Exclude lists from restore since they are not supported yet.
sel.Exclude(sel.Lists(selectors.Any()))
}
return runRestore( return runRestore(
ctx, ctx,

View File

@ -30,6 +30,7 @@ type SharePointOpts struct {
ListModifiedBefore string ListModifiedBefore string
ListCreatedBefore string ListCreatedBefore string
ListCreatedAfter string ListCreatedAfter string
AllowListsRestore bool
PageFolder []string PageFolder []string
Page []string Page []string
@ -81,6 +82,7 @@ func MakeSharePointOpts(cmd *cobra.Command) SharePointOpts {
ListModifiedBefore: flags.ListModifiedBeforeFV, ListModifiedBefore: flags.ListModifiedBeforeFV,
ListCreatedAfter: flags.ListCreatedAfterFV, ListCreatedAfter: flags.ListCreatedAfterFV,
ListCreatedBefore: flags.ListCreatedBeforeFV, ListCreatedBefore: flags.ListCreatedBeforeFV,
AllowListsRestore: flags.AllowListsRestoreFV,
Page: flags.PageFV, Page: flags.PageFV,
PageFolder: flags.PageFolderFV, PageFolder: flags.PageFolderFV,
@ -98,22 +100,19 @@ func MakeSharePointOpts(cmd *cobra.Command) SharePointOpts {
func SharePointAllowedCategories() map[string]struct{} { func SharePointAllowedCategories() map[string]struct{} {
return map[string]struct{}{ return map[string]struct{}{
flags.DataLibraries: {}, flags.DataLibraries: {},
// flags.DataLists: {}, [TODO]: uncomment when lists are enabled flags.DataLists: {},
} }
} }
func AddCategories(sel *selectors.SharePointBackup, cats []string) *selectors.SharePointBackup { func AddCategories(sel *selectors.SharePointBackup, cats []string) *selectors.SharePointBackup {
if len(cats) == 0 { if len(cats) == 0 {
// backup of sharepoint lists not enabled yet sel.Include(sel.LibraryFolders(selectors.Any()), sel.Lists(selectors.Any()))
// sel.Include(sel.LibraryFolders(selectors.Any()), sel.Lists(selectors.Any()))
sel.Include(sel.LibraryFolders(selectors.Any()))
} }
for _, d := range cats { for _, d := range cats {
switch d { switch d {
// backup of sharepoint lists not enabled yet case flags.DataLists:
// case flags.DataLists: sel.Include(sel.Lists(selectors.Any()))
// sel.Include(sel.Lists(selectors.Any()))
case flags.DataLibraries: case flags.DataLibraries:
sel.Include(sel.LibraryFolders(selectors.Any())) sel.Include(sel.LibraryFolders(selectors.Any()))
} }

View File

@ -411,36 +411,35 @@ func (suite *SharePointUtilsSuite) TestValidateSharePointRestoreFlags() {
} }
} }
// [TODO]hitesh uncomment the test cases once sharepoint list backup is enabled
func (suite *SharePointUtilsSuite) TestAddSharepointCategories() { func (suite *SharePointUtilsSuite) TestAddSharepointCategories() {
table := []struct { table := []struct {
name string name string
cats []string cats []string
expectScopeLen int expectScopeLen int
}{ }{
// { {
// name: "none", name: "none",
// cats: []string{}, cats: []string{},
// expectScopeLen: 2, expectScopeLen: 2,
// }, },
{ {
name: "libraries", name: "libraries",
cats: []string{flags.DataLibraries}, cats: []string{flags.DataLibraries},
expectScopeLen: 1, expectScopeLen: 1,
}, },
// { {
// name: "lists", name: "lists",
// cats: []string{flags.DataLists}, cats: []string{flags.DataLists},
// expectScopeLen: 1, expectScopeLen: 1,
// }, },
// { {
// name: "all allowed", name: "all allowed",
// cats: []string{ cats: []string{
// flags.DataLibraries, flags.DataLibraries,
// flags.DataLists, flags.DataLists,
// }, },
// expectScopeLen: 2, expectScopeLen: 2,
// }, },
{ {
name: "bad inputs", name: "bad inputs",
cats: []string{"foo"}, cats: []string{"foo"},