diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b3f7690..06d7a09ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Email size metadata was incorrectly set to the size of the last attachment. Emails will now correctly report the size of the mail content plus the size of all attachments. - Improves the filtering capabilities for Groups restore and backup - Improve check to skip OneNote files that cannot be downloaded. +- Fix Groups backup for non Team groups ### Changed - Groups restore now expects the site whose backup we should restore diff --git a/src/cli/backup/groups_e2e_test.go b/src/cli/backup/groups_e2e_test.go index 87ef93d2b..5a38a4b94 100644 --- a/src/cli/backup/groups_e2e_test.go +++ b/src/cli/backup/groups_e2e_test.go @@ -517,7 +517,7 @@ func (suite *BackupDeleteGroupsE2ESuite) SetupSuite() { suite.dpnd = prepM365Test(t, ctx, path.GroupsService) - m365GroupID := tconfig.M365GroupID(t) + m365GroupID := tconfig.M365TeamID(t) groups := []string{m365GroupID} // some tests require an existing backup diff --git a/src/internal/m365/backup_test.go b/src/internal/m365/backup_test.go index b5efb4d4c..e17915dcc 100644 --- a/src/internal/m365/backup_test.go +++ b/src/internal/m365/backup_test.go @@ -511,7 +511,7 @@ func (suite *GroupsCollectionIntgSuite) TestCreateGroupsCollection_SharePoint() defer flush() var ( - groupID = tconfig.M365GroupID(t) + groupID = tconfig.M365TeamID(t) ctrl = newController(ctx, t, path.GroupsService) groupIDs = []string{groupID} ) @@ -585,7 +585,7 @@ func (suite *GroupsCollectionIntgSuite) TestCreateGroupsCollection_SharePoint_In defer flush() var ( - groupID = tconfig.M365GroupID(t) + groupID = tconfig.M365TeamID(t) ctrl = newController(ctx, t, path.GroupsService) groupIDs = []string{groupID} ) diff --git a/src/internal/m365/collection/groups/backup_test.go b/src/internal/m365/collection/groups/backup_test.go index a372922ba..972688595 100644 --- a/src/internal/m365/collection/groups/backup_test.go +++ b/src/internal/m365/collection/groups/backup_test.go @@ -470,7 +470,7 @@ func (suite *BackupIntgSuite) SetupSuite() { func (suite *BackupIntgSuite) TestCreateCollections() { var ( - protectedResource = tconfig.M365GroupID(suite.T()) + protectedResource = tconfig.M365TeamID(suite.T()) resources = []string{protectedResource} handler = NewChannelBackupHandler(protectedResource, suite.ac.Channels()) ) diff --git a/src/internal/tester/tconfig/config.go b/src/internal/tester/tconfig/config.go index 623dc1282..1c23d6316 100644 --- a/src/internal/tester/tconfig/config.go +++ b/src/internal/tester/tconfig/config.go @@ -184,13 +184,13 @@ func ReadTestConfig() (map[string]string, error) { TestCfgGroupID, os.Getenv(EnvCorsoM365TestGroupID), vpr.GetString(TestCfgGroupID), - "6f24b40d-b13d-4752-980f-f5fb9fba7aa0") + "87d622a5-fb64-4fa4-a324-3dd620afe0bd") // CINonTeamGroup (create one without teams) fallbackTo( testEnv, TestCfgSecondaryGroupID, os.Getenv(EnvCorsoSecondaryM365TestGroupID), vpr.GetString(TestCfgSecondaryGroupID), - "20cda3c0-6f9a-4286-9f2f-bb284e1f79c9") + "cd260eff-834f-4cc3-b3bf-0aad1c9b8b7e") // CINonTeamGroup2 (create one without teams) fallbackTo( testEnv, TestCfgSiteURL, diff --git a/src/internal/tester/tconfig/protected_resources.go b/src/internal/tester/tconfig/protected_resources.go index 2bf68a159..563293128 100644 --- a/src/internal/tester/tconfig/protected_resources.go +++ b/src/internal/tester/tconfig/protected_resources.go @@ -278,9 +278,10 @@ func SecondaryM365TeamID(t *testing.T) string { // by either the env var CORSO_M365_TEST_GROUP_ID, the corso_test.toml config // file or the default value (in that order of priority). The default is a // last-attempt fallback that will only work on alcion's testing org. +// NOTE: This Group will not have a Team associated with it. func M365GroupID(t *testing.T) string { cfg, err := ReadTestConfig() require.NoError(t, err, "retrieving m365 group id from test configuration: %+v", clues.ToCore(err)) - return strings.ToLower(cfg[TestCfgTeamID]) + return strings.ToLower(cfg[TestCfgGroupID]) } diff --git a/src/pkg/services/m365/api/groups.go b/src/pkg/services/m365/api/groups.go index 4dcba24e0..68e0277d9 100644 --- a/src/pkg/services/m365/api/groups.go +++ b/src/pkg/services/m365/api/groups.go @@ -182,6 +182,19 @@ func (c Groups) GetAllSites( sites := []models.Siteable{root} + group, err := c.Groups().GetByID( + ctx, + identifier, + CallConfig{}) + if err != nil { + return nil, clues.Wrap(err, "getting group").WithClues(ctx) + } + + isTeam := IsTeam(ctx, group) + if !isTeam { + return sites, nil + } + channels, err := Channels(c).GetChannels(ctx, identifier) if err != nil { return nil, clues.Wrap(err, "getting channels") diff --git a/src/pkg/services/m365/api/groups_test.go b/src/pkg/services/m365/api/groups_test.go index 213bb5d81..41e516b90 100644 --- a/src/pkg/services/m365/api/groups_test.go +++ b/src/pkg/services/m365/api/groups_test.go @@ -137,6 +137,24 @@ func (suite *GroupsIntgSuite) TestGetAllSites() { require.Equal(t, siteCount, len(sites), "incorrect number of sites") } +// GetAllSites for Groups that are not Teams should return just the root site +func (suite *GroupsIntgSuite) TestGetAllSitesNonTeam() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + group, err := suite.its.ac.Groups().GetByID(ctx, suite.its.nonTeamGroup.id, api.CallConfig{}) + require.NoError(t, err) + require.False(t, api.IsTeam(ctx, group), "group should not be a team for this test") + + sites, err := suite.its.ac. + Groups(). + GetAllSites(ctx, suite.its.nonTeamGroup.id, fault.New(true)) + require.NoError(t, err) + require.Equal(t, 1, len(sites), "incorrect number of sites") +} + func (suite *GroupsIntgSuite) TestGroups_GetByID() { t := suite.T() diff --git a/src/pkg/services/m365/api/helper_test.go b/src/pkg/services/m365/api/helper_test.go index b3de4f43e..25976f5e1 100644 --- a/src/pkg/services/m365/api/helper_test.go +++ b/src/pkg/services/m365/api/helper_test.go @@ -83,11 +83,12 @@ type ids struct { } type intgTesterSetup struct { - ac api.Client - gockAC api.Client - user ids - site ids - group ids + ac api.Client + gockAC api.Client + user ids + site ids + group ids + nonTeamGroup ids // group which does not have an associated team } func newIntegrationTesterSetup(t *testing.T) intgTesterSetup { @@ -142,6 +143,8 @@ func newIntegrationTesterSetup(t *testing.T) intgTesterSetup { // the group has full usage of the teams api. its.group.id = tconfig.M365TeamID(t) + its.nonTeamGroup.id = tconfig.M365GroupID(t) + channel, err := its.ac.Channels(). GetChannelByName( ctx,