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

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

commit d9bd3a2626fe835af9ffa09f3a58d84c4d57653d
Author: Luffy <[email protected]>
AuthorDate: Mon Dec 30 13:19:42 2024 +0800

    feat: remove user config
---
 cmd/wire_gen.go                                    |  8 ++---
 internal/repo/activity_common/activity_repo.go     |  2 +-
 internal/repo/badge/badge_repo.go                  |  9 +++++
 internal/repo/notification/notification_repo.go    | 16 +++++++++
 .../repo/plugin_config/plugin_user_config_repo.go  |  8 +++++
 internal/service/activity_common/activity.go       |  2 +-
 internal/service/badge/badge_service.go            |  2 ++
 internal/service/content/question_service.go       |  2 +-
 .../service/notification_common/notification.go    |  2 ++
 .../service/plugin_common/plugin_common_service.go |  1 +
 internal/service/user_admin/user_backyard.go       | 41 +++++++++++++++++++---
 11 files changed, 82 insertions(+), 11 deletions(-)

diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 3f267984..4363f08b 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -227,8 +227,11 @@ func initApplication(debug bool, serverConf *conf.Server, 
dbConf *data.Database,
        contentRevisionService := content.NewRevisionService(revisionRepo, 
userCommon, questionCommon, answerService, objService, questionRepo, 
answerRepo, tagRepo, tagCommonService, notificationQueueService, 
activityQueueService, reportRepo, reviewService, reviewActivityRepo)
        revisionController := 
controller.NewRevisionController(contentRevisionService, rankService)
        rankController := controller.NewRankController(rankService)
+       badgeRepo := badge.NewBadgeRepo(dataData, uniqueIDRepo)
+       notificationRepo := notification2.NewNotificationRepo(dataData)
+       pluginUserConfigRepo := plugin_config.NewPluginUserConfigRepo(dataData)
        userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)
-       userAdminService := user_admin.NewUserAdminService(userAdminRepo, 
userRoleRelService, authService, userCommon, userActiveActivityRepo, 
siteInfoCommonService, emailService, questionRepo, answerRepo, 
commentCommonRepo, userExternalLoginRepo)
+       userAdminService := user_admin.NewUserAdminService(userAdminRepo, 
userRoleRelService, authService, userCommon, userActiveActivityRepo, 
siteInfoCommonService, emailService, questionRepo, answerRepo, 
commentCommonRepo, userExternalLoginRepo, notificationRepo, 
pluginUserConfigRepo, badgeRepo)
        userAdminController := 
controller_admin.NewUserAdminController(userAdminService)
        reasonRepo := reason.NewReasonRepo(configService)
        reasonService := reason2.NewReasonService(reasonRepo)
@@ -237,9 +240,7 @@ func initApplication(debug bool, serverConf *conf.Server, 
dbConf *data.Database,
        siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, 
siteInfoCommonService, emailService, tagCommonService, configService, 
questionCommon)
        siteInfoController := 
controller_admin.NewSiteInfoController(siteInfoService)
        controllerSiteInfoController := 
controller.NewSiteInfoController(siteInfoCommonService)
-       notificationRepo := notification2.NewNotificationRepo(dataData)
        notificationCommon := 
notificationcommon.NewNotificationCommon(dataData, notificationRepo, 
userCommon, activityRepo, followRepo, objService, notificationQueueService, 
userExternalLoginRepo, siteInfoCommonService)
-       badgeRepo := badge.NewBadgeRepo(dataData, uniqueIDRepo)
        notificationService := notification.NewNotificationService(dataData, 
notificationRepo, notificationCommon, revisionService, userRepo, reportRepo, 
reviewService, badgeRepo)
        notificationController := 
