From cf849e9c5df8efcd1c24ff991d3f97fe348866f8 Mon Sep 17 00:00:00 2001 From: Keepers Date: Tue, 23 May 2023 12:08:34 -0600 Subject: [PATCH] fix has drive and has mailbox conditions (#3473) #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :bug: Bugfix #### Test Plan - [x] :zap: Unit test - [x] :green_heart: E2E --- src/pkg/services/m365/api/users.go | 23 +++++++++++------------ src/pkg/services/m365/m365.go | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/pkg/services/m365/api/users.go b/src/pkg/services/m365/api/users.go index 003549e53..1121c7dba 100644 --- a/src/pkg/services/m365/api/users.go +++ b/src/pkg/services/m365/api/users.go @@ -3,7 +3,6 @@ package api import ( "context" "fmt" - "net/http" "strings" "github.com/alcionai/clues" @@ -261,29 +260,29 @@ func (c Users) GetInfo(ctx context.Context, userID string) (*UserInfo, error) { mfs, err := c.GetMailFolders(ctx, userID, options) if err != nil { + logger.CtxErr(ctx, err).Error("getting user's mail folders") + if graph.IsErrUserNotFound(err) { - logger.CtxErr(ctx, err).Error("user not found") - return nil, graph.Stack(ctx, clues.Stack(graph.ErrResourceOwnerNotFound, err)) + return nil, clues.Stack(graph.ErrResourceOwnerNotFound, err) } - if !graph.IsErrExchangeMailFolderNotFound(err) || - clues.HasLabel(err, graph.LabelStatus(http.StatusNotFound)) { - logger.CtxErr(ctx, err).Error("getting user's mail folder") - return nil, err + if !graph.IsErrExchangeMailFolderNotFound(err) { + return nil, clues.Stack(err) } - logger.Ctx(ctx).Info("resource owner does not have a mailbox enabled") delete(userInfo.ServicesEnabled, path.ExchangeService) } if _, err := c.GetDrives(ctx, userID); err != nil { - if !clues.HasLabel(err, graph.LabelsMysiteNotFound) { - logger.CtxErr(ctx, err).Error("getting user's drives") + logger.CtxErr(ctx, err).Error("getting user's drives") - return nil, graph.Wrap(ctx, err, "getting user's drives") + if graph.IsErrUserNotFound(err) { + return nil, clues.Stack(graph.ErrResourceOwnerNotFound, err) } - logger.Ctx(ctx).Info("resource owner does not have a drive") + if !clues.HasLabel(err, graph.LabelsMysiteNotFound) { + return nil, clues.Stack(err) + } delete(userInfo.ServicesEnabled, path.OneDriveService) } diff --git a/src/pkg/services/m365/m365.go b/src/pkg/services/m365/m365.go index 9ba5337e4..48dd0d9f6 100644 --- a/src/pkg/services/m365/m365.go +++ b/src/pkg/services/m365/m365.go @@ -2,7 +2,6 @@ package m365 import ( "context" - "net/http" "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" @@ -91,16 +90,17 @@ func UserHasMailbox(ctx context.Context, acct account.Account, userID string) (b _, err = uapi.GetMailFolders(ctx, userID, options) if err != nil { + // we consider this a non-error case, since it + // answers the question the caller is asking. + if graph.IsErrExchangeMailFolderNotFound(err) { + return false, nil + } + if graph.IsErrUserNotFound(err) { return false, clues.Stack(graph.ErrResourceOwnerNotFound, err) } - if !graph.IsErrExchangeMailFolderNotFound(err) || - clues.HasLabel(err, graph.LabelStatus(http.StatusNotFound)) { - return false, err - } - - return false, nil + return false, clues.Stack(err) } return true, nil @@ -116,17 +116,17 @@ func UserHasDrives(ctx context.Context, acct account.Account, userID string) (bo _, err = uapi.GetDrives(ctx, userID) if err != nil { + // we consider this a non-error case, since it + // answers the question the caller is asking. + if clues.HasLabel(err, graph.LabelsMysiteNotFound) { + return false, nil + } + if graph.IsErrUserNotFound(err) { return false, clues.Stack(graph.ErrResourceOwnerNotFound, err) } - if !graph.IsErrExchangeMailFolderNotFound(err) || - clues.HasLabel(err, graph.LabelStatus(http.StatusNotFound)) || - clues.HasLabel(err, graph.LabelsMysiteNotFound) { - return false, err - } - - return false, nil + return false, clues.Stack(err) } return true, nil