Revert "Fetch calendar by name on 409 ErrorFolderExist (#3318)"
This reverts commit 5b9cd69e292ca4c3be4ed7cb2d775b8fa5261ea9.
This commit is contained in:
parent
f5365f19c5
commit
052f3cd56d
@ -99,45 +99,6 @@ func (c Events) GetContainerByID(
|
||||
return graph.CalendarDisplayable{Calendarable: cal}, nil
|
||||
}
|
||||
|
||||
// GetContainerByName fetches a calendar by name
|
||||
func (c Events) GetContainerByName(
|
||||
ctx context.Context,
|
||||
userID, name string,
|
||||
) (models.Calendarable, error) {
|
||||
filter := fmt.Sprintf("name eq '%s'", name)
|
||||
options := &users.ItemCalendarsRequestBuilderGetRequestConfiguration{
|
||||
QueryParameters: &users.ItemCalendarsRequestBuilderGetQueryParameters{
|
||||
Filter: &filter,
|
||||
},
|
||||
}
|
||||
|
||||
ctx = clues.Add(ctx, "calendar_name", name)
|
||||
|
||||
resp, err := c.Stable.Client().UsersById(userID).Calendars().Get(ctx, options)
|
||||
if err != nil {
|
||||
return nil, graph.Stack(ctx, err).WithClues(ctx)
|
||||
}
|
||||
|
||||
// We only allow the api to match one calendar with provided name.
|
||||
// Return an error if multiple calendars exist (unlikely) or if no calendar
|
||||
// is found.
|
||||
if len(resp.GetValue()) != 1 {
|
||||
err = clues.New("unexpected number of calendars returned").
|
||||
With("returned_calendar_count", len(resp.GetValue()))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Sanity check ID and name
|
||||
cal := resp.GetValue()[0]
|
||||
cd := CalendarDisplayable{Calendarable: cal}
|
||||
|
||||
if err := checkIDAndName(cd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cal, nil
|
||||
}
|
||||
|
||||
// GetItem retrieves an Eventable item.
|
||||
func (c Events) GetItem(
|
||||
ctx context.Context,
|
||||
|
||||
@ -689,20 +689,10 @@ func establishEventsRestoreLocation(
|
||||
ctx = clues.Add(ctx, "is_new_cache", isNewCache)
|
||||
|
||||
temp, err := ac.Events().CreateCalendar(ctx, user, folders[0])
|
||||
if err != nil && !graph.IsErrFolderExists(err) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 409 handling: Fetch folder if it exists and add to cache.
|
||||
// This is rare, but may happen if CreateCalendar() POST fails with 5xx,
|
||||
// potentially leaving dirty state in graph.
|
||||
if graph.IsErrFolderExists(err) {
|
||||
temp, err = ac.Events().GetContainerByName(ctx, user, folders[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
folderID := ptr.Val(temp.GetId())
|
||||
|
||||
if isNewCache {
|
||||
|
||||
@ -41,10 +41,6 @@ const (
|
||||
syncFolderNotFound errorCode = "ErrorSyncFolderNotFound"
|
||||
syncStateInvalid errorCode = "SyncStateInvalid"
|
||||
syncStateNotFound errorCode = "SyncStateNotFound"
|
||||
// This error occurs when an attempt is made to create a folder that has
|
||||
// the same name as another folder in the same parent. Such duplicate folder
|
||||
// names are not allowed by graph.
|
||||
folderExists errorCode = "ErrorFolderExists"
|
||||
)
|
||||
|
||||
type errorMessage string
|
||||
@ -182,10 +178,6 @@ func IsMalwareResp(ctx context.Context, resp *http.Response) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func IsErrFolderExists(err error) bool {
|
||||
return hasErrorCode(err, folderExists)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// error parsers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -300,48 +300,3 @@ func (suite *GraphErrorsUnitSuite) TestMalwareInfo() {
|
||||
|
||||
assert.Equal(suite.T(), expect, ItemInfo(&i))
|
||||
}
|
||||
|
||||
func (suite *GraphErrorsUnitSuite) TestIsErrFolderExists() {
|
||||
table := []struct {
|
||||
name string
|
||||
err error
|
||||
expect assert.BoolAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
err: nil,
|
||||
expect: assert.False,
|
||||
},
|
||||
{
|
||||
name: "non-matching",
|
||||
err: assert.AnError,
|
||||
expect: assert.False,
|
||||
},
|
||||
{
|
||||
name: "non-matching oDataErr",
|
||||
err: odErr("folder doesn't exist"),
|
||||
expect: assert.False,
|
||||
},
|
||||
{
|
||||
name: "matching oDataErr",
|
||||
err: odErr(string(folderExists)),
|
||||
expect: assert.True,
|
||||
},
|
||||
// next two tests are to make sure the checks are case insensitive
|
||||
{
|
||||
name: "oDataErr camelcase",
|
||||
err: odErr("ErrorFolderExists"),
|
||||
expect: assert.True,
|
||||
},
|
||||
{
|
||||
name: "oDataErr lowercase",
|
||||
err: odErr("errorfolderexists"),
|
||||
expect: assert.True,
|
||||
},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.Run(test.name, func() {
|
||||
test.expect(suite.T(), IsErrFolderExists(test.err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user