From 3706ae6c14204d585d4d21844634ae24da0f1dcf Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 11 Sep 2023 13:44:15 +0530 Subject: [PATCH] Handle groups without SharePoint sites (#4095) Security groups will not have an associated site. This avoids trying to backup the site if we get an error that the site is not available. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [x] :broom: Tech Debt/Cleanup #### Issue(s) * https://github.com/alcionai/corso/issues/3990 #### Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/m365/service/groups/backup.go | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/internal/m365/service/groups/backup.go b/src/internal/m365/service/groups/backup.go index 9f3551cf4..b38a5d684 100644 --- a/src/internal/m365/service/groups/backup.go +++ b/src/internal/m365/service/groups/backup.go @@ -4,6 +4,7 @@ import ( "context" "github.com/alcionai/clues" + "golang.org/x/exp/slices" "github.com/alcionai/corso/src/internal/common/idname" "github.com/alcionai/corso/src/internal/common/prefixmatcher" @@ -20,6 +21,7 @@ import ( "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/backup/metadata" "github.com/alcionai/corso/src/pkg/fault" + "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -51,6 +53,27 @@ func ProduceBackupCollections( "group_id", clues.Hide(bpc.ProtectedResource.ID()), "group_name", clues.Hide(bpc.ProtectedResource.Name())) + resp, err := ac.Groups().GetByID(ctx, bpc.ProtectedResource.ID()) + if err != nil { + return nil, nil, false, clues.Wrap(err, "getting group").WithClues(ctx) + } + + // Not all groups will have associated SharePoint + // sites. Distribution channels and Security groups will not + // have one. This check is to skip those groups. + groupTypes := resp.GetGroupTypes() + hasSharePoint := slices.Contains(groupTypes, "Unified") + + // If we don't have SharePoint site, there is nothing here to + // backup as of now. + if !hasSharePoint { + logger.Ctx(ctx). + With("group_id", bpc.ProtectedResource.ID()). + Infof("No SharePoint site found for group") + + return nil, nil, false, clues.Stack(graph.ErrServiceNotEnabled, err).WithClues(ctx) + } + for _, scope := range b.Scopes() { if el.Failure() != nil { break