Skip to content

Commit

Permalink
fix(admin): add restriction about admin modify their password
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Feb 23, 2023
1 parent 66510fc commit 15390ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions i18n/en_US.yaml
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions internal/base/reason/reason.go
Expand Up @@ -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"
)
4 changes: 4 additions & 0 deletions internal/service/user_admin/user_backyard.go
Expand Up @@ -153,6 +153,10 @@ func (us *UserAdminService) AddUser(ctx context.Context, req *schema.AddUserReq)

// UpdateUserPassword update user password
func (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
Expand Down

0 comments on commit 15390ad

Please sign in to comment.