From 3bbf84861e6137b580cb72f495d77c7a7f7ae1f7 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 18 Apr 2022 10:53:23 +0800 Subject: [PATCH] organization --- cmd/open_im_api/main.go | 5 +++-- internal/rpc/group/group.go | 33 +++++++++++++++++++++++++++++++-- pkg/common/constant/error.go | 4 +++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index a2f8522ef..b391bd4f2 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -157,11 +157,12 @@ func main() { organizationGroup.POST("/create_organization_user", organization.CreateOrganizationUser) organizationGroup.POST("/update_organization_user", organization.UpdateOrganizationUser) - organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember) + organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser) + organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember) organizationGroup.POST("/get_user_in_department", organization.GetUserInDepartment) organizationGroup.POST("/update_user_In_department", organization.UpdateUserInDepartment) - organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser) + organizationGroup.POST("/get_department_member", organization.GetDepartmentMember) organizationGroup.POST("/delete_user_in_department", organization.DeleteUserInDepartment) } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index e22ab18bf..fec32ec32 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -207,10 +207,14 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - _, err := imdb.GetGroupInfoByGroupID(req.GroupID) + groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) if err != nil { log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err) - return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil + return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil + } + if groupInfo.Status == constant.GroupStatusDismissed { + errMsg := " group status is dismissed " + return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}, nil } // //from User: invite: applicant @@ -518,6 +522,16 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) + if err != nil { + log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err) + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } + if groupInfo.Status == constant.GroupStatusDismissed { + errMsg := " group status is dismissed " + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil + } + var groupRequest db.GroupRequest groupRequest.UserID = req.OpUserID groupRequest.ReqMsg = req.ReqMessage @@ -595,6 +609,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, http.WrapError(constant.ErrDB) } + if group.Status == constant.GroupStatusDismissed { + errMsg := " group status is dismissed " + return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil + } + ////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner var changedType int32 if group.GroupName != req.GroupInfo.GroupName && req.GroupInfo.GroupName != "" { @@ -627,6 +646,16 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) { log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String()) + groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) + if err != nil { + log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err) + return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } + if groupInfo.Status == constant.GroupStatusDismissed { + errMsg := " group status is dismissed " + return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil + } + if req.OldOwnerUserID == req.NewOwnerUserID { log.NewError(req.OperationID, "same owner ", req.OldOwnerUserID, req.NewOwnerUserID) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil diff --git a/pkg/common/constant/error.go b/pkg/common/constant/error.go index 00a11fd49..c8aca5fe6 100644 --- a/pkg/common/constant/error.go +++ b/pkg/common/constant/error.go @@ -51,7 +51,8 @@ var ( ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()} ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()} - ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()} + ErrArgs = ErrInfo{ErrCode: 803, ErrMsg: ArgsMsg.Error()} + ErrStatus = ErrInfo{ErrCode: 804, ErrMsg: StatusMsg.Error()} ErrCallback = ErrInfo{ErrCode: 809, ErrMsg: CallBackMsg.Error()} ) @@ -64,6 +65,7 @@ var ( TokenUnknownMsg = errors.New("couldn't handle this token") TokenUserKickedMsg = errors.New("user has been kicked") AccessMsg = errors.New("no permission") + StatusMsg = errors.New("status is abnormal") DBMsg = errors.New("db failed") ArgsMsg = errors.New("args failed") CallBackMsg = errors.New("callback failed")