fix user validation in factory (#3031)

#### Type of change

- [x] 🐛 Bugfix

#### Test Plan

- [x] 💪 Manual
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-04-04 18:54:04 -06:00 committed by GitHub
parent ec30c9ccce
commit c949c333e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -88,8 +88,7 @@ func generateAndRestoreItems(
service, service,
tenantID, userID, tenantID, userID,
dest, dest,
collections, collections)
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -121,21 +120,18 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon
return nil, account.Account{}, clues.Wrap(err, "finding m365 account details") return nil, account.Account{}, clues.Wrap(err, "finding m365 account details")
} }
// build a graph connector
// TODO: log/print recoverable errors // TODO: log/print recoverable errors
errs := fault.New(false) errs := fault.New(false)
normUsers := map[string]struct{}{}
ins, err := m365.UsersMap(ctx, acct, errs) ins, err := m365.UsersMap(ctx, acct, errs)
if err != nil { if err != nil {
return nil, account.Account{}, clues.Wrap(err, "getting tenant users") return nil, account.Account{}, clues.Wrap(err, "getting tenant users")
} }
for _, k := range ins.IDs() { _, idOK := ins.NameOf(strings.ToLower(userID))
normUsers[strings.ToLower(k)] = struct{}{} _, nameOK := ins.IDOf(strings.ToLower(userID))
}
if _, ok := normUsers[strings.ToLower(User)]; !ok { if !idOK && !nameOK {
return nil, account.Account{}, clues.New("user not found within tenant") return nil, account.Account{}, clues.New("user not found within tenant")
} }

View File

@ -2,6 +2,7 @@ package m365
import ( import (
"context" "context"
"strings"
"github.com/alcionai/clues" "github.com/alcionai/clues"
"github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models"
@ -75,8 +76,9 @@ func UsersMap(
) )
for _, u := range users { for _, u := range users {
idToName[u.ID] = u.PrincipalName id, name := strings.ToLower(u.ID), strings.ToLower(u.PrincipalName)
nameToID[u.PrincipalName] = u.ID idToName[id] = name
nameToID[name] = id
} }
ins := common.IDsNames{ ins := common.IDsNames{