From 517356f1765766ba4f0820ba03ef631cdfcfde8a Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 23 Mar 2022 15:44:58 +0100 Subject: [PATCH] graph: Allow PATCH on user without 'mail' in body Skip the mail validator if 'mail' attribute is not present in the request. --- changelog/unreleased/graph-patch-mail.md | 6 ++++++ graph/pkg/service/v0/users.go | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/graph-patch-mail.md diff --git a/changelog/unreleased/graph-patch-mail.md b/changelog/unreleased/graph-patch-mail.md new file mode 100644 index 00000000000..608e9a665ef --- /dev/null +++ b/changelog/unreleased/graph-patch-mail.md @@ -0,0 +1,6 @@ +Bugfix: Fix request validation on GraphAPI User updates + +Fix PATCH on graph/v1.0/users when no 'mail' attribute +is present in the request body + +https://github.com/owncloud/ocis/issues/3167 diff --git a/graph/pkg/service/v0/users.go b/graph/pkg/service/v0/users.go index ab7f3f9ecb9..592d1ecd136 100644 --- a/graph/pkg/service/v0/users.go +++ b/graph/pkg/service/v0/users.go @@ -180,11 +180,12 @@ func (g Graph) PatchUser(w http.ResponseWriter, r *http.Request) { return } - mail := changes.GetMail() - if !isValidEmail(mail) { - errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, - fmt.Sprintf("'%s' is not a valid email address", mail)) - return + if mail, ok := changes.GetMailOk(); ok { + if !isValidEmail(*mail) { + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, + fmt.Sprintf("'%s' is not a valid email address", *mail)) + return + } } u, err := g.identityBackend.UpdateUser(r.Context(), nameOrID, *changes)