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

Commit

Permalink
expose sitesInGroup to sdk consumers (#4532)
Browse files Browse the repository at this point in the history
exposes the m365 api call to get all sites in a group to the sdk service interface.

---

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

- [x] ⛔ No

#### Type of change

- [x] 🌻 Feature

#### Test Plan

- [x] ⚡ Unit test
- [x] 💚 E2E
  • Loading branch information
ryanfkeepers authored Oct 24, 2023
1 parent 5cc68e2 commit 9e40d88
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
29 changes: 27 additions & 2 deletions src/pkg/services/m365/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GroupByID(
) (*Group, error) {
ac, err := makeAC(ctx, acct, path.GroupsService)
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
return nil, clues.Stack(err)
}

cc := api.CallConfig{}
Expand Down Expand Up @@ -69,7 +69,7 @@ func Groups(
) ([]*Group, error) {
ac, err := makeAC(ctx, acct, path.GroupsService)
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
return nil, clues.Stack(err)
}

return getAllGroups(ctx, ac.Groups())
Expand Down Expand Up @@ -98,6 +98,31 @@ func getAllGroups(
return ret, nil
}

func SitesInGroup(
ctx context.Context,
acct account.Account,
groupID string,
errs *fault.Bus,
) ([]*Site, error) {
ac, err := makeAC(ctx, acct, path.GroupsService)
if err != nil {
return nil, clues.Stack(err)
}

sites, err := ac.Groups().GetAllSites(ctx, groupID, errs)
if err != nil {
return nil, clues.Stack(err)
}

result := make([]*Site, 0, len(sites))

for _, site := range sites {
result = append(result, ParseSite(site))
}

return result, nil
}

// ---------------------------------------------------------------------------
// helpers
// ---------------------------------------------------------------------------
Expand Down
35 changes: 35 additions & 0 deletions src/pkg/services/m365/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/alcionai/clues"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/alcionai/corso/src/internal/tester/tconfig"
"github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/credentials"
"github.com/alcionai/corso/src/pkg/errs"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/services/m365"
)
Expand Down Expand Up @@ -59,6 +61,20 @@ func (suite *GroupsIntgSuite) TestGroupByID() {
assert.NotEmpty(t, group.DisplayName)
}

func (suite *GroupsIntgSuite) TestGroupByID_notFound() {
t := suite.T()

ctx, flush := tester.NewContext(t)
defer flush()

graph.InitializeConcurrencyLimiter(ctx, true, 4)

group, err := m365.GroupByID(ctx, suite.acct, uuid.NewString())
require.Nil(t, group)
require.ErrorIs(t, err, graph.ErrResourceOwnerNotFound, clues.ToCore(err))
require.True(t, errs.Is(err, errs.ResourceOwnerNotFound))
}

func (suite *GroupsIntgSuite) TestGroups() {
t := suite.T()

Expand Down Expand Up @@ -86,6 +102,25 @@ func (suite *GroupsIntgSuite) TestGroups() {
}
}

func (suite *GroupsIntgSuite) TestSitesInGroup() {
t := suite.T()

ctx, flush := tester.NewContext(t)
defer flush()

graph.InitializeConcurrencyLimiter(ctx, true, 4)

gid := tconfig.M365TeamID(t)

sites, err := m365.SitesInGroup(
ctx,
suite.acct,
gid,
fault.New(true))
assert.NoError(t, err, clues.ToCore(err))
assert.NotEmpty(t, sites)
}

func (suite *GroupsIntgSuite) TestGroupsMap() {
t := suite.T()

Expand Down
4 changes: 2 additions & 2 deletions src/pkg/services/m365/m365.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func makeAC(

creds, err := acct.M365Config()
if err != nil {
return api.Client{}, clues.Wrap(err, "getting m365 account creds")
return api.Client{}, clues.Wrap(err, "getting m365 account creds").WithClues(ctx)
}

cli, err := api.NewClient(creds, control.DefaultOptions())
if err != nil {
return api.Client{}, clues.Wrap(err, "constructing api client")
return api.Client{}, clues.Wrap(err, "constructing api client").WithClues(ctx)
}

return cli, nil
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/services/m365/sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func SiteByID(
) (*Site, error) {
ac, err := makeAC(ctx, acct, path.SharePointService)
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
return nil, clues.Stack(err)
}

cc := api.CallConfig{
Expand All @@ -75,7 +75,7 @@ func SiteByID(
func Sites(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*Site, error) {
ac, err := makeAC(ctx, acct, path.SharePointService)
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
return nil, clues.Stack(err)
}

return getAllSites(ctx, ac.Sites())
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/services/m365/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func UsersCompatNoInfo(ctx context.Context, acct account.Account) ([]*UserNoInfo
func UserHasMailbox(ctx context.Context, acct account.Account, userID string) (bool, error) {
ac, err := makeAC(ctx, acct, path.ExchangeService)
if err != nil {
return false, clues.Stack(err).WithClues(ctx)
return false, clues.Stack(err)
}

return exchange.IsServiceEnabled(ctx, ac.Users(), userID)
Expand All @@ -55,7 +55,7 @@ func UserGetMailboxInfo(
) (api.MailboxInfo, error) {
ac, err := makeAC(ctx, acct, path.ExchangeService)
if err != nil {
return api.MailboxInfo{}, clues.Stack(err).WithClues(ctx)
return api.MailboxInfo{}, clues.Stack(err)
}

return exchange.GetMailboxInfo(ctx, ac.Users(), userID)
Expand All @@ -66,7 +66,7 @@ func UserGetMailboxInfo(
func UserHasDrives(ctx context.Context, acct account.Account, userID string) (bool, error) {
ac, err := makeAC(ctx, acct, path.OneDriveService)
if err != nil {
return false, clues.Stack(err).WithClues(ctx)
return false, clues.Stack(err)
}

return onedrive.IsServiceEnabled(ctx, ac.Users(), userID)
Expand All @@ -76,7 +76,7 @@ func UserHasDrives(ctx context.Context, acct account.Account, userID string) (bo
func usersNoInfo(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*UserNoInfo, error) {
ac, err := makeAC(ctx, acct, path.UnknownService)
if err != nil {
return nil, clues.Stack(err).WithClues(ctx)
return nil, clues.Stack(err)
}

us, err := ac.Users().GetAll(ctx, errs)
Expand Down

0 comments on commit 9e40d88

Please sign in to comment.