From 9c912342ff62f4e4038bff8b0d56e33bcf6f77ce Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 19 Oct 2022 21:07:21 +0200 Subject: [PATCH 1/2] Suppress `ExternalLoginUserNotExist` error (#21504) Fixes #21202 Closes #21276 An `ExternalLoginUser` is not mandatory if the current user account was created with/by the external login source. --- routers/web/auth/auth.go | 6 +++++- routers/web/auth/oauth.go | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index ea5c7232a8aec..22225bc43722b 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -6,6 +6,7 @@ package auth import ( + "errors" "fmt" "net/http" "strings" @@ -23,6 +24,7 @@ import ( "code.gitea.io/gitea/modules/session" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/routers/utils" @@ -613,7 +615,9 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. // update external user information if gothUser != nil { if err := externalaccount.UpdateExternalUser(u, *gothUser); err != nil { - log.Error("UpdateExternalUser failed: %v", err) + if !errors.Is(err, util.ErrNotExist) { + log.Error("UpdateExternalUser failed: %v", err) + } } } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index a9fc39d0195c1..56312f822cc8d 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -1061,7 +1061,9 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model // update external user information if err := externalaccount.UpdateExternalUser(u, gothUser); err != nil { - log.Error("UpdateExternalUser failed: %v", err) + if !errors.Is(err, util.ErrNotExist) { + log.Error("UpdateExternalUser failed: %v", err) + } } if err := resetLocale(ctx, u); err != nil { From fb2bf7b587fbd83ef94e7a0ad47e13bbaf53ffa1 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 25 Oct 2022 09:32:44 +0000 Subject: [PATCH 2/2] Use IsErrExternalLoginUserNotExist. --- routers/web/auth/auth.go | 4 +--- routers/web/auth/oauth.go | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 22225bc43722b..bda6789d8d674 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -6,7 +6,6 @@ package auth import ( - "errors" "fmt" "net/http" "strings" @@ -24,7 +23,6 @@ import ( "code.gitea.io/gitea/modules/session" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/routers/utils" @@ -615,7 +613,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. // update external user information if gothUser != nil { if err := externalaccount.UpdateExternalUser(u, *gothUser); err != nil { - if !errors.Is(err, util.ErrNotExist) { + if !user_model.IsErrExternalLoginUserNotExist(err) { log.Error("UpdateExternalUser failed: %v", err) } } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 56312f822cc8d..0492d30656201 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -1061,7 +1061,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model // update external user information if err := externalaccount.UpdateExternalUser(u, gothUser); err != nil { - if !errors.Is(err, util.ErrNotExist) { + if !user_model.IsErrExternalLoginUserNotExist(err) { log.Error("UpdateExternalUser failed: %v", err) } }