From 0e7f49fb466f5c57a3074bc40b1223cb5637a82f Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 19 May 2023 11:21:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=B6=85=E7=AE=A1=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/group_m/mic.go | 2 +- domain/model/user_m/superManager.go | 33 ++++++++++++++++++++++++++++- domain/service/group_s/group_op.go | 2 +- route/group_r/group_op.go | 4 ++-- route/group_r/group_setting.go | 2 +- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/domain/model/group_m/mic.go b/domain/model/group_m/mic.go index be4576e..9f2ce79 100644 --- a/domain/model/group_m/mic.go +++ b/domain/model/group_m/mic.go @@ -576,7 +576,7 @@ func (micUser *MicUser) SpeechClose(userId uint64, externalId, lang string) erro } else if flag { //不能让超级管理人移除 return bizerr.OfficialStaffLimit - } else if flag, err := user_m.IsSuperManager(micUser.model, userId); err != nil { + } else if flag, err := user_m.IsSuperManagerV2(micUser.model, userId, micUser.UserId); err != nil { return err } else if flag { //超级管理人,无敌状态 diff --git a/domain/model/user_m/superManager.go b/domain/model/user_m/superManager.go index d671d1a..7fa3c8d 100644 --- a/domain/model/user_m/superManager.go +++ b/domain/model/user_m/superManager.go @@ -3,13 +3,17 @@ package user_m import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" + "gorm.io/gorm" "hilo-group/myerr" + "strings" ) type SuperManager struct { mysql.Entity *domain.Model `gorm:"-"` UserId mysql.ID + IsAll bool + Countries string } func IsSuperManager(model *domain.Model, userId mysql.ID) (bool, error) { @@ -22,6 +26,33 @@ func IsSuperManager(model *domain.Model, userId mysql.ID) (bool, error) { return n > 0, nil } +// 对某人是否有超管权限 +func IsSuperManagerV2(model *domain.Model, userId, targetUserId mysql.ID) (bool, error) { + var man SuperManager + if err := model.Db.Model(&SuperManager{}).Where(&SuperManager{ + UserId: userId, + }).First(&man).Error; err != nil { + if err != gorm.ErrRecordNotFound { + model.Log.Errorf("IsSuperManagerV2 fail:%v", err) + } + return false, nil + } + if man.IsAll { + return true, nil + } + targetUser, err := GetUser(model, targetUserId) + if err != nil { + return false, err + } + countries := strings.Split(man.Countries, ",") + for _, c := range countries { + if c == targetUser.Country { + return true, nil + } + } + return false, nil +} + func GetSuperManagerAll(model *domain.Model) ([]uint64, error) { superManagers := []SuperManager{} if err := model.Db.Model(&SuperManager{}).Find(&superManagers).Error; err != nil { @@ -51,4 +82,4 @@ func GetSuperManagerMap(userIds []uint64) (map[uint64]bool, error) { rs[superManagers[i].UserId] = true } return rs, nil -} \ No newline at end of file +} diff --git a/domain/service/group_s/group_op.go b/domain/service/group_s/group_op.go index 7a2d3dc..fb13ab9 100644 --- a/domain/service/group_s/group_op.go +++ b/domain/service/group_s/group_op.go @@ -401,7 +401,7 @@ func (s *GroupService) GroupKick(groupUuid string, userId uint64, userExternalId } //超级管理人,无敌状态 - if flag, err := user_m.IsSuperManager(model, userId); err != nil { + if flag, err := user_m.IsSuperManagerV2(model, userId, beKickUserId); err != nil { return err } else if !flag { //判断权限 diff --git a/route/group_r/group_op.go b/route/group_r/group_op.go index c09cd54..50659f8 100644 --- a/route/group_r/group_op.go +++ b/route/group_r/group_op.go @@ -878,14 +878,14 @@ func SearchGroup(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } if owner.Status == user_e.UserStatusFrozen { - if flag, _ := user_m.IsSuperManager(model, myUserId); !flag { + if flag, _ := user_m.IsSuperManagerV2(model, myUserId, owner.ID); !flag { // 被封锁的用户,除了超管账户,其它用户搜索他的群组和个人ID,搜索结果为空 resp.ResponsePageOk(c, result, uint(total), 1) return myContext, nil } } if group_m.IsHiddenGroupBy(model, g.ImGroupId) { - if flag, _ := user_m.IsSuperManager(model, myUserId); !flag { + if flag, _ := user_m.IsSuperManagerV2(model, myUserId, g.Owner); !flag { // 被隐藏的用户,除了超管账户,其它用户搜索他的群组和个人ID,搜索结果为空 resp.ResponsePageOk(c, result, uint(total), 1) return myContext, nil diff --git a/route/group_r/group_setting.go b/route/group_r/group_setting.go index 37345e1..ce4ef33 100644 --- a/route/group_r/group_setting.go +++ b/route/group_r/group_setting.go @@ -543,7 +543,7 @@ func AddGroupBlacklist(c *gin.Context) (*mycontext.MyContext, error) { // 检查是否可以对svip6进行操作 optUserId:被操作的用户id func CheckOptToSvip6(model *domain.Model, userId, optUserId uint64, lang string, privilegeId int) error { // 是否超管 - isM, err := user_m.IsSuperManager(model, userId) + isM, err := user_m.IsSuperManagerV2(model, userId, optUserId) if err != nil { return err } -- 2.22.0