diff --git a/modules/msp/instance/db/instance_tenant.go b/modules/msp/instance/db/instance_tenant.go index 1b2d43fde1f..db95f487126 100644 --- a/modules/msp/instance/db/instance_tenant.go +++ b/modules/msp/instance/db/instance_tenant.go @@ -57,9 +57,7 @@ func (db *InstanceTenantDB) GetByTenantGroup(group string) ([]*InstanceTenant, e } var list []*InstanceTenant if err := db.query(). - Where("tenant_group=?", group). - Where("engine=?", "monitor").Limit(1). - Find(&list).Error; err != nil { + Where("tenant_group=?", group).Find(&list).Error; err != nil { return nil, err } return list, nil diff --git a/modules/msp/instance/permission/permission.go b/modules/msp/instance/permission/permission.go index 9fa7259678c..c39ac53a33e 100644 --- a/modules/msp/instance/permission/permission.go +++ b/modules/msp/instance/permission/permission.go @@ -74,35 +74,26 @@ func (p *provider) getProjectIDByGroupID(group string) (string, error) { return id, nil } - tenants, err := p.instanceTenantDB.GetByTenantGroup(group) + tenant, err := p.instanceTenantDB.GetInstanceByTenantGroup(group) if err != nil { return "", errors.NewDatabaseError(err) } - if len(tenants) <= 0 { - return "", errors.NewNotFoundError(group) + tmc, err := p.tmcDB.GetByEngine(tenant.Engine) + if err != nil { + return "", errors.NewDatabaseError(err) } - var monitorId = "" - for _, tenant := range tenants { - if tenant.Engine == instance.Monitor { - monitorId = tenant.ID - } - tmc, err := p.tmcDB.GetByEngine(tenant.Engine) - if err != nil { - return "", errors.NewDatabaseError(err) - } - if tmc == nil { - continue - } - if strings.EqualFold(tmc.ServiceType, string(instance.ServiceTypeMicroService)) { - id := p.getProjectIDByTenant(tenant) - if len(id) > 0 { - return id, nil - } + if tmc == nil { + return "", errors.NewDatabaseError(err) + } + if strings.EqualFold(tmc.ServiceType, string(instance.ServiceTypeMicroService)) { + id := p.getProjectIDByTenant(tenant) + if len(id) > 0 { + return id, nil } } monitor, err := p.monitorDB.GetByFields(map[string]interface{}{ - "MonitorId": monitorId, + "MonitorId": tenant.ID, }) if monitor != nil { return monitor.ProjectId, nil