graph/users: gracefully handle PATCH requests with empty bodies

Return as success status code when the PATCH request comes with an empty
body. This is mainly to workaround issues like:
https://github.com/owncloud/web/issues/8946
This commit is contained in:
Ralf Haferkamp
2023-04-27 16:49:37 +02:00
committed by Ralf Haferkamp
parent 1ad31218ec
commit 77e773515d
2 changed files with 16 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"sort"
"strings"
@@ -130,6 +131,13 @@ func (g Graph) PatchGroup(w http.ResponseWriter, r *http.Request) {
return
}
if reflect.ValueOf(*changes).IsZero() {
logger.Debug().Interface("body", r.Body).Msg("ignoring empyt request body")
render.Status(r, http.StatusNoContent)
render.NoContent(w, r)
return
}
if changes.HasDisplayName() {
groupName := changes.GetDisplayName()
err = g.identityBackend.UpdateGroupName(r.Context(), groupID, groupName)

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"regexp"
"sort"
"strings"
@@ -646,6 +647,13 @@ func (g Graph) PatchUser(w http.ResponseWriter, r *http.Request) {
return
}
if reflect.ValueOf(*changes).IsZero() {
logger.Debug().Interface("body", r.Body).Msg("ignoring empyt request body")
render.Status(r, http.StatusNoContent)
render.NoContent(w, r)
return
}
var features []events.UserFeature
if mail, ok := changes.GetMailOk(); ok {
if !isValidEmail(*mail) {