Skip to content

Commit

Permalink
Merge branch 'dev' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Dec 9, 2024
2 parents 21655f6 + 2cc7b33 commit 1aed48a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7831,7 +7831,7 @@ const docTemplate = `{
"display_name": {
"type": "string",
"maxLength": 30,
"minLength": 4
"minLength": 2
},
"email": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7804,7 +7804,7 @@
"display_name": {
"type": "string",
"maxLength": 30,
"minLength": 4
"minLength": 2
},
"email": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ definitions:
properties:
display_name:
maxLength: 30
minLength: 4
minLength: 2
type: string
email:
maxLength: 500
Expand Down
10 changes: 10 additions & 0 deletions internal/repo/user_external_login/user_external_login_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/backyard_user_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type EditUserProfileReq struct {

// AddUserReq add user request
type AddUserReq struct {
DisplayName string `validate:"required,gte=4,lte=30" json:"display_name"`
DisplayName string `validate:"required,gte=2,lte=30" json:"display_name"`
Email string `validate:"required,email,gt=0,lte=500" json:"email"`
Password string `validate:"required,gte=8,lte=32" json:"password"`
LoginUserID string `json:"-"`
Expand Down
11 changes: 11 additions & 0 deletions internal/service/user_admin/user_backyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -102,6 +105,7 @@ func NewUserAdminService(
questionCommonRepo: questionCommonRepo,
answerCommonRepo: answerCommonRepo,
commentCommonRepo: commentCommonRepo,
userExternalLoginRepo: userExternalLoginRepo,
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gravatar/gravatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGetAvatarURL(t *testing.T) {
{
name: "[email protected]",
args: args{email: "[email protected]"},
want: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7",
want: "https://www.gravatar.com/avatar/7296942c1f63d97f6c124705142009867638f7b3dbcdadd0cb1bcb40e427eb8e",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 1aed48a

Please sign in to comment.