pull/137/head
wangchuxiao 3 years ago
parent 445100f32d
commit 65be1263b9

@ -0,0 +1,25 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_cms_api
BIN_DIR=../../bin/
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi

@ -0,0 +1,23 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_admin_cms
BIN_DIR=../../../bin/
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi

@ -0,0 +1,23 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_message_cms
BIN_DIR=../../../bin/
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi

@ -6,7 +6,7 @@ import (
) )
func main() { func main() {
rpcPort := flag.Int("port", 10301, "rpc listening port") rpcPort := flag.Int("port", 10300, "rpc listening port")
flag.Parse() flag.Parse()
rpcServer := rpcChat.NewRpcChatServer(*rpcPort) rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
rpcServer.Run() rpcServer.Run()

@ -0,0 +1,23 @@
.PHONY: all build run gotool install clean help
BINARY_NAME=open_im_statistics
BIN_DIR=../../../bin/
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
run:
@go run ./
gotool:
go fmt ./
go vet ./
install:
make build
mv ${BINARY_NAME} ${BIN_DIR}
clean:
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi

@ -6,7 +6,7 @@ import (
) )
func main() { func main() {
rpcPort := flag.Int("port", 10101, "rpc listening port") rpcPort := flag.Int("port", 10100, "rpc listening port")
flag.Parse() flag.Parse()
rpcServer := user.NewUserServer(*rpcPort) rpcServer := user.NewUserServer(*rpcPort)
rpcServer.Run() rpcServer.Run()

@ -8,7 +8,7 @@ etcd:
etcdAddr: [ 127.0.0.1:2379 ] etcdAddr: [ 127.0.0.1:2379 ]
mysql: mysql:
dbMysqlAddress: [ 127.0.0.1:13306 ] dbMysqlAddress: [ 43.128.5.63:13306 ]
dbMysqlUserName: root dbMysqlUserName: root
dbMysqlPassword: openIM dbMysqlPassword: openIM
dbMysqlDatabaseName: openIM dbMysqlDatabaseName: openIM
@ -19,7 +19,7 @@ mysql:
dbMaxLifeTime: 120 dbMaxLifeTime: 120
mongo: mongo:
dbAddress: [ 127.0.0.1:37017 ] dbAddress: [ 43.128.5.63:37017 ]
dbDirect: false dbDirect: false
dbTimeout: 10 dbTimeout: 10
dbDatabase: openIM dbDatabase: openIM
@ -30,7 +30,7 @@ mongo:
dbRetainChatRecords: 7 dbRetainChatRecords: 7
redis: redis:
dbAddress: 127.0.0.1:16379 dbAddress: 43.128.5.63:16379
dbMaxIdle: 128 dbMaxIdle: 128
dbMaxActive: 0 dbMaxActive: 0
dbIdleTimeout: 120 dbIdleTimeout: 120

@ -696,7 +696,6 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
groupMember, err := imdb.GetGroupMaster(v.GroupID) groupMember, err := imdb.GetGroupMaster(v.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
continue
} }
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{ resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{ GroupInfo: &open_im_sdk.GroupInfo{
@ -738,7 +737,6 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*
groupMember, err := imdb.GetGroupMaster(v.GroupID) groupMember, err := imdb.GetGroupMaster(v.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
continue
} }
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{ resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{ GroupInfo: &open_im_sdk.GroupInfo{

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"errors" "errors"
"fmt" "fmt"
"github.com/jinzhu/gorm"
"time" "time"
) )
@ -124,17 +125,56 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
groupMember := db.GroupMember{ groupMember := db.GroupMember{
UserID: userId, UserID: userId,
GroupID: groupId, GroupID: groupId,
RoleLevel: roleLevel,
} }
updateInfo := db.GroupMember{ updateInfo := db.GroupMember{
RoleLevel: roleLevel, RoleLevel: roleLevel,
} }
result := dbConn.Table("group_members").Find(&groupMember).Update(updateInfo) groupMaster := db.GroupMember{
if result.Error != nil { }
return result.Error switch roleLevel {
} case constant.GroupOwner:
if result.RowsAffected == 0 { return dbConn.Transaction(func(tx *gorm.DB) error {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{
RoleLevel: constant.GroupOrdinaryUsers,
})
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
result = dbConn.Table("group_members").First(&groupMember).Update(updateInfo)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
return nil
})
case constant.GroupOrdinaryUsers:
return dbConn.Transaction(func(tx *gorm.DB) error {
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
if groupMaster.UserID == userId {
return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId))
} else {
result = dbConn.Table("group_members").Find(&groupMember).Update(updateInfo)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
}
}
return nil
})
} }
return nil return nil
} }

Loading…
Cancel
Save