mirror of https://gitee.com/answerdev/answer.git
fix(admin): add restriction about admin modify their status
This commit is contained in:
parent
15390adbfc
commit
4ca2429d19
|
@ -37,6 +37,8 @@ backend:
|
||||||
admin:
|
admin:
|
||||||
cannot_update_their_password:
|
cannot_update_their_password:
|
||||||
other: You cannot modify your password.
|
other: You cannot modify your password.
|
||||||
|
cannot_modify_self_status:
|
||||||
|
other: You cannot modify your status.
|
||||||
email_or_password_wrong:
|
email_or_password_wrong:
|
||||||
other: Email and password do not match.
|
other: Email and password do not match.
|
||||||
answer:
|
answer:
|
||||||
|
|
|
@ -65,4 +65,5 @@ const (
|
||||||
NotAllowedRegistration = "error.user.not_allowed_registration"
|
NotAllowedRegistration = "error.user.not_allowed_registration"
|
||||||
SMTPConfigFromNameCannotBeEmail = "error.smtp.config_from_name_cannot_be_email"
|
SMTPConfigFromNameCannotBeEmail = "error.smtp.config_from_name_cannot_be_email"
|
||||||
AdminCannotUpdateTheirPassword = "error.admin.cannot_update_their_password"
|
AdminCannotUpdateTheirPassword = "error.admin.cannot_update_their_password"
|
||||||
|
AdminCannotModifySelfStatus = "error.admin.cannot_modify_self_status"
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,6 +34,8 @@ func (uc *UserAdminController) UpdateUserStatus(ctx *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
|
|
||||||
err := uc.userService.UpdateUserStatus(ctx, req)
|
err := uc.userService.UpdateUserStatus(ctx, req)
|
||||||
handler.HandleResponse(ctx, err, nil)
|
handler.HandleResponse(ctx, err, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,9 @@ package schema
|
||||||
|
|
||||||
// UpdateUserStatusReq update user request
|
// UpdateUserStatusReq update user request
|
||||||
type UpdateUserStatusReq struct {
|
type UpdateUserStatusReq struct {
|
||||||
// user id
|
UserID string `validate:"required" json:"user_id"`
|
||||||
UserID string `validate:"required" json:"user_id"`
|
Status string `validate:"required,oneof=normal suspended deleted inactive" json:"status" enums:"normal,suspended,deleted,inactive"`
|
||||||
// user status
|
LoginUserID string `json:"-"`
|
||||||
Status string `validate:"required,oneof=normal suspended deleted inactive" json:"status" enums:"normal,suspended,deleted,inactive"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -61,6 +61,10 @@ func NewUserAdminService(
|
||||||
|
|
||||||
// UpdateUserStatus update user
|
// UpdateUserStatus update user
|
||||||
func (us *UserAdminService) UpdateUserStatus(ctx context.Context, req *schema.UpdateUserStatusReq) (err error) {
|
func (us *UserAdminService) UpdateUserStatus(ctx context.Context, req *schema.UpdateUserStatusReq) (err error) {
|
||||||
|
// Admin cannot modify their status
|
||||||
|
if req.UserID == req.LoginUserID {
|
||||||
|
return errors.BadRequest(reason.AdminCannotModifySelfStatus)
|
||||||
|
}
|
||||||
userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
|
userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue