mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 04:25:59 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
Conflicts: internal/push/sdk/tpns-server-sdk-go/go/auth/auth.go pkg/proto/group/group.proto
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
rpc "Open_IM/pkg/proto/auth"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -149,7 +148,7 @@ func UserToken(c *gin.Context) {
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.ParseTokenReq true "secret为openIM密钥, 详细见服务端config.yaml secret字段<br>platform为平台ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.ParseTokenResp{Data=api.ExpireTime}
|
||||
// @Success 0 {object} api.ParseTokenResp{Map=api.ExpireTime}
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /auth/parse_token [post]
|
||||
|
||||
@@ -343,7 +343,7 @@ package friend
|
||||
// utils.CopyStructFields(&black, v)
|
||||
// resp.BlackUserInfoList = append(resp.BlackUserInfoList, &black)
|
||||
// }
|
||||
// resp.Data = jsonData.JsonDataList(resp.BlackUserInfoList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.BlackUserInfoList)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetBlacklist api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
@@ -561,7 +561,7 @@ package friend
|
||||
// }
|
||||
//
|
||||
// resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, FriendInfoList: RpcResp.FriendInfoList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.FriendInfoList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.FriendInfoList)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// //c.JSON(http.StatusOK, resp)
|
||||
@@ -618,7 +618,7 @@ package friend
|
||||
// }
|
||||
//
|
||||
// resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
@@ -672,7 +672,7 @@ package friend
|
||||
// return
|
||||
// }
|
||||
// resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
|
||||
@@ -142,7 +142,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// memberListResp := api.GetGroupMembersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
||||
// memberListResp.Data = jsonData.JsonDataList(RpcResp.MemberList)
|
||||
// memberListResp.Map = jsonData.JsonDataList(RpcResp.MemberList)
|
||||
// log.NewInfo(req.OperationID, "GetGroupMembersInfo api return ", memberListResp)
|
||||
// c.JSON(http.StatusOK, memberListResp)
|
||||
//}
|
||||
@@ -186,7 +186,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// memberListResp := api.GetGroupMemberListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, MemberList: RpcResp.MemberList, NextSeq: RpcResp.NextSeq}
|
||||
// memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
// memberListResp.Map = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
//
|
||||
// log.NewInfo(req.OperationID, "FindGroupMemberAll api return ", memberListResp)
|
||||
// c.JSON(http.StatusOK, memberListResp)
|
||||
@@ -243,7 +243,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// memberListResp := api.GetGroupAllMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
||||
// memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
// memberListResp.Map = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
// log.NewInfo(req.OperationID, "GetGroupAllMember api return ", len(memberListResp.MemberList))
|
||||
// c.JSON(http.StatusOK, memberListResp)
|
||||
//}
|
||||
@@ -298,7 +298,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, GroupInfoList: RpcResp.GroupList}
|
||||
// GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
// GroupListResp.Map = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
// log.NewInfo(req.OperationID, "FindJoinedGroup api return ", GroupListResp)
|
||||
// c.JSON(http.StatusOK, GroupListResp)
|
||||
//}
|
||||
@@ -437,7 +437,7 @@ package group
|
||||
//// resp := api.CreateGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
//// if RpcResp.ErrCode == 0 {
|
||||
//// utils.CopyStructFields(&resp.GroupInfo, RpcResp.GroupInfo)
|
||||
//// resp.Data = jsonData.JsonDataOne(&resp.GroupInfo)
|
||||
//// resp.Map = jsonData.JsonDataOne(&resp.GroupInfo)
|
||||
//// }
|
||||
//// log.NewInfo(req.OperationID, "CreateGroup api return ", resp)
|
||||
//// c.JSON(http.StatusOK, resp)
|
||||
@@ -496,7 +496,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}, GroupRequestList: reply.GroupRequestList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.GroupRequestList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.GroupRequestList)
|
||||
// log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
@@ -567,7 +567,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// resp := api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, GroupInfoList: RpcResp.GroupInfoList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
// log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -67,7 +69,8 @@ func KickGroupMember(c *gin.Context) {
|
||||
// 默认 全部自动
|
||||
NewRpc(NewApiBind[apistruct.KickGroupMemberReq, apistruct.KickGroupMemberResp](c), "", group.NewGroupClient, group.GroupClient.KickGroupMember).Execute()
|
||||
// 可以自定义编辑请求和响应
|
||||
NewRpc(NewApiBind[api_struct.KickGroupMemberReq, api_struct.KickGroupMemberResp](c), "", group.NewGroupClient, group.GroupClient.KickGroupMember).Before(func(apiReq *api_struct.KickGroupMemberReq, rpcReq *group.KickGroupMemberReq, bind func() error) error {
|
||||
a := NewRpc(NewApiBind[api_struct.KickGroupMemberReq, api_struct.KickGroupMemberResp](c), "", group.NewGroupClient, group.GroupClient.KickGroupMember)
|
||||
a.Before(func(apiReq *api_struct.KickGroupMemberReq, rpcReq *group.KickGroupMemberReq, bind func() error) error {
|
||||
return bind()
|
||||
}).After(func(rpcResp *group.KickGroupMemberResp, apiResp *api_struct.KickGroupMemberResp, bind func() error) error {
|
||||
return bind()
|
||||
@@ -102,6 +105,22 @@ func (a *RpcRun[A, B, C, D, Z]) After(fn func(rpcResp D, apiResp *B, bind func()
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *RpcRun[A, B, C, D, Z]) execute() (*B, error) {
|
||||
userID, err := a.bind.OpUserID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opID := a.bind.OperationID()
|
||||
var rpcReq C // C type => *Struct
|
||||
rpcReq = reflect.New(reflect.TypeOf(rpcReq).Elem()).Interface().(C)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *RpcRun[A, B, C, D, Z]) Execute() {
|
||||
|
||||
}
|
||||
|
||||
func GetGrpcConn(name string) (*grpc.ClientConn, error) {
|
||||
return nil, errors.New("todo")
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ package group
|
||||
// return
|
||||
// }
|
||||
// GroupListResp := api.GetJoinedSuperGroupListResp{GetJoinedGroupListResp: api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupList}}
|
||||
// GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
// GroupListResp.Map = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
// log.NewInfo(req.OperationID, "GetJoinedSuperGroupList api return ", GroupListResp)
|
||||
// c.JSON(http.StatusOK, GroupListResp)
|
||||
//}
|
||||
@@ -83,7 +83,7 @@ package group
|
||||
// }
|
||||
//
|
||||
// resp := api.GetSuperGroupsInfoResp{GetGroupInfoResp: api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupInfoList}}
|
||||
// resp.Data = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
// resp.Map = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
// log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -165,7 +164,7 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
}
|
||||
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
log.Error(c.PostForm("operationID"), "content to Data struct err", err.Error())
|
||||
log.Error(c.PostForm("operationID"), "content to Map struct err", err.Error())
|
||||
return
|
||||
} else if err := validate.Struct(data); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 403, "errMsg": err.Error()})
|
||||
@@ -298,7 +297,7 @@ func ManagementBatchSendMsg(c *gin.Context) {
|
||||
}
|
||||
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
log.Error(c.PostForm("operationID"), "content to Data struct err", err.Error())
|
||||
log.Error(c.PostForm("operationID"), "content to Map struct err", err.Error())
|
||||
return
|
||||
} else if err := validate.Struct(data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 403, "errMsg": err.Error()})
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -565,7 +564,7 @@ func GetUserFriendWorkMoments(c *gin.Context) {
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
//if err := utils.CopyStructFields(&resp.Data.WorkMoments, respPb.WorkMoments); err != nil {
|
||||
//if err := utils.CopyStructFields(&resp.Map.WorkMoments, respPb.WorkMoments); err != nil {
|
||||
// log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
//}
|
||||
resp.Data.WorkMoments = []*api.WorkMoment{}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
cacheRpc "Open_IM/pkg/proto/cache"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdkws"
|
||||
@@ -156,7 +155,7 @@ func GetBlackIDListFromCache(c *gin.Context) {
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetUsersInfoReq true "请求体"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetUsersInfoResp{Data=[]open_im_sdk.PublicUserInfo}
|
||||
// @Success 0 {object} api.GetUsersInfoResp{Map=[]open_im_sdk.PublicUserInfo}
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /user/get_users_info [post]
|
||||
|
||||
@@ -36,6 +36,7 @@ func NewRpcServer(registerIPInConfig string, port int, registerName string, zkSe
|
||||
return nil, err
|
||||
}
|
||||
s.RegisterCenter = zkClient
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass boo
|
||||
case constant.WSGetNewestSeq:
|
||||
data := open_im_sdk.GetMaxAndMinSeqReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.Error(operationID, "Decode Data struct err", err.Error(), r)
|
||||
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
||||
return false, 203, err.Error(), nil
|
||||
}
|
||||
if err := validate.Struct(data); err != nil {
|
||||
@@ -74,7 +74,7 @@ func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass boo
|
||||
case constant.WSSendMsg:
|
||||
data := open_im_sdk.MsgData{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.Error(operationID, "Decode Data struct err", err.Error(), r)
|
||||
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
||||
return false, 203, err.Error(), nil
|
||||
}
|
||||
if err := validate.Struct(data); err != nil {
|
||||
@@ -86,7 +86,7 @@ func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass boo
|
||||
case constant.WSSendSignalMsg:
|
||||
data := pbRtc.SignalReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.Error(operationID, "Decode Data struct err", err.Error(), r)
|
||||
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
||||
return false, 203, err.Error(), nil
|
||||
}
|
||||
if err := validate.Struct(data); err != nil {
|
||||
@@ -98,7 +98,7 @@ func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass boo
|
||||
case constant.WSPullMsgBySeqList:
|
||||
data := open_im_sdk.PullMessageBySeqListReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.Error(operationID, "Decode Data struct err", err.Error(), r)
|
||||
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
||||
return false, 203, err.Error(), nil
|
||||
}
|
||||
if err := validate.Struct(data); err != nil {
|
||||
@@ -110,7 +110,7 @@ func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass boo
|
||||
case constant.WsSetBackgroundStatus:
|
||||
data := open_im_sdk.SetAppBackgroundStatusReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.Error(operationID, "Decode Data struct err", err.Error(), r)
|
||||
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
||||
return false, 203, err.Error(), nil
|
||||
}
|
||||
if err := validate.Struct(data); err != nil {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
b64 "encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
AccessID string
|
||||
SecretKey string
|
||||
}
|
||||
|
||||
var UseSignAuthored = true
|
||||
|
||||
func (a *Auther) Auth(req *http.Request, useSignAuthored bool, auth Auther, reqBody string) {
|
||||
|
||||
if useSignAuthored {
|
||||
now := time.Now()
|
||||
timeStamp := now.Unix()
|
||||
req.Header.Add("AccessId", auth.AccessID)
|
||||
req.Header.Add("TimeStamp", strconv.Itoa(int(timeStamp)))
|
||||
sign := GenSign(uint64(timeStamp), auth.AccessID, auth.SecretKey, reqBody)
|
||||
req.Header.Add("Sign", sign)
|
||||
} else {
|
||||
author := makeAuthHeader(a.AccessID, a.SecretKey)
|
||||
//log.Printf("author string:%v", author)
|
||||
req.Header.Add("Authorization", author)
|
||||
}
|
||||
//req.Header.Add("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
func makeAuthHeader(appID, secretKey string) string {
|
||||
base64Str := base64.StdEncoding.EncodeToString(
|
||||
[]byte(
|
||||
fmt.Sprintf("%s:%s", appID, secretKey),
|
||||
),
|
||||
)
|
||||
return fmt.Sprintf("Basic %s", base64Str)
|
||||
}
|
||||
|
||||
func GenSign(timeStamp uint64, accessId string, secretKey, requestBody string) string {
|
||||
signBody := strconv.Itoa(int(timeStamp)) + accessId + requestBody
|
||||
// Create a new HMAC by defining the hash type and the key (as byte array)
|
||||
h := hmac.New(sha256.New, []byte(secretKey))
|
||||
// Write Map to it
|
||||
h.Write([]byte(signBody))
|
||||
|
||||
// Get result and encode as hexadecimal string
|
||||
sha := hex.EncodeToString(h.Sum(nil))
|
||||
//fmt.Println()
|
||||
//fmt.Println("timeStamp: " + strconv.Itoa(int(timeStamp)) + " accessID:" + accessId + " body:" + requestBody)
|
||||
sEnc := b64.StdEncoding.EncodeToString([]byte(sha))
|
||||
//fmt.Println("final Result " + sEnc)
|
||||
return sEnc
|
||||
}
|
||||
+17
-11
@@ -5,6 +5,7 @@ import (
|
||||
"Open_IM/internal/common/rpc_server"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/controller"
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
@@ -23,8 +24,11 @@ func NewRpcAuthServer(port int) *rpcAuth {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var redis cache.RedisClient
|
||||
redis.InitRedis()
|
||||
return &rpcAuth{
|
||||
RpcServer: r,
|
||||
RpcServer: r,
|
||||
AuthInterface: controller.NewAuthController(redis.GetClient(), config.Config.TokenPolicy.AccessSecret, config.Config.TokenPolicy.AccessExpire),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +68,7 @@ func (s *rpcAuth) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbA
|
||||
if _, err := check.GetUsersInfo(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
token, err := s.CreateToken(ctx, req.UserID, int(req.PlatformID), config.Config.TokenPolicy.AccessExpire)
|
||||
token, err := s.CreateToken(ctx, req.UserID, constant.PlatformIDToName(int(req.PlatformID)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,39 +77,41 @@ func (s *rpcAuth) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbA
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *rpcAuth) parseToken(ctx context.Context, tokensString, operationID string) (claims *tokenverify.Claims, err error) {
|
||||
func (s *rpcAuth) parseToken(ctx context.Context, tokensString string) (claims *tokenverify.Claims, err error) {
|
||||
claims, err = tokenverify.GetClaimFromToken(tokensString)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
m, err := s.GetTokens(ctx, claims.UID, claims.Platform)
|
||||
m, err := s.GetTokensWithoutError(ctx, claims.UID, claims.Platform)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(m) == 0 {
|
||||
return nil, constant.ErrTokenNotExist.Wrap()
|
||||
}
|
||||
if v, ok := m[tokensString]; ok {
|
||||
switch v {
|
||||
case constant.NormalToken:
|
||||
return claims, nil
|
||||
case constant.KickedToken:
|
||||
return nil, utils.Wrap(constant.ErrTokenKicked, "this token has been kicked by other same terminal ")
|
||||
return nil, constant.ErrTokenKicked.Wrap()
|
||||
default:
|
||||
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||
}
|
||||
}
|
||||
return nil, utils.Wrap(constant.ErrTokenNotExist, "redis token map not find")
|
||||
return nil, constant.ErrTokenNotExist.Wrap()
|
||||
}
|
||||
|
||||
func (s *rpcAuth) ParseToken(ctx context.Context, req *pbAuth.ParseTokenReq) (*pbAuth.ParseTokenResp, error) {
|
||||
resp := pbAuth.ParseTokenResp{}
|
||||
claims, err := s.parseToken(ctx, req.Token, req.OperationID)
|
||||
func (s *rpcAuth) ParseToken(ctx context.Context, req *pbAuth.ParseTokenReq) (resp *pbAuth.ParseTokenResp, err error) {
|
||||
resp = &pbAuth.ParseTokenResp{}
|
||||
claims, err := s.parseToken(ctx, req.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.UserID = claims.UID
|
||||
resp.Platform = claims.Platform
|
||||
resp.ExpireTimeSeconds = claims.ExpiresAt.Unix()
|
||||
return &resp, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *rpcAuth) ForceLogout(ctx context.Context, req *pbAuth.ForceLogoutReq) (*pbAuth.ForceLogoutResp, error) {
|
||||
|
||||
@@ -119,7 +119,7 @@ func CallbackBeforeMemberJoinGroup(ctx context.Context, operationID string, grou
|
||||
return err
|
||||
}
|
||||
|
||||
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (err error) {
|
||||
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfo) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", *req)
|
||||
}()
|
||||
|
||||
@@ -84,7 +84,7 @@ func DbToPbGroupRequest(m *relation.GroupRequestModel, user *open_im_sdk.PublicU
|
||||
func DbToPbGroupAbstractInfo(groupID string, groupMemberNumber int32, groupMemberListHash uint64) *pbGroup.GroupAbstractInfo {
|
||||
return &pbGroup.GroupAbstractInfo{
|
||||
GroupID: groupID,
|
||||
GroupMemberNumber: groupMemberNumber,
|
||||
GroupMemberNumber: uint32(groupMemberNumber),
|
||||
GroupMemberListHash: groupMemberListHash,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func UpdateGroupMemberMutedTimeMap(t time.Time) map[string]any {
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateGroupMemberMap(req *pbGroup.SetGroupMemberInfoReq) map[string]any {
|
||||
func UpdateGroupMemberMap(req *pbGroup.SetGroupMemberInfo) map[string]any {
|
||||
m := make(map[string]any)
|
||||
if req.Nickname != nil {
|
||||
m["nickname"] = req.Nickname.Value
|
||||
|
||||
+77
-39
@@ -30,7 +30,6 @@ import (
|
||||
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
type groupServer struct {
|
||||
@@ -75,7 +74,7 @@ func NewGroupServer(port int) *groupServer {
|
||||
|
||||
//conns, err := g.registerCenter.GetConns(config.Config.RpcRegisterName.OpenImConversationName)
|
||||
|
||||
g.GroupInterface = controller.NewGroupInterface(controller.NewGroupDatabase(mysql.GormConn(), redis.GetClient(), mongo.GetClient()))
|
||||
g.GroupInterface = controller.NewGroupInterface(mysql.GormConn(), redis.GetClient(), mongo.GetClient())
|
||||
return &g
|
||||
}
|
||||
|
||||
@@ -191,7 +190,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := s.GroupInterface.CreateGroup(ctx, []*relation.GroupModel{group}, groupMembers); err != nil {
|
||||
if err := s.GroupInterface.CreateGroup(ctx, []*relationTb.GroupModel{group}, groupMembers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupInfo = DbToPbGroupInfo(group, req.OwnerUserID, uint32(len(userIDs)))
|
||||
@@ -287,9 +286,9 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return nil, constant.ErrNoPermission.Wrap("not in group")
|
||||
}
|
||||
if !(member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin) {
|
||||
var requests []*relation.GroupRequestModel
|
||||
var requests []*relationTb.GroupRequestModel
|
||||
for _, userID := range req.InvitedUserIDs {
|
||||
requests = append(requests, &relation.GroupRequestModel{
|
||||
requests = append(requests, &relationTb.GroupRequestModel{
|
||||
UserID: userID,
|
||||
GroupID: req.GroupID,
|
||||
JoinSource: constant.JoinByInvitation,
|
||||
@@ -951,50 +950,79 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) {
|
||||
_, err := s.SetGroupMemberInfo(ctx, &pbGroup.SetGroupMemberInfoReq{GroupID: req.GroupID, UserID: req.UserID, Nickname: wrapperspb.String(req.Nickname)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbGroup.SetGroupMemberNicknameResp{}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (*pbGroup.SetGroupMemberInfoResp, error) {
|
||||
resp := &pbGroup.SetGroupMemberInfoResp{}
|
||||
if req.RoleLevel != nil && req.RoleLevel.Value == constant.GroupOwner {
|
||||
return nil, constant.ErrNoPermission.Wrap("set group owner")
|
||||
if len(req.Members) == 0 {
|
||||
return nil, constant.ErrArgs.Wrap("members empty")
|
||||
}
|
||||
group, err := s.GroupInterface.TakeGroup(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if group.Status == constant.GroupStatusDismissed {
|
||||
return nil, constant.ErrArgs.Wrap("group status is dismissed")
|
||||
}
|
||||
member, err := s.GroupInterface.TakeGroupMember(ctx, req.GroupID, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tracelog.GetOpUserID(ctx) == req.UserID {
|
||||
if req.RoleLevel != nil {
|
||||
return nil, constant.ErrArgs.Wrap("update role level")
|
||||
duplicateMap := make(map[[2]string]struct{})
|
||||
userIDMap := make(map[string]struct{})
|
||||
groupIDMap := make(map[string]struct{})
|
||||
for _, member := range req.Members {
|
||||
key := [...]string{member.GroupID, member.UserID}
|
||||
if _, ok := duplicateMap[key]; ok {
|
||||
return nil, constant.ErrArgs.Wrap("group user duplicate")
|
||||
}
|
||||
} else if !tokenverify.IsAppManagerUid(ctx) {
|
||||
opMember, err := s.GroupInterface.TakeGroupMember(ctx, req.GroupID, tracelog.GetOpUserID(ctx))
|
||||
if err != nil {
|
||||
duplicateMap[key] = struct{}{}
|
||||
userIDMap[member.UserID] = struct{}{}
|
||||
groupIDMap[member.GroupID] = struct{}{}
|
||||
}
|
||||
groupIDs := utils.Keys(groupIDMap)
|
||||
userIDs := utils.Keys(userIDMap)
|
||||
members, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, append(userIDs, tracelog.GetOpUserID(ctx)), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, member := range members {
|
||||
delete(duplicateMap, [...]string{member.GroupID, member.UserID})
|
||||
}
|
||||
if len(duplicateMap) > 0 {
|
||||
return nil, constant.ErrArgs.Wrap("group not found or user not in group")
|
||||
}
|
||||
memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string {
|
||||
return [...]string{e.GroupID, e.UserID}
|
||||
})
|
||||
if !tokenverify.IsAppManagerUid(ctx) {
|
||||
opUserID := tracelog.GetOpUserID(ctx)
|
||||
for _, member := range members {
|
||||
if member.UserID == opUserID {
|
||||
continue
|
||||
}
|
||||
opMember, ok := memberMap[[...]string{member.GroupID, member.UserID}]
|
||||
if !ok {
|
||||
return nil, constant.ErrArgs.Wrap(fmt.Sprintf("user %s not in group %s", opUserID, member.GroupID))
|
||||
}
|
||||
if member.RoleLevel >= opMember.RoleLevel {
|
||||
return nil, constant.ErrNoPermission.Wrap(fmt.Sprintf("group %s : %s RoleLevel %d >= %s RoleLevel %d", member.GroupID, member.UserID, member.RoleLevel, opMember.UserID, opMember.RoleLevel))
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, member := range req.Members {
|
||||
if member.RoleLevel == nil {
|
||||
continue
|
||||
}
|
||||
if memberMap[[...]string{member.GroupID, member.UserID}].RoleLevel == constant.GroupOwner {
|
||||
return nil, constant.ErrArgs.Wrap(fmt.Sprintf("group %s user %s is owner", member.GroupID, member.UserID))
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(req.Members); i++ {
|
||||
if err := CallbackBeforeSetGroupMemberInfo(ctx, req.Members[i]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opMember.RoleLevel <= member.RoleLevel {
|
||||
return nil, constant.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel, member.RoleLevel))
|
||||
}
|
||||
err = s.GroupInterface.UpdateGroupMembers(ctx, utils.Slice(req.Members, func(e *pbGroup.SetGroupMemberInfo) *controller.BatchUpdateGroupMember {
|
||||
return &controller.BatchUpdateGroupMember{
|
||||
GroupID: e.GroupID,
|
||||
UserID: e.UserID,
|
||||
Map: UpdateGroupMemberMap(e),
|
||||
}
|
||||
}
|
||||
if err := CallbackBeforeSetGroupMemberInfo(ctx, req); err != nil {
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.GroupInterface.UpdateGroupMember(ctx, req.GroupID, req.UserID, UpdateGroupMemberMap(req)); err != nil {
|
||||
return nil, err
|
||||
for _, member := range req.Members {
|
||||
chat.GroupMemberInfoSetNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), member.GroupID, member.UserID)
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.GroupID, req.UserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -1038,3 +1066,13 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberUserID(ctx context.Context, req *pbGroup.GetGroupMemberUserIDReq) (*pbGroup.GetGroupMemberUserIDResp, error) {
|
||||
resp := &pbGroup.GetGroupMemberUserIDResp{}
|
||||
userIDs, err := s.GroupInterface.FindGroupMemberUserID(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.UserIDs = userIDs
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user