fix: 允许IM平台管理员选择租户
This commit is contained in:
@@ -39,7 +39,7 @@ func resolveImAdminScopeWithAll(ctx context.Context, selectedTenantId int64, all
|
||||
scope.OperatorId = operatorId
|
||||
scope.RoleKey = contexts.GetRoleKey(ctx)
|
||||
scope.RequestId = gctx.CtxId(ctx)
|
||||
if service.AdminMember().VerifySuperId(ctx, operatorId) {
|
||||
if isImPlatformAdmin(ctx, operatorId) {
|
||||
if selectedTenantId <= 0 {
|
||||
if allowAll {
|
||||
return scope, nil
|
||||
@@ -53,12 +53,12 @@ func resolveImAdminScopeWithAll(ctx context.Context, selectedTenantId int64, all
|
||||
return scope, nil
|
||||
}
|
||||
|
||||
if contexts.GetDeptType(ctx) != consts.DeptTypeTenant {
|
||||
return scope, gerror.New("当前账号不是租户管理员,不能管理邀请码")
|
||||
if !contexts.IsTenantDept(ctx) {
|
||||
return scope, gerror.New("当前账号无权管理IM租户")
|
||||
}
|
||||
tenantId := contexts.GetTenantId(ctx)
|
||||
if tenantId <= 0 {
|
||||
return scope, gerror.New("当前管理员未关联租户")
|
||||
tenantId, err := resolveImAdminBoundTenant(ctx)
|
||||
if err != nil {
|
||||
return scope, err
|
||||
}
|
||||
if err = ensureImTenantActive(ctx, tenantId); err != nil {
|
||||
return scope, err
|
||||
@@ -67,6 +67,21 @@ func resolveImAdminScopeWithAll(ctx context.Context, selectedTenantId int64, all
|
||||
return scope, nil
|
||||
}
|
||||
|
||||
func isImPlatformAdmin(ctx context.Context, operatorId int64) bool {
|
||||
if contexts.IsCompanyDept(ctx) {
|
||||
return true
|
||||
}
|
||||
return service.AdminMember().VerifySuperId(ctx, operatorId)
|
||||
}
|
||||
|
||||
func resolveImAdminBoundTenant(ctx context.Context) (int64, error) {
|
||||
tenantId := contexts.GetTenantId(ctx)
|
||||
if tenantId <= 0 {
|
||||
return 0, gerror.New("当前管理员未关联IM租户")
|
||||
}
|
||||
return tenantId, nil
|
||||
}
|
||||
|
||||
func ensureImTenantActive(ctx context.Context, tenantId int64) (err error) {
|
||||
var tenant *entity.ImTenant
|
||||
if err = imtenant.RegistryDB().Model(dao.ImTenant.Table()).Safe().Ctx(ctx).WherePri(tenantId).Scan(&tenant); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user