LinkinStars commented on code in PR #980:
URL: https://github.com/apache/incubator-answer/pull/980#discussion_r1635124374


##########
internal/service/user_admin/user_backyard.go:
##########
@@ -345,6 +346,73 @@ func (us *UserAdminService) UpdateUserPassword(ctx 
context.Context, req *schema.
        return
 }
 
+// EditUserProfile edit user profile
+func (us *UserAdminService) EditUserProfile(ctx context.Context, req 
*schema.EditUserProfileReq) (
+       errFields []*validator.FormErrorField, err error) {
+       if req.UserID == req.LoginUserID {
+               return nil, 
errors.BadRequest(reason.AdminCannotEditTheirProfile)
+       }
+       userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
+       if err != nil {
+               return nil, err
+       }
+       if !exist {
+               return nil, errors.BadRequest(reason.UserNotFound)
+       }
+
+       if checker.IsInvalidUsername(req.Username) {
+               return append(errFields, &validator.FormErrorField{
+                       ErrorField: "username",
+                       ErrorMsg:   reason.UsernameInvalid,
+               }), errors.BadRequest(reason.UsernameInvalid)
+       }
+
+       if !req.IsAdmin && checker.IsReservedUsername(req.Username) {
+               return append(errFields, &validator.FormErrorField{
+                       ErrorField: "username",
+                       ErrorMsg:   reason.UsernameInvalid,
+               }), errors.BadRequest(reason.UsernameInvalid)
+       } else if req.IsAdmin && checker.IsUsersIgnorePath(req.Username) {
+               return append(errFields, &validator.FormErrorField{
+                       ErrorField: "username",
+                       ErrorMsg:   reason.UsernameInvalid,
+               }), errors.BadRequest(reason.UsernameInvalid)
+       }

Review Comment:
   Since this route is registered under `/admin`, the user accessing this route 
must be an admin. So there should be no need to check whether it is admin or 
not here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to