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"},
expect: assert.Error,
},
// [TODO](hitesh): Uncomment when lists are enabled
// {
// name: "site with lists category",
// site: []string{"smarf"},
// cats: []string{flags.DataLists},
// expect: assert.NoError,
// },
{
name: "site with lists category",
site: []string{"smarf"},
cats: []string{flags.DataLists},
expect: assert.NoError,
},
// [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/utils"
"github.com/alcionai/corso/src/pkg/selectors"
)
// 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)
utils.FilterSharePointRestoreInfoSelectors(sel, opts)
// Exclude lists from exports since they are not supported yet.
sel.Exclude(sel.Lists(selectors.Any()))
return runExport(
ctx,
cmd,

View File

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

View File

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

View File

@ -30,6 +30,7 @@ type SharePointOpts struct {
ListModifiedBefore string
ListCreatedBefore string
ListCreatedAfter string
AllowListsRestore bool
PageFolder []string
Page []string
@ -81,6 +82,7 @@ func MakeSharePointOpts(cmd *cobra.Command) SharePointOpts {
ListModifiedBefore: flags.ListModifiedBeforeFV,
ListCreatedAfter: flags.ListCreatedAfterFV,
ListCreatedBefore: flags.ListCreatedBeforeFV,
AllowListsRestore: flags.AllowListsRestoreFV,
Page: flags.PageFV,
PageFolder: flags.PageFolderFV,
@ -98,22 +100,19 @@ func MakeSharePointOpts(cmd *cobra.Command) SharePointOpts {
func SharePointAllowedCategories() map[string]struct{} {
return map[string]struct{}{
flags.DataLibraries: {},
// flags.DataLists: {}, [TODO]: uncomment when lists are enabled
flags.DataLists: {},
}
}
func AddCategories(sel *selectors.SharePointBackup, cats []string) *selectors.SharePointBackup {
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.Include(sel.LibraryFolders(selectors.Any()), sel.Lists(selectors.Any()))
}
for _, d := range cats {
switch d {
// backup of sharepoint lists not enabled yet
// case flags.DataLists:
// sel.Include(sel.Lists(selectors.Any()))
case flags.DataLists:
sel.Include(sel.Lists(selectors.Any()))
case flags.DataLibraries:
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() {
table := []struct {
name string
cats []string
expectScopeLen int
}{
// {
// name: "none",
// cats: []string{},
// expectScopeLen: 2,
// },
{
name: "none",
cats: []string{},
expectScopeLen: 2,
},
{
name: "libraries",
cats: []string{flags.DataLibraries},
expectScopeLen: 1,
},
// {
// name: "lists",
// cats: []string{flags.DataLists},
// expectScopeLen: 1,
// },
// {
// name: "all allowed",
// cats: []string{
// flags.DataLibraries,
// flags.DataLists,
// },
// expectScopeLen: 2,
// },
{
name: "lists",
cats: []string{flags.DataLists},
expectScopeLen: 1,
},
{
name: "all allowed",
cats: []string{
flags.DataLibraries,
flags.DataLists,
},
expectScopeLen: 2,
},
{
name: "bad inputs",
cats: []string{"foo"},