Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bd3d61f77 | ||
|
|
4af8678c8a | ||
|
|
c641e457fd |
@ -55,6 +55,41 @@ func (c Contacts) CreateContactFolder(
|
|||||||
return mdl, nil
|
return mdl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetContactFolderByDisplayName fetches contact folder which has the displayName of
|
||||||
|
// folderName. This is only done at root level.
|
||||||
|
func (c Contacts) GetContactFolderByDisplayName(
|
||||||
|
ctx context.Context,
|
||||||
|
user, folderName string,
|
||||||
|
) (models.ContactFolderable, error) {
|
||||||
|
filter := fmt.Sprintf("displayName eq '%s'", folderName)
|
||||||
|
options := &users.ItemContactFoldersRequestBuilderGetRequestConfiguration{
|
||||||
|
QueryParameters: &users.ItemContactFoldersRequestBuilderGetQueryParameters{
|
||||||
|
Filter: &filter,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.Stable.Client().UsersById(user).ContactFolders().Get(ctx, options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, graph.Wrap(ctx, err, "getting contact folder").
|
||||||
|
With("folder name", folderName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only expect one folder with provided folderName. Return an error if
|
||||||
|
// multiple folders exist(unlikely) or if no folder was found
|
||||||
|
if len(resp.GetValue()) != 1 {
|
||||||
|
return nil, graph.Wrap(ctx, err, "unexpected number of folders").
|
||||||
|
With("folder count", len(resp.GetValue())).
|
||||||
|
With("folder name", folderName)
|
||||||
|
}
|
||||||
|
|
||||||
|
fold := resp.GetValue()[0]
|
||||||
|
if err := checkIDAndName(fold); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fold, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteContainer deletes the ContactFolder associated with the M365 ID if permissions are valid.
|
// DeleteContainer deletes the ContactFolder associated with the M365 ID if permissions are valid.
|
||||||
func (c Contacts) DeleteContainer(
|
func (c Contacts) DeleteContainer(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|||||||
@ -651,19 +651,27 @@ func establishContactsRestoreLocation(
|
|||||||
|
|
||||||
ctx = clues.Add(ctx, "is_new_cache", isNewCache)
|
ctx = clues.Add(ctx, "is_new_cache", isNewCache)
|
||||||
|
|
||||||
temp, err := ac.Contacts().CreateContactFolder(ctx, user, folders[0])
|
fold, err := ac.Contacts().CreateContactFolder(ctx, user, folders[0])
|
||||||
|
// 409 handling: Fetch folder if it exists.
|
||||||
|
// This is rare, but it may happen if an earlier CreateContactFolder POST failed
|
||||||
|
// with 5xx, potentially leaving dirty state in graph.
|
||||||
|
if graph.IsErrFolderExists(err) {
|
||||||
|
fold, err = ac.Contacts().GetContactFolderByDisplayName(ctx, user, folders[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
folderID := ptr.Val(temp.GetId())
|
folderID := ptr.Val(fold.GetId())
|
||||||
|
|
||||||
if isNewCache {
|
if isNewCache {
|
||||||
if err := cfc.Populate(ctx, errs, folderID, folders[0]); err != nil {
|
if err := cfc.Populate(ctx, errs, folderID, folders[0]); err != nil {
|
||||||
return "", clues.Wrap(err, "populating contact cache")
|
return "", clues.Wrap(err, "populating contact cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = cfc.AddToCache(ctx, temp); err != nil {
|
if err = cfc.AddToCache(ctx, fold); err != nil {
|
||||||
return "", clues.Wrap(err, "adding contact folder to cache")
|
return "", clues.Wrap(err, "adding contact folder to cache")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ const (
|
|||||||
syncFolderNotFound errorCode = "ErrorSyncFolderNotFound"
|
syncFolderNotFound errorCode = "ErrorSyncFolderNotFound"
|
||||||
syncStateInvalid errorCode = "SyncStateInvalid"
|
syncStateInvalid errorCode = "SyncStateInvalid"
|
||||||
syncStateNotFound errorCode = "SyncStateNotFound"
|
syncStateNotFound errorCode = "SyncStateNotFound"
|
||||||
|
folderExists errorCode = "ErrorFolderExists"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -172,6 +173,10 @@ func IsMalwareResp(ctx context.Context, resp *http.Response) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsErrFolderExists(err error) bool {
|
||||||
|
return hasErrorCode(err, folderExists)
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// error parsers
|
// error parsers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user