diff --git a/src/cli/backup/groups.go b/src/cli/backup/groups.go index 4aae07a1f..f2ad9bec8 100644 --- a/src/cli/backup/groups.go +++ b/src/cli/backup/groups.go @@ -162,7 +162,7 @@ func createGroupsCmd(cmd *cobra.Command, args []string) error { return Only(ctx, clues.Stack(err)) } - ins, err := svcCli.GroupsMap(ctx, errs) + ins, err := svcCli.AC.Groups().GetAllIDsAndNames(ctx, errs) if err != nil { return Only(ctx, clues.Wrap(err, "Failed to retrieve M365 groups")) } diff --git a/src/pkg/services/m365/api/groups_test.go b/src/pkg/services/m365/api/groups_test.go index f48496484..e3f19f7c7 100644 --- a/src/pkg/services/m365/api/groups_test.go +++ b/src/pkg/services/m365/api/groups_test.go @@ -233,6 +233,30 @@ func (suite *GroupsIntgSuite) TestGroups_GetByID() { } } +func (suite *GroupsIntgSuite) TestGroups_GetAllIDsAndNames() { + t := suite.T() + groupsAPI := suite.its.ac.Groups() + + ctx, flush := tester.NewContext(t) + defer flush() + + gm, err := groupsAPI.GetAllIDsAndNames(ctx, fault.New(true)) + assert.NoError(t, err, clues.ToCore(err)) + assert.NotEmpty(t, gm) + + for _, gid := range gm.IDs() { + suite.Run("group_"+gid, func() { + t := suite.T() + + assert.NotEmpty(t, gid) + + name, ok := gm.NameOf(gid) + assert.True(t, ok) + assert.NotEmpty(t, name) + }) + } +} + func (suite *GroupsIntgSuite) TestGroups_GetByID_mockResourceLockedErrs() { gID := uuid.NewString() diff --git a/src/pkg/services/m365/groups.go b/src/pkg/services/m365/groups.go index a19161d23..a7e0cff6a 100644 --- a/src/pkg/services/m365/groups.go +++ b/src/pkg/services/m365/groups.go @@ -6,7 +6,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/alcionai/corso/src/internal/common/idname" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/services/m365/api" @@ -33,7 +32,7 @@ func (c client) GroupByID( ) (*Group, error) { cc := api.CallConfig{} - g, err := c.ac.Groups().GetByID(ctx, id, cc) + g, err := c.AC.Groups().GetByID(ctx, id, cc) if err != nil { return nil, clues.Stack(err) } @@ -50,7 +49,7 @@ func (c client) TeamByID( ) (*Group, error) { cc := api.CallConfig{} - g, err := c.ac.Groups().GetTeamByID(ctx, id, cc) + g, err := c.AC.Groups().GetTeamByID(ctx, id, cc) if err != nil { return nil, clues.Stack(err) } @@ -75,7 +74,7 @@ func (c client) Groups( ctx context.Context, errs *fault.Bus, ) ([]*Group, error) { - return getAllGroups(ctx, c.ac.Groups()) + return getAllGroups(ctx, c.AC.Groups()) } func getAllGroups( @@ -106,7 +105,7 @@ func (c client) SitesInGroup( groupID string, errs *fault.Bus, ) ([]*Site, error) { - sites, err := c.ac.Groups().GetAllSites(ctx, groupID, errs) + sites, err := c.AC.Groups().GetAllSites(ctx, groupID, errs) if err != nil { return nil, clues.Stack(err) } @@ -155,22 +154,3 @@ func parseGroupFromTeamable(ctx context.Context, mg models.Teamable) (*Group, er return u, nil } - -// GroupsMap retrieves an id-name cache of all groups in the tenant. -func (c client) GroupsMap( - ctx context.Context, - errs *fault.Bus, -) (idname.Cacher, error) { - groups, err := c.Groups(ctx, errs) - if err != nil { - return idname.NewCache(nil), err - } - - itn := make(map[string]string, len(groups)) - - for _, s := range groups { - itn[s.ID] = s.DisplayName - } - - return idname.NewCache(itn), nil -} diff --git a/src/pkg/services/m365/groups_test.go b/src/pkg/services/m365/groups_test.go index a76753782..643ea4dec 100644 --- a/src/pkg/services/m365/groups_test.go +++ b/src/pkg/services/m365/groups_test.go @@ -149,26 +149,3 @@ func (suite *GroupsIntgSuite) TestSitesInGroup() { assert.NoError(t, err, clues.ToCore(err)) assert.NotEmpty(t, sites) } - -func (suite *GroupsIntgSuite) TestGroupsMap() { - t := suite.T() - - ctx, flush := tester.NewContext(t) - defer flush() - - gm, err := suite.cli.GroupsMap(ctx, fault.New(true)) - assert.NoError(t, err, clues.ToCore(err)) - assert.NotEmpty(t, gm) - - for _, gid := range gm.IDs() { - suite.Run("group_"+gid, func() { - t := suite.T() - - assert.NotEmpty(t, gid) - - name, ok := gm.NameOf(gid) - assert.True(t, ok) - assert.NotEmpty(t, name) - }) - } -} diff --git a/src/pkg/services/m365/m365.go b/src/pkg/services/m365/m365.go index a7cfcf1c0..372bca816 100644 --- a/src/pkg/services/m365/m365.go +++ b/src/pkg/services/m365/m365.go @@ -15,7 +15,7 @@ import ( ) type client struct { - ac api.Client + AC api.Client } func NewM365Client( diff --git a/src/pkg/services/m365/sites.go b/src/pkg/services/m365/sites.go index fc3d3666d..d9f57ff19 100644 --- a/src/pkg/services/m365/sites.go +++ b/src/pkg/services/m365/sites.go @@ -59,7 +59,7 @@ func (c client) SiteByID( Expand: []string{"drive"}, } - return getSiteByID(ctx, c.ac.Sites(), id, cc) + return getSiteByID(ctx, c.AC.Sites(), id, cc) } func getSiteByID( @@ -78,7 +78,7 @@ func getSiteByID( // Sites returns a list of Sites in a specified M365 tenant func (c client) Sites(ctx context.Context, errs *fault.Bus) ([]*Site, error) { - return getAllSites(ctx, c.ac.Sites()) + return getAllSites(ctx, c.AC.Sites()) } func getAllSites( diff --git a/src/pkg/services/m365/users.go b/src/pkg/services/m365/users.go index cd8df7743..c609be5f9 100644 --- a/src/pkg/services/m365/users.go +++ b/src/pkg/services/m365/users.go @@ -28,7 +28,7 @@ type UserNoInfo struct { func (c client) UsersCompatNoInfo(ctx context.Context) ([]*UserNoInfo, error) { errs := fault.New(true) - us, err := usersNoInfo(ctx, c.ac, errs) + us, err := usersNoInfo(ctx, c.AC, errs) if err != nil { return nil, err } @@ -39,20 +39,20 @@ func (c client) UsersCompatNoInfo(ctx context.Context) ([]*UserNoInfo, error) { // UserHasMailbox returns true if the user has an exchange mailbox enabled // false otherwise, and a nil pointer and an error in case of error func (c client) UserHasMailbox(ctx context.Context, userID string) (bool, error) { - return exchange.IsServiceEnabled(ctx, c.ac.Users(), userID) + return exchange.IsServiceEnabled(ctx, c.AC.Users(), userID) } func (c client) UserGetMailboxInfo( ctx context.Context, userID string, ) (api.MailboxInfo, error) { - return exchange.GetMailboxInfo(ctx, c.ac.Users(), userID) + return exchange.GetMailboxInfo(ctx, c.AC.Users(), userID) } // UserHasDrives returns true if the user has any drives // false otherwise, and a nil pointer and an error in case of error func (c client) UserHasDrives(ctx context.Context, userID string) (bool, error) { - return onedrive.IsServiceEnabled(ctx, c.ac.Users(), userID) + return onedrive.IsServiceEnabled(ctx, c.AC.Users(), userID) } // usersNoInfo returns a list of users in the specified M365 tenant - with no info @@ -87,7 +87,7 @@ func usersNoInfo( } func (c client) UserAssignedLicenses(ctx context.Context, userID string) (int, error) { - us, err := c.ac.Users().GetByID( + us, err := c.AC.Users().GetByID( ctx, userID, api.CallConfig{Select: api.SelectProps("assignedLicenses")})