This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git

commit 42f8947e7c4bbd586b8496621079830880378346
Author: Douglas Cortez <[email protected]>
AuthorDate: Wed Dec 24 00:24:21 2025 -0300

    fix(notification): use SSO provider for external_id lookup in notifications
---
 .../repo/user_external_login/user_external_login_repo.go  |  2 +-
 .../service/notification/new_question_notification.go     | 15 +++++++++------
 internal/service/notification_common/notification.go      | 15 +++++++--------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/internal/repo/user_external_login/user_external_login_repo.go 
b/internal/repo/user_external_login/user_external_login_repo.go
index c797e461..b5cf85e8 100644
--- a/internal/repo/user_external_login/user_external_login_repo.go
+++ b/internal/repo/user_external_login/user_external_login_repo.go
@@ -87,7 +87,7 @@ func (ur *userExternalLoginRepo) GetByUserID(ctx 
context.Context, provider, user
 func (ur *userExternalLoginRepo) GetUserExternalLoginList(ctx context.Context, 
userID string) (
        resp []*entity.UserExternalLogin, err error) {
        resp = make([]*entity.UserExternalLogin, 0)
-       err = ur.data.DB.Context(ctx).Where("user_id = ?", userID).Find(&resp)
+       err = ur.data.DB.Context(ctx).Where("user_id = ?", 
userID).OrderBy("updated_at DESC").Find(&resp)
        if err != nil {
                err = 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
        }
diff --git a/internal/service/notification/new_question_notification.go 
b/internal/service/notification/new_question_notification.go
index 2f83042b..085b3ec4 100644
--- a/internal/service/notification/new_question_notification.go
+++ b/internal/service/notification/new_question_notification.go
@@ -238,14 +238,17 @@ func (ns *ExternalNotificationService) 
syncNewQuestionNotificationToPlugin(ctx c
                                }
                        }
 
-                       userInfo, exist, err := 
ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, subscriberUserID)
+                       externalLogins, err := 
ns.userExternalLoginRepo.GetUserExternalLoginList(ctx, subscriberUserID)
                        if err != nil {
-                               log.Errorf("get user external login info 
failed: %v", err)
-                               return nil
-                       }
-                       if exist {
-                               newMsg.ReceiverExternalID = userInfo.ExternalID
+                               log.Errorf("get user external login list failed 
for user %s: %v", subscriberUserID, err)
+                       } else if len(externalLogins) > 0 {
+                               newMsg.ReceiverExternalID = 
externalLogins[0].ExternalID
+                               if len(externalLogins) > 1 {
+                                       log.Debugf("user %s has %d SSO logins, 
using most recent: provider=%s",
+                                               subscriberUserID, 
len(externalLogins), externalLogins[0].Provider)
+                               }
                        }
+
                        fn.Notify(newMsg)
                }
                return nil
diff --git a/internal/service/notification_common/notification.go 
b/internal/service/notification_common/notification.go
index 0bbd1865..5dbadcb9 100644
--- a/internal/service/notification_common/notification.go
+++ b/internal/service/notification_common/notification.go
@@ -423,15 +423,14 @@ func (ns *NotificationCommon) 
syncNotificationToPlugin(ctx context.Context, objI
                }
        }
 
+       externalLogins, err := 
ns.userExternalLoginRepo.GetUserExternalLoginList(ctx, msg.ReceiverUserID)
+       if err != nil {
+               log.Errorf("get user external login list failed for user %s: 
%v", msg.ReceiverUserID, err)
+       } else if len(externalLogins) > 0 {
+               pluginNotificationMsg.ReceiverExternalID = 
externalLogins[0].ExternalID
+       }
+
        _ = plugin.CallNotification(func(fn plugin.Notification) error {
-               userInfo, exist, err := 
ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, 
msg.ReceiverUserID)
-               if err != nil {
-                       log.Errorf("get user external login info failed: %v", 
err)
-                       return nil
-               }
-               if exist {
-                       pluginNotificationMsg.ReceiverExternalID = 
userInfo.ExternalID
-               }
                fn.Notify(pluginNotificationMsg)
                return nil
        })

Reply via email to