controller.NewNotificationController(notificationService, rankService)
        dashboardService := dashboard.NewDashboardService(questionRepo, 
answerRepo, commentCommonRepo, voteRepo, userRepo, reportRepo, configService, 
siteInfoCommonService, serviceConf, reviewService, revisionRepo, dataData)
@@ -253,7 +254,6 @@ func initApplication(debug bool, serverConf *conf.Server, 
dbConf *data.Database,
        activityController := controller.NewActivityController(activityService)
        roleController := controller_admin.NewRoleController(roleService)
        pluginConfigRepo := plugin_config.NewPluginConfigRepo(dataData)
-       pluginUserConfigRepo := plugin_config.NewPluginUserConfigRepo(dataData)
        importerService := importer.NewImporterService(questionService, 
rankService, userCommon)
        pluginCommonService := 
plugin_common.NewPluginCommonService(pluginConfigRepo, pluginUserConfigRepo, 
configService, dataData, importerService)
        pluginController := 
controller_admin.NewPluginController(pluginCommonService)
diff --git a/internal/repo/activity_common/activity_repo.go 
b/internal/repo/activity_common/activity_repo.go
index 9f0a59e4..0fce5a74 100644
--- a/internal/repo/activity_common/activity_repo.go
+++ b/internal/repo/activity_common/activity_repo.go
@@ -107,7 +107,7 @@ func (ar *ActivityRepo) GetActivity(ctx context.Context, 
session *xorm.Session,
        return
 }
 
-func (ar *ActivityRepo) GetUserActivitysByActivityType(ctx context.Context, 
userID string, activityType int) (
+func (ar *ActivityRepo) GetUserActivitiesByActivityType(ctx context.Context, 
userID string, activityType int) (
        activityList []*entity.Activity, err error) {
        activityList = make([]*entity.Activity, 0)
        err = ar.data.DB.Context(ctx).Where("user_id = ?", userID).
diff --git a/internal/repo/badge/badge_repo.go 
b/internal/repo/badge/badge_repo.go
index d52fc122..4c5e51ae 100644
--- a/internal/repo/badge/badge_repo.go
+++ b/internal/repo/badge/badge_repo.go
@@ -149,3 +149,12 @@ func (r *badgeRepo) UpdateAwardCount(ctx context.Context, 
badgeID string, awardC
        }
        return
 }
+
+// DeleteUserBadge delete user badge
+func (r *badgeRepo) DeleteUserBadge(ctx context.Context, userID string) (err 
error) {
+       _, err = r.data.DB.Context(ctx).Where("user_id = ?", 
userID).Delete(&entity.BadgeAward{})
+       if err != nil {
+               err = 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+       }
+       return
+}
diff --git a/internal/repo/notification/notification_repo.go 
b/internal/repo/notification/notification_repo.go
index 5a2a6cc7..09ee9f35 100644
--- a/internal/repo/notification/notification_repo.go
+++ b/internal/repo/notification/notification_repo.go
@@ -137,3 +137,19 @@ func (nr *notificationRepo) CountNotificationByUser(ctx 
context.Context, cond *e
        }
        return count, err
 }
+
+func (nr *notificationRepo) DeleteNotification(ctx context.Context, userID 
string) (err error) {
+       _, err = nr.data.DB.Context(ctx).Where("user_id = ?", 
userID).Delete(&entity.Notification{})
+       if err != nil {
+               return 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+       }
+       return
+}
+
+func (nr *notificationRepo) DeleteUserNotificationConfig(ctx context.Context, 
userID string) (err error) {
+       _, err = nr.data.DB.Context(ctx).Where("user_id = ?", 
userID).Delete(&entity.UserNotificationConfig{})
+       if err != nil {
+               return 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+       }
+       return
+}
diff --git a/internal/repo/plugin_config/plugin_user_config_repo.go 
b/internal/repo/plugin_config/plugin_user_config_repo.go
index 5b3b54de..3ab011ef 100644
--- a/internal/repo/plugin_config/plugin_user_config_repo.go
+++ b/internal/repo/plugin_config/plugin_user_config_repo.go
@@ -97,3 +97,11 @@ func (ur *pluginUserConfigRepo) GetPluginUserConfigPage(ctx 
context.Context, pag
        }
        return
 }
