diff --git a/cmd/open_im_cms_api/Makefile b/cmd/open_im_cms_api/Makefile index e69de29bb..31304542d 100644 --- a/cmd/open_im_cms_api/Makefile +++ b/cmd/open_im_cms_api/Makefile @@ -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 + diff --git a/cmd/rpc/open_im_admin_cms/Makefile b/cmd/rpc/open_im_admin_cms/Makefile new file mode 100644 index 000000000..f6efc1c08 --- /dev/null +++ b/cmd/rpc/open_im_admin_cms/Makefile @@ -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 diff --git a/cmd/rpc/open_im_message_cms/Makefile b/cmd/rpc/open_im_message_cms/Makefile new file mode 100644 index 000000000..4ac4cba3a --- /dev/null +++ b/cmd/rpc/open_im_message_cms/Makefile @@ -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 diff --git a/cmd/rpc/open_im_msg/main.go b/cmd/rpc/open_im_msg/main.go index b79d53f1a..7344facf4 100644 --- a/cmd/rpc/open_im_msg/main.go +++ b/cmd/rpc/open_im_msg/main.go @@ -6,7 +6,7 @@ import ( ) func main() { - rpcPort := flag.Int("port", 10301, "rpc listening port") + rpcPort := flag.Int("port", 10300, "rpc listening port") flag.Parse() rpcServer := rpcChat.NewRpcChatServer(*rpcPort) rpcServer.Run() diff --git a/cmd/rpc/open_im_statistics/Makefile b/cmd/rpc/open_im_statistics/Makefile new file mode 100644 index 000000000..37dbb3efe --- /dev/null +++ b/cmd/rpc/open_im_statistics/Makefile @@ -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 diff --git a/cmd/rpc/open_im_user/main.go b/cmd/rpc/open_im_user/main.go index 4382dc9fe..91b6e55b5 100644 --- a/cmd/rpc/open_im_user/main.go +++ b/cmd/rpc/open_im_user/main.go @@ -6,7 +6,7 @@ import ( ) func main() { - rpcPort := flag.Int("port", 10101, "rpc listening port") + rpcPort := flag.Int("port", 10100, "rpc listening port") flag.Parse() rpcServer := user.NewUserServer(*rpcPort) rpcServer.Run() diff --git a/config/config.yaml b/config/config.yaml index eea6bcbb7..bdd51bb57 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -8,7 +8,7 @@ etcd: etcdAddr: [ 127.0.0.1:2379 ] mysql: - dbMysqlAddress: [ 127.0.0.1:13306 ] + dbMysqlAddress: [ 43.128.5.63:13306 ] dbMysqlUserName: root dbMysqlPassword: openIM dbMysqlDatabaseName: openIM @@ -19,7 +19,7 @@ mysql: dbMaxLifeTime: 120 mongo: - dbAddress: [ 127.0.0.1:37017 ] + dbAddress: [ 43.128.5.63:37017 ] dbDirect: false dbTimeout: 10 dbDatabase: openIM @@ -30,7 +30,7 @@ mongo: dbRetainChatRecords: 7 redis: - dbAddress: 127.0.0.1:16379 + dbAddress: 43.128.5.63:16379 dbMaxIdle: 128 dbMaxActive: 0 dbIdleTimeout: 120 diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 2a0f59f8d..4fc915971 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -696,7 +696,6 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb groupMember, err := imdb.GetGroupMaster(v.GroupID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error()) - continue } resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{ GroupInfo: &open_im_sdk.GroupInfo{ @@ -738,7 +737,6 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (* groupMember, err := imdb.GetGroupMaster(v.GroupID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - continue } resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{ GroupInfo: &open_im_sdk.GroupInfo{ diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go index a1e8318fd..46ec80738 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -6,6 +6,7 @@ import ( "Open_IM/pkg/utils" "errors" "fmt" + "github.com/jinzhu/gorm" "time" ) @@ -124,17 +125,56 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error { groupMember := db.GroupMember{ UserID: userId, GroupID: groupId, - RoleLevel: roleLevel, } updateInfo := db.GroupMember{ RoleLevel: roleLevel, } - 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)) + groupMaster := db.GroupMember{ + } + switch roleLevel { + case constant.GroupOwner: + return dbConn.Transaction(func(tx *gorm.DB) error { + 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 }