Introduce a UserCompatNoInfo call (#3257)
Instead of returning `Info` in `User`, callers should call the `GetUserInfo` API to get extended user information. This allows the caller to decide whether info is needed *and* control parallelism for these queries. This change introduces a `UserCompatNoInfo` call that allows us to make the switch without breaking existing `UserCompat` references. We will remove this API after callers have switched. --- #### 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 - [x] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [ ] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
40d8c45ec7
commit
084b519766
@ -33,6 +33,14 @@ type User struct {
|
|||||||
Info api.UserInfo
|
Info api.UserInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserNoInfo is the minimal information required to identify and display a user.
|
||||||
|
// TODO: Remove this once `UsersCompatNoInfo` is removed
|
||||||
|
type UserNoInfo struct {
|
||||||
|
PrincipalName string
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
// UsersCompat returns a list of users in the specified M365 tenant.
|
// UsersCompat returns a list of users in the specified M365 tenant.
|
||||||
// TODO(ashmrtn): Remove when upstream consumers of the SDK support the fault
|
// TODO(ashmrtn): Remove when upstream consumers of the SDK support the fault
|
||||||
// package.
|
// package.
|
||||||
@ -47,6 +55,54 @@ func UsersCompat(ctx context.Context, acct account.Account) ([]*User, error) {
|
|||||||
return users, errs.Failure()
|
return users, errs.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UsersCompatNoInfo returns a list of users in the specified M365 tenant.
|
||||||
|
// TODO: Remove this once `Info` is removed from the `User` struct and callers
|
||||||
|
// have switched over
|
||||||
|
func UsersCompatNoInfo(ctx context.Context, acct account.Account) ([]*UserNoInfo, error) {
|
||||||
|
errs := fault.New(true)
|
||||||
|
|
||||||
|
users, err := usersNoInfo(ctx, acct, errs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, errs.Failure()
|
||||||
|
}
|
||||||
|
|
||||||
|
// usersNoInfo returns a list of users in the specified M365 tenant - with no info
|
||||||
|
// TODO: Remove this once we remove `Info` from `Users` and instead rely on the `GetUserInfo` API
|
||||||
|
// to get user information
|
||||||
|
func usersNoInfo(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*UserNoInfo, error) {
|
||||||
|
uapi, err := makeUserAPI(acct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, clues.Wrap(err, "getting users").WithClues(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
users, err := discovery.Users(ctx, uapi, errs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := make([]*UserNoInfo, 0, len(users))
|
||||||
|
|
||||||
|
for _, u := range users {
|
||||||
|
pu, err := parseUser(u)
|
||||||
|
if err != nil {
|
||||||
|
return nil, clues.Wrap(err, "formatting user data")
|
||||||
|
}
|
||||||
|
|
||||||
|
puNoInfo := &UserNoInfo{
|
||||||
|
PrincipalName: pu.PrincipalName,
|
||||||
|
ID: pu.ID,
|
||||||
|
Name: pu.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, puNoInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Users returns a list of users in the specified M365 tenant
|
// Users returns a list of users in the specified M365 tenant
|
||||||
func Users(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*User, error) {
|
func Users(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*User, error) {
|
||||||
uapi, err := makeUserAPI(acct)
|
uapi, err := makeUserAPI(acct)
|
||||||
|
|||||||
@ -52,6 +52,30 @@ func (suite *M365IntegrationSuite) TestUsers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *M365IntegrationSuite) TestUsersCompat_HasNoInfo() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
var (
|
||||||
|
t = suite.T()
|
||||||
|
acct = tester.NewM365Account(suite.T())
|
||||||
|
)
|
||||||
|
|
||||||
|
users, err := m365.UsersCompatNoInfo(ctx, acct)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
assert.NotEmpty(t, users)
|
||||||
|
|
||||||
|
for _, u := range users {
|
||||||
|
suite.Run("user_"+u.ID, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
assert.NotEmpty(t, u.ID)
|
||||||
|
assert.NotEmpty(t, u.PrincipalName)
|
||||||
|
assert.NotEmpty(t, u.Name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *M365IntegrationSuite) TestGetUserInfo() {
|
func (suite *M365IntegrationSuite) TestGetUserInfo() {
|
||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user