You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2025/12/29 02:27:06 UTC

(answer) branch dev updated (61d9bf34 -> c8908b7b)

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

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


    from 61d9bf34 修复最佳评论越权问题
     new 42f8947e fix(notification): use SSO provider for external_id lookup in notifications
     new c8908b7b fix(review): notifications from the specific external system will take precedence

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../repo/user_external_login/user_external_login_repo.go    |  2 +-
 internal/service/notification/new_question_notification.go  | 13 +++++++++++++
 internal/service/notification_common/notification.go        |  7 +++++++
 3 files changed, 21 insertions(+), 1 deletion(-)


(answer) 01/02: fix(notification): use SSO provider for external_id lookup in notifications

Posted by li...@apache.org.
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 <do...@outlook.com>
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
 	})


(answer) 02/02: fix(review): notifications from the specific external system will take precedence

Posted by li...@apache.org.
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 c8908b7b3405e1bd927c6019e35630526a29c484
Author: Douglas Cortez <do...@outlook.com>
AuthorDate: Fri Dec 26 12:18:26 2025 -0300

    fix(review): notifications from the specific external system will take precedence
---
 internal/service/notification/new_question_notification.go | 10 ++++++++++
 internal/service/notification_common/notification.go       |  8 ++++++++
 2 files changed, 18 insertions(+)

diff --git a/internal/service/notification/new_question_notification.go b/internal/service/notification/new_question_notification.go
index 085b3ec4..0a547187 100644
--- a/internal/service/notification/new_question_notification.go
+++ b/internal/service/notification/new_question_notification.go
@@ -238,6 +238,7 @@ func (ns *ExternalNotificationService) syncNewQuestionNotificationToPlugin(ctx c
 				}
 			}
 
+			// Get all external logins as fallback
 			externalLogins, err := ns.userExternalLoginRepo.GetUserExternalLoginList(ctx, subscriberUserID)
 			if err != nil {
 				log.Errorf("get user external login list failed for user %s: %v", subscriberUserID, err)
@@ -249,6 +250,15 @@ func (ns *ExternalNotificationService) syncNewQuestionNotificationToPlugin(ctx c
 				}
 			}
 
+			// Try to get external login specific to this plugin (takes precedence over fallback)
+			userInfo, exist, err := ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, subscriberUserID)
+			if err != nil {
+				log.Errorf("get user external login info failed: %v", err)
+				return nil
+			}
+			if exist {
+				newMsg.ReceiverExternalID = userInfo.ExternalID
+			}
 			fn.Notify(newMsg)
 		}
 		return nil
diff --git a/internal/service/notification_common/notification.go b/internal/service/notification_common/notification.go
index 5dbadcb9..94ce86b1 100644
--- a/internal/service/notification_common/notification.go
+++ b/internal/service/notification_common/notification.go
@@ -431,6 +431,14 @@ func (ns *NotificationCommon) syncNotificationToPlugin(ctx context.Context, objI
 	}
 
 	_ = 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
 	})