Drop GroupsMap in favor of api.GetAllIDsAndNames (#4967)
Follow up from https://github.com/alcionai/corso/pull/4955#discussion_r1440922835 --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [ ] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
ca50b1e908
commit
a3d573973e
@ -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"))
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type client struct {
|
||||
ac api.Client
|
||||
AC api.Client
|
||||
}
|
||||
|
||||
func NewM365Client(
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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")})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user