Skip to content

Commit

Permalink
fix: modify user information must carry userID
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao authored and cubxxw committed Jul 29, 2023
1 parent b6484c2 commit 95ac6be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 0 additions & 4 deletions internal/api/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/checker"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mcontext"
"io"
"net"
"time"
Expand Down Expand Up @@ -196,9 +195,6 @@ func (o *ChatApi) UpdateUserInfo(c *gin.Context) {
apiresp.GinError(c, err) // 参数校验失败
return
}
if req.UserID == "" {
req.UserID = mcontext.GetOpUserID(c)
}
respUpdate, err := o.chatClient.UpdateUserInfo(c, &req)
if err != nil {
apiresp.GinError(c, err)
Expand Down
17 changes: 8 additions & 9 deletions internal/rpc/chat/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ func (o *chatSvr) UpdateUserInfo(ctx context.Context, req *chat.UpdateUserInfoRe
if err != nil {
return nil, err
}
if req.UserID == "" {
return nil, errs.ErrArgs.Wrap("user id is empty")
}
switch userType {
case constant.NormalUser:
if req.UserID == "" {
req.UserID = opUserID
}
//if req.UserID == "" {
// req.UserID = opUserID
//}
if req.UserID != opUserID {
return nil, errs.ErrNoPermission.Wrap("only admin can update other user info")
}
//if req.Email != nil {
// return nil, errs.ErrNoPermission.Wrap("email can not be updated")
//}
if req.AreaCode != nil {
return nil, errs.ErrNoPermission.Wrap("areaCode can not be updated")
}
Expand All @@ -55,9 +55,8 @@ func (o *chatSvr) UpdateUserInfo(ctx context.Context, req *chat.UpdateUserInfoRe
return nil, errs.ErrNoPermission.Wrap("level can not be updated")
}
case constant.AdminUser:
if req.UserID == "" {
return nil, errs.ErrArgs.Wrap("user id is empty")
}
default:
return nil, errs.ErrNoPermission.Wrap("user type error")
}
update, err := ToDBAttributeUpdate(req)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/proto/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
)

func (x *UpdateUserInfoReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
if x.Email != nil && x.Email.Value != "" {
if err := EmailCheck(x.Email.Value); err != nil {
return err
Expand Down

0 comments on commit 95ac6be

Please sign in to comment.