fix: connectable without gateway and asset count when no-admin

This commit is contained in:
ttk
2024-03-22 16:46:11 +08:00
parent 68121b4c64
commit e596495192
3 changed files with 16 additions and 6 deletions

View File

@@ -92,7 +92,7 @@ func (c *Controller) GetAssets(ctx *gin.Context) {
if info && !acl.IsAdmin(currentUser) {
//rs := make([]*acl.Resource, 0)
rs, err := acl.GetRoleResources(ctx, currentUser.Acl.Rid, acl.GetResourceTypeName(conf.RESOURCE_AUTHORIZATION))
authorizationResourceIds, err := GetAutorizationResourceIds(ctx)
if err != nil {
handleRemoteErr(ctx, err)
return
@@ -100,7 +100,7 @@ func (c *Controller) GetAssets(ctx *gin.Context) {
ids := make([]int, 0)
if err = mysql.DB.
Model(&model.Authorization{}).
Where("resource_id IN ?", lo.Map(rs, func(r *acl.Resource, _ int) int { return r.ResourceId })).
Where("resource_id IN ?", authorizationResourceIds).
Distinct().
Pluck("asset_id", &ids).
Error; err != nil {

View File

@@ -129,7 +129,17 @@ func nodePostHookCountAsset(ctx *gin.Context, data []*model.Node) {
ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
db = db.Where("resource_id IN ?", authorizationResourceIds)
ids := make([]int, 0)
if err = mysql.DB.
Model(&model.Authorization{}).
Where("resource_id IN ?", authorizationResourceIds).
Distinct().
Pluck("asset_id", &ids).
Error; err != nil {
ctx.AbortWithError(http.StatusInternalServerError, &ApiError{Code: ErrInternal, Data: map[string]any{"err": err}})
return
}
db = db.Where("id IN ?", ids)
}
if err := db.Find(&assets).Error; err != nil {
logger.L.Error("node posthookfailed asset count", zap.Error(err))

View File

@@ -126,10 +126,10 @@ func checkOne(asset *model.Asset, gateway *model.Gateway) (sid string, ok bool)
if asset.GatewayId != 0 {
<-gt.Chan
}
if gt.LocalConn == nil || gt.RemoteConn == nil {
continue
}
}
ok = true
return
}