+
+func (ur *pluginUserConfigRepo) DeleteUserPluginConfig(ctx context.Context, 
userID string) (err error) {
+       _, err = ur.data.DB.Context(ctx).Where("user_id = ?", 
userID).Delete(&entity.PluginUserConfig{})
+       if err != nil {
+               err = 
errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+       }
+       return
+}
diff --git a/internal/service/activity_common/activity.go 
b/internal/service/activity_common/activity.go
index 6b3557c0..62a8bb88 100644
--- a/internal/service/activity_common/activity.go
+++ b/internal/service/activity_common/activity.go
@@ -37,7 +37,7 @@ type ActivityRepo interface {
        GetActivityTypeByObjectType(ctx context.Context, objectKey, action 
string) (activityType int, err error)
        GetActivity(ctx context.Context, session *xorm.Session, objectID, 
userID string, activityType int) (
                existsActivity *entity.Activity, exist bool, err error)
-       GetUserActivitysByActivityType(ctx context.Context, userID string, 
activityType int) (activityList []*entity.Activity, err error)
+       GetUserActivitiesByActivityType(ctx context.Context, userID string, 
activityType int) (activityList []*entity.Activity, err error)
        GetUserIDObjectIDActivitySum(ctx context.Context, userID, objectID 
string) (int, error)
        GetActivityTypeByConfigKey(ctx context.Context, configKey string) 
(activityType int, err error)
        AddActivity(ctx context.Context, activity *entity.Activity) (err error)
diff --git a/internal/service/badge/badge_service.go 
b/internal/service/badge/badge_service.go
index 0ab538a3..5ed4c157 100644
--- a/internal/service/badge/badge_service.go
+++ b/internal/service/badge/badge_service.go
@@ -45,6 +45,8 @@ type BadgeRepo interface {
 
        UpdateStatus(ctx context.Context, id string, status int8) (err error)
        UpdateAwardCount(ctx context.Context, badgeID string, awardCount int) 
(err error)
+
+       DeleteUserBadge(ctx context.Context, userID string) (err error)
 }
 
 type BadgeService struct {
diff --git a/internal/service/content/question_service.go 
b/internal/service/content/question_service.go
index 145f7da1..1a282142 100644
--- a/internal/service/content/question_service.go
+++ b/internal/service/content/question_service.go
@@ -1445,7 +1445,7 @@ func (qs *QuestionService) GetRecommendQuestionPage(ctx 
context.Context, req *sc
        if err != nil {
                return nil, 0, err
        }
-       activities, err := qs.activityRepo.GetUserActivitysByActivityType(ctx, 
req.LoginUserID, activityType)
+       activities, err := qs.activityRepo.GetUserActivitiesByActivityType(ctx, 
req.LoginUserID, activityType)
        if err != nil {
                return nil, 0, err
        }
diff --git a/internal/service/notification_common/notification.go 
b/internal/service/notification_common/notification.go
index 9d08e258..b967970b 100644
--- a/internal/service/notification_common/notification.go
+++ b/internal/service/notification_common/notification.go
@@ -55,6 +55,8 @@ type NotificationRepo interface {
        UpdateNotificationContent(ctx context.Context, notification 
*entity.Notification) (err error)
        GetById(ctx context.Context, id string) (*entity.Notification, bool, 
error)
        CountNotificationByUser(ctx context.Context, cond *entity.Notification) 
(int64, error)
+       DeleteNotification(ctx context.Context, userID string) (err error)
+       DeleteUserNotificationConfig(ctx context.Context, userID string) (err 
error)
 }
 
 type NotificationCommon struct {
diff --git a/internal/service/plugin_common/plugin_common_service.go 
b/internal/service/plugin_common/plugin_common_service.go
index ea6701bd..044f39cb 100644
--- a/internal/service/plugin_common/plugin_common_service.go
+++ b/internal/service/plugin_common/plugin_common_service.go
@@ -49,6 +49,7 @@ type PluginUserConfigRepo interface {
                pluginUserConfig *entity.PluginUserConfig, exist bool, err 
error)
        GetPluginUserConfigPage(ctx context.Context, page, pageSize int) (
                pluginUserConfigs []*entity.PluginUserConfig, total int64, err 
error)
+       DeleteUserPluginConfig(ctx context.Context, userID string) (err error)
 }
 
 // PluginCommonService user service
diff --git a/internal/service/user_admin/user_backyard.go 
b/internal/service/user_admin/user_backyard.go
index e7f63d5f..6f436b0c 100644
--- a/internal/service/user_admin/user_backyard.go
+++ b/internal/service/user_admin/user_backyard.go
@@ -27,8 +27,11 @@ import (
        "github.com/apache/incubator-answer/internal/base/translator"
        "github.com/apache/incubator-answer/internal/base/validator"
        answercommon 
"github.com/apache/incubator-answer/internal/service/answer_common"
+       "github.com/apache/incubator-answer/internal/service/badge"
        "github.com/apache/incubator-answer/internal/service/comment_common"
        "github.com/apache/incubator-answer/internal/service/export"
+       notificationcommon 
"github.com/apache/incubator-answer/internal/service/notification_common"
+       "github.com/apache/incubator-answer/internal/service/plugin_common"
        questioncommon 
"github.com/apache/incubator-answer/internal/service/question_common"
        "github.com/apache/incubator-answer/pkg/token"
        "net/mail"
@@ -79,6 +82,9 @@ type UserAdminService struct {
        answerCommonRepo      answercommon.AnswerRepo
        commentCommonRepo     comment_common.CommentCommonRepo
        userExternalLoginRepo user_external_login.UserExternalLoginRepo
+       notificationRepo      notificationcommon.NotificationRepo
+       pluginUserConfigRepo  plugin_common.PluginUserConfigRepo
+       badgeRepo             badge.BadgeRepo
 }
 
 // NewUserAdminService new user admin service
@@ -94,6 +100,9 @@ func NewUserAdminService(
        answerCommonRepo answercommon.AnswerRepo,
        commentCommonRepo comment_common.CommentCommonRepo,
        userExternalLoginRepo user_external_login.UserExternalLoginRepo,
+       notificationRepo notificationcommon.NotificationRepo,
+       pluginUserConfigRepo plugin_common.PluginUserConfigRepo,
+       badgeRepo badge.BadgeRepo,
 ) *UserAdminService {
        return &UserAdminService{
                userRepo:              userRepo,
@@ -107,6 +116,9 @@ func NewUserAdminService(
                answerCommonRepo:      answerCommonRepo,
                commentCommonRepo:     commentCommonRepo,
                userExternalLoginRepo: userExternalLoginRepo,
+               notificationRepo:      notificationRepo,
+               pluginUserConfigRepo:  pluginUserConfigRepo,
+               badgeRepo:             badgeRepo,
        }
 }
 
@@ -154,10 +166,7 @@ func (us *UserAdminService) UpdateUserStatus(ctx 
context.Context, req *schema.Up
        }
 
        if req.IsDeleted() {
-               err := 
us.userExternalLoginRepo.DeleteUserExternalLoginByUserID(ctx, userInfo.ID)
-               if err != nil {
-                       log.Errorf("remove all user external login error: %v", 
err)
-               }
+               us.removeAllUserConfiguration(ctx, userInfo.ID)
        }
 
        // if user reputation is zero means this user is inactive, so try to 
activate this user.
@@ -167,6 +176,30 @@ func (us *UserAdminService) UpdateUserStatus(ctx 
context.Context, req *schema.Up
        return nil
 }
 
+// removeAllUserConfiguration remove all user configuration
+func (us *UserAdminService) removeAllUserConfiguration(ctx context.Context, 
userID string) {
+       err := us.userExternalLoginRepo.DeleteUserExternalLoginByUserID(ctx, 
userID)
+       if err != nil {
+               log.Errorf("remove all user external login error: %v", err)
+       }
+       err = us.notificationRepo.DeleteNotification(ctx, userID)
+       if err != nil {
+               log.Errorf("remove all user notification error: %v", err)
+       }
+       err = us.notificationRepo.DeleteUserNotificationConfig(ctx, userID)
+       if err != nil {
+               log.Errorf("remove all user notification config error: %v", err)
+       }
+       err = us.pluginUserConfigRepo.DeleteUserPluginConfig(ctx, userID)
+       if err != nil {
+               log.Errorf("remove all user plugin config error: %v", err)
+       }
+       err = us.badgeRepo.DeleteUserBadge(ctx, userID)
+       if err != nil {
+               log.Errorf("remove all user badge error: %v", err)
+       }
+}
+
 // removeAllUserCreatedContent remove all user created content
 func (us *UserAdminService) removeAllUserCreatedContent(ctx context.Context, 
userID string) {
        if err := us.questionCommonRepo.RemoveAllUserQuestion(ctx, userID); err 
!= nil {

Reply via email to