A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(admin): add restriction about admin modify their password
LinkinStars15390adbfcd5
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 69a39c12..237d410c 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -35,6 +35,8 @@ backend:other: Email and password do not match.error:admin:+ cannot_update_their_password:+ other: You cannot modify your password.email_or_password_wrong:other: Email and password do not match.answer:diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.goindex a33e33cc..86b448d9 100644--- a/internal/base/reason/reason.go+++ b/internal/base/reason/reason.go@@ -64,4 +64,5 @@ const (TagCannotSetSynonymAsItself = "error.tag.cannot_set_synonym_as_itself"NotAllowedRegistration = "error.user.not_allowed_registration"SMTPConfigFromNameCannotBeEmail = "error.smtp.config_from_name_cannot_be_email"+ AdminCannotUpdateTheirPassword = "error.admin.cannot_update_their_password")diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.goindex ae09ce85..5712610d 100644--- a/internal/service/user_admin/user_backyard.go+++ b/internal/service/user_admin/user_backyard.go@@ -153,6 +153,10 @@ func (us *UserAdminService) AddUser(ctx context.Context, req *schema.AddUserReq)// UpdateUserPassword update user passwordfunc (us *UserAdminService) UpdateUserPassword(ctx context.Context, req *schema.UpdateUserPasswordReq) (err error) {+ // Users cannot modify their password+ if req.UserID == req.LoginUserID {+ return errors.BadRequest(reason.AdminCannotUpdateTheirPassword)+ }userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)if err != nil {return err