diff --git a/src/internal/m365/service/groups/backup.go b/src/internal/m365/service/groups/backup.go index 27f34f7b3..7dbbf8e13 100644 --- a/src/internal/m365/service/groups/backup.go +++ b/src/internal/m365/service/groups/backup.go @@ -55,7 +55,10 @@ func ProduceBackupCollections( "group_id", clues.Hide(bpc.ProtectedResource.ID()), "group_name", clues.Hide(bpc.ProtectedResource.Name())) - group, err := ac.Groups().GetByID(ctx, bpc.ProtectedResource.ID()) + group, err := ac.Groups().GetByID( + ctx, + bpc.ProtectedResource.ID(), + api.CallConfig{}) if err != nil { return nil, nil, false, clues.Wrap(err, "getting group").WithClues(ctx) } diff --git a/src/internal/m365/service/groups/enabled.go b/src/internal/m365/service/groups/enabled.go index 87acc8c48..4580746e5 100644 --- a/src/internal/m365/service/groups/enabled.go +++ b/src/internal/m365/service/groups/enabled.go @@ -7,18 +7,15 @@ import ( "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/alcionai/corso/src/pkg/filters" + "github.com/alcionai/corso/src/pkg/services/m365/api" ) -type getByIDer interface { - GetByID(ctx context.Context, identifier string) (models.Groupable, error) -} - func IsServiceEnabled( ctx context.Context, - gbi getByIDer, + gbi api.GetByIDer[models.Groupable], resource string, ) (bool, error) { - resp, err := gbi.GetByID(ctx, resource) + resp, err := gbi.GetByID(ctx, resource, api.CallConfig{}) if err != nil { return false, clues.Wrap(err, "getting group").WithClues(ctx) } diff --git a/src/internal/m365/service/groups/enabled_test.go b/src/internal/m365/service/groups/enabled_test.go index c2447982e..d032be415 100644 --- a/src/internal/m365/service/groups/enabled_test.go +++ b/src/internal/m365/service/groups/enabled_test.go @@ -12,6 +12,7 @@ import ( "github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/services/m365/api" ) type EnabledUnitSuite struct { @@ -22,14 +23,18 @@ func TestEnabledUnitSuite(t *testing.T) { suite.Run(t, &EnabledUnitSuite{Suite: tester.NewUnitSuite(t)}) } -var _ getByIDer = mockGBI{} +var _ api.GetByIDer[models.Groupable] = mockGBI{} type mockGBI struct { group models.Groupable err error } -func (m mockGBI) GetByID(ctx context.Context, identifier string) (models.Groupable, error) { +func (m mockGBI) GetByID( + ctx context.Context, + identifier string, + _ api.CallConfig, +) (models.Groupable, error) { return m.group, m.err } @@ -56,13 +61,13 @@ func (suite *EnabledUnitSuite) TestIsServiceEnabled() { table := []struct { name string - mock func(context.Context) getByIDer + mock func(context.Context) api.GetByIDer[models.Groupable] expect assert.BoolAssertionFunc expectErr assert.ErrorAssertionFunc }{ { name: "ok", - mock: func(ctx context.Context) getByIDer { + mock: func(ctx context.Context) api.GetByIDer[models.Groupable] { return mockGBI{ group: unified, } @@ -72,7 +77,7 @@ func (suite *EnabledUnitSuite) TestIsServiceEnabled() { }, { name: "non-unified group", - mock: func(ctx context.Context) getByIDer { + mock: func(ctx context.Context) api.GetByIDer[models.Groupable] { return mockGBI{ group: nonUnified, } @@ -82,7 +87,7 @@ func (suite *EnabledUnitSuite) TestIsServiceEnabled() { }, { name: "group not found", - mock: func(ctx context.Context) getByIDer { + mock: func(ctx context.Context) api.GetByIDer[models.Groupable] { return mockGBI{ err: graph.Stack(ctx, odErrMsg(string(graph.RequestResourceNotFound), "message")), } @@ -92,7 +97,7 @@ func (suite *EnabledUnitSuite) TestIsServiceEnabled() { }, { name: "arbitrary error", - mock: func(ctx context.Context) getByIDer { + mock: func(ctx context.Context) api.GetByIDer[models.Groupable] { return mockGBI{ err: assert.AnError, } diff --git a/src/pkg/services/m365/api/client.go b/src/pkg/services/m365/api/client.go index 64b00f3dd..04f490f12 100644 --- a/src/pkg/services/m365/api/client.go +++ b/src/pkg/services/m365/api/client.go @@ -126,3 +126,15 @@ func (c Client) Get( type CallConfig struct { Expand []string } + +// --------------------------------------------------------------------------- +// common interfaces +// --------------------------------------------------------------------------- + +type GetByIDer[T any] interface { + GetByID( + ctx context.Context, + identifier string, + cc CallConfig, + ) (T, error) +} diff --git a/src/pkg/services/m365/api/groups.go b/src/pkg/services/m365/api/groups.go index 73beb3d2b..2aacdedf0 100644 --- a/src/pkg/services/m365/api/groups.go +++ b/src/pkg/services/m365/api/groups.go @@ -102,6 +102,7 @@ const filterGroupByDisplayNameQueryTmpl = "displayName eq '%s'" func (c Groups) GetByID( ctx context.Context, identifier string, + _ CallConfig, // matching standards ) (models.Groupable, error) { service, err := c.Service() if err != nil { @@ -234,9 +235,9 @@ func IsTeam(ctx context.Context, mg models.Groupable) bool { func (c Groups) GetIDAndName( ctx context.Context, groupID string, - _ CallConfig, // not currently supported + cc CallConfig, ) (string, string, error) { - s, err := c.GetByID(ctx, groupID) + s, err := c.GetByID(ctx, groupID, cc) if err != nil { return "", "", err } diff --git a/src/pkg/services/m365/api/groups_test.go b/src/pkg/services/m365/api/groups_test.go index c00b64a13..b60240cff 100644 --- a/src/pkg/services/m365/api/groups_test.go +++ b/src/pkg/services/m365/api/groups_test.go @@ -121,7 +121,7 @@ func (suite *GroupsIntgSuite) TestGroups_GetByID() { groupsAPI = suite.its.ac.Groups() ) - grp, err := groupsAPI.GetByID(ctx, groupID) + grp, err := groupsAPI.GetByID(ctx, groupID, api.CallConfig{}) require.NoError(t, err, clues.ToCore(err)) table := []struct { @@ -157,7 +157,7 @@ func (suite *GroupsIntgSuite) TestGroups_GetByID() { ctx, flush := tester.NewContext(t) defer flush() - _, err := groupsAPI.GetByID(ctx, test.id) + _, err := groupsAPI.GetByID(ctx, test.id, api.CallConfig{}) test.expectErr(t, err, clues.ToCore(err)) }) } diff --git a/src/pkg/services/m365/groups.go b/src/pkg/services/m365/groups.go index a32195c1c..5255620a7 100644 --- a/src/pkg/services/m365/groups.go +++ b/src/pkg/services/m365/groups.go @@ -28,6 +28,27 @@ type Group struct { IsTeam bool } +// GroupByID retrieves a specific group. +func GroupByID( + ctx context.Context, + acct account.Account, + id string, +) (*Group, error) { + ac, err := makeAC(ctx, acct, path.GroupsService) + if err != nil { + return nil, clues.Stack(err).WithClues(ctx) + } + + cc := api.CallConfig{} + + g, err := ac.Groups().GetByID(ctx, id, cc) + if err != nil { + return nil, clues.Stack(err) + } + + return parseGroup(ctx, g) +} + // GroupsCompat returns a list of groups in the specified M365 tenant. func GroupsCompat(ctx context.Context, acct account.Account) ([]*Group, error) { errs := fault.New(true) diff --git a/src/pkg/services/m365/groups_test.go b/src/pkg/services/m365/groups_test.go index 7c2cd4183..02091d42b 100644 --- a/src/pkg/services/m365/groups_test.go +++ b/src/pkg/services/m365/groups_test.go @@ -41,6 +41,24 @@ func (suite *GroupsIntgSuite) SetupSuite() { suite.acct = tconfig.NewM365Account(t) } +func (suite *GroupsIntgSuite) TestGroupByID() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + graph.InitializeConcurrencyLimiter(ctx, true, 4) + + gid := tconfig.M365TeamID(t) + + group, err := m365.GroupByID(ctx, suite.acct, gid) + require.NoError(t, err, clues.ToCore(err)) + require.NotNil(t, group) + + assert.Equal(t, gid, group.ID, "must match expected id") + assert.NotEmpty(t, group.DisplayName) +} + func (suite *GroupsIntgSuite) TestGroups() { t := suite.T()