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

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

commit a4752957841a9c524325f535aadad685ce2be571
Author: Luffy <[email protected]>
AuthorDate: Fri Dec 6 14:34:30 2024 +0800

    feat: Add delete external user login info by user ID
---
 cmd/wire_gen.go                                               |  2 +-
 internal/repo/user_external_login/user_external_login_repo.go | 10 ++++++++++
 internal/service/user_admin/user_backyard.go                  | 11 +++++++++++
 .../user_external_login/user_external_login_service.go        |  1 +
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 5e4d395b..3f267984 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -228,7 +228,7 @@ func initApplication(debug bool, serverConf *conf.Server, 
dbConf *data.Database,
        revisionController := 
controller.NewRevisionController(contentRevisionService, rankService)
        rankController := controller.NewRankController(rankService)
        userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)
-       userAdminService := user_admin.NewUserAdminService(userAdminRepo, 
userRoleRelService, authService, userCommon, userActiveActivityRepo, 
siteInfoCommonService, emailService, questionRepo, answerRepo, 
commentCommonRepo)
+       userAdminService := user_admin.NewUserAdminService(userAdminRepo, 
userRoleRelService, authService, userCommon, userActiveActivityRepo, 
siteInfoCommonService, emailService, questionRepo, answerRepo, 
commentCommonRepo, userExternalLoginRepo)
        userAdminController := 
controller_admin.NewUserAdminController(userAdminService)
        reasonRepo := reason.NewReasonRepo(configService)
        reasonService := reason2.NewReasonService(reasonRepo)
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 8b78b8b4..c2d13108 100644
--- a/internal/repo/user_external_login/user_external_login_repo.go
+++ b/internal/repo/user_external_login/user_external_login_repo.go
@@ -104,6 +104,16 @@ func (ur *userExternalLoginRepo) 
DeleteUserExternalLogin(ctx context.Context, us
        return
 }
 
+// DeleteUserExternalLoginByUserID delete external user login info by user ID
+func (ur *userExternalLoginRepo) DeleteUserExternalLoginByUserID(ctx 
context.Context, userID string) (err error) {
+       cond := &entity.UserExternalLogin{}
+       _, err = ur.data.DB.Context(ctx).Where("user_id = ?", 
userID).Delete(cond)
+       if err != nil {
+               err = 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+       }
+       return
+}
+
 // SetCacheUserExternalLoginInfo cache user info for external login
 func (ur *userExternalLoginRepo) SetCacheUserExternalLoginInfo(
        ctx context.Context, key string, info 
*schema.ExternalLoginUserInfoCache) (err error) {
diff --git a/internal/service/user_admin/user_backyard.go 
b/internal/service/user_admin/user_backyard.go
index 52c0d630..ebe1ea74 100644
--- a/internal/service/user_admin/user_backyard.go
+++ b/internal/service/user_admin/user_backyard.go
@@ -45,6 +45,7 @@ import (
        "github.com/apache/incubator-answer/internal/service/role"
        "github.com/apache/incubator-answer/internal/service/siteinfo_common"
        usercommon 
"github.com/apache/incubator-answer/internal/service/user_common"
+       
"github.com/apache/incubator-answer/internal/service/user_external_login"
        "github.com/apache/incubator-answer/pkg/checker"
        "github.com/jinzhu/copier"
        "github.com/segmentfault/pacman/errors"
@@ -76,6 +77,7 @@ type UserAdminService struct {
        questionCommonRepo    questioncommon.QuestionRepo
        answerCommonRepo      answercommon.AnswerRepo
        commentCommonRepo     comment_common.CommentCommonRepo
+       userExternalLoginRepo user_external_login.UserExternalLoginRepo
 }
 
 // NewUserAdminService new user admin service
@@ -90,6 +92,7 @@ func NewUserAdminService(
        questionCommonRepo questioncommon.QuestionRepo,
        answerCommonRepo answercommon.AnswerRepo,
        commentCommonRepo comment_common.CommentCommonRepo,
+       userExternalLoginRepo user_external_login.UserExternalLoginRepo,
 ) *UserAdminService {
        return &UserAdminService{
                userRepo:              userRepo,
@@ -102,6 +105,7 @@ func NewUserAdminService(
                questionCommonRepo:    questionCommonRepo,
                answerCommonRepo:      answerCommonRepo,
                commentCommonRepo:     commentCommonRepo,
+               userExternalLoginRepo: userExternalLoginRepo,
        }
 }
 
@@ -148,6 +152,13 @@ func (us *UserAdminService) UpdateUserStatus(ctx 
context.Context, req *schema.Up
                us.removeAllUserCreatedContent(ctx, userInfo.ID)
        }
 
+       if req.IsDeleted() {
+               err := 
us.userExternalLoginRepo.DeleteUserExternalLoginByUserID(ctx, userInfo.ID)
+               if err != nil {
+                       log.Errorf("remove all user external login error: %v", 
err)
+               }
+       }
+
        // if user reputation is zero means this user is inactive, so try to 
activate this user.
        if req.IsNormal() && userInfo.Rank == 0 {
                return us.userActivity.UserActive(ctx, userInfo.ID)
diff --git 
a/internal/service/user_external_login/user_external_login_service.go 
b/internal/service/user_external_login/user_external_login_service.go
index e0afbd37..9107fcc0 100644
--- a/internal/service/user_external_login/user_external_login_service.go
+++ b/internal/service/user_external_login/user_external_login_service.go
@@ -51,6 +51,7 @@ type UserExternalLoginRepo interface {
        GetByUserID(ctx context.Context, provider, userID string) (userInfo 
*entity.UserExternalLogin, exist bool, err error)
        GetUserExternalLoginList(ctx context.Context, userID string) (resp 
[]*entity.UserExternalLogin, err error)
        DeleteUserExternalLogin(ctx context.Context, userID, externalID string) 
(err error)
+       DeleteUserExternalLoginByUserID(ctx context.Context, userID string) 
(err error)
        SetCacheUserExternalLoginInfo(ctx context.Context, key string, info 
*schema.ExternalLoginUserInfoCache) (err error)
        GetCacheUserExternalLoginInfo(ctx context.Context, key string) (info 
*schema.ExternalLoginUserInfoCache, err error)
 }

Reply via email to