Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove user config #1213

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/repo/activity_common/activity_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
9 changes: 9 additions & 0 deletions internal/repo/badge_award/badge_award_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,12 @@ func (r *badgeAwardRepo) GetByUserIdAndBadgeIdAndAwardKey(ctx context.Context, u
}
return
}

// DeleteUserBadgeAward delete user badge award
func (r *badgeAwardRepo) DeleteUserBadgeAward(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
}
16 changes: 16 additions & 0 deletions internal/repo/notification/notification_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions internal/repo/plugin_config/plugin_user_config_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion internal/service/activity_common/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/service/badge/badge_award_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type BadgeAwardRepo interface {

GetByUserIdAndBadgeId(ctx context.Context, userID string, badgeID string) (badgeAward *entity.BadgeAward, exists bool, err error)
GetByUserIdAndBadgeIdAndAwardKey(ctx context.Context, userID string, badgeID string, awardKey string) (badgeAward *entity.BadgeAward, exists bool, err error)

DeleteUserBadgeAward(ctx context.Context, userID string) (err error)
}

type BadgeAwardService struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/content/question_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions internal/service/notification_common/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/service/plugin_common/plugin_common_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 37 additions & 4 deletions internal/service/user_admin/user_backyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
badgeAwardRepo badge.BadgeAwardRepo
}

// NewUserAdminService new user admin service
Expand All @@ -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,
badgeAwardRepo badge.BadgeAwardRepo,
) *UserAdminService {
return &UserAdminService{
userRepo: userRepo,
Expand All @@ -107,6 +116,9 @@ func NewUserAdminService(
answerCommonRepo: answerCommonRepo,
commentCommonRepo: commentCommonRepo,
userExternalLoginRepo: userExternalLoginRepo,
notificationRepo: notificationRepo,
pluginUserConfigRepo: pluginUserConfigRepo,
badgeAwardRepo: badgeAwardRepo,
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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.badgeAwardRepo.DeleteUserBadgeAward(ctx, userID)
if err != nil {
log.Errorf("remove all user badge award 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 {
Expand Down