Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fix backup of Groups without an associated Team (#4520)
Browse files Browse the repository at this point in the history
Previously we were trying to fetch channels of Groups without channels.

---

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

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

#### Type of change

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

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* closes #4519

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [ ] ⚡ Unit test
- [x] 💚 E2E
  • Loading branch information
meain authored Oct 17, 2023
1 parent d10b1a3 commit 08e8b18
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cli/backup/groups_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/internal/m365/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down Expand Up @@ -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}
)
Expand Down
2 changes: 1 addition & 1 deletion src/internal/m365/collection/groups/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
Expand Down
4 changes: 2 additions & 2 deletions src/internal/tester/tconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/internal/tester/tconfig/protected_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
13 changes: 13 additions & 0 deletions src/pkg/services/m365/api/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions src/pkg/services/m365/api/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
13 changes: 8 additions & 5 deletions src/pkg/services/m365/api/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 08e8b18

Please sign in to comment.