mirror of
https://github.com/veops/oneterm.git
synced 2025-10-28 17:51:49 +08:00
fix: connectable without gateway and asset count when no-admin
This commit is contained in:
@@ -92,7 +92,7 @@ func (c *Controller) GetAssets(ctx *gin.Context) {
|
|||||||
|
|
||||||
if info && !acl.IsAdmin(currentUser) {
|
if info && !acl.IsAdmin(currentUser) {
|
||||||
//rs := make([]*acl.Resource, 0)
|
//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 {
|
if err != nil {
|
||||||
handleRemoteErr(ctx, err)
|
handleRemoteErr(ctx, err)
|
||||||
return
|
return
|
||||||
@@ -100,7 +100,7 @@ func (c *Controller) GetAssets(ctx *gin.Context) {
|
|||||||
ids := make([]int, 0)
|
ids := make([]int, 0)
|
||||||
if err = mysql.DB.
|
if err = mysql.DB.
|
||||||
Model(&model.Authorization{}).
|
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().
|
Distinct().
|
||||||
Pluck("asset_id", &ids).
|
Pluck("asset_id", &ids).
|
||||||
Error; err != nil {
|
Error; err != nil {
|
||||||
|
|||||||
@@ -129,7 +129,17 @@ func nodePostHookCountAsset(ctx *gin.Context, data []*model.Node) {
|
|||||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
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 {
|
if err := db.Find(&assets).Error; err != nil {
|
||||||
logger.L.Error("node posthookfailed asset count", zap.Error(err))
|
logger.L.Error("node posthookfailed asset count", zap.Error(err))
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ func checkOne(asset *model.Asset, gateway *model.Gateway) (sid string, ok bool)
|
|||||||
|
|
||||||
if asset.GatewayId != 0 {
|
if asset.GatewayId != 0 {
|
||||||
<-gt.Chan
|
<-gt.Chan
|
||||||
}
|
if gt.LocalConn == nil || gt.RemoteConn == nil {
|
||||||
if gt.LocalConn == nil || gt.RemoteConn == nil {
|
continue
|
||||||
continue
|
}
|
||||||
}
|
}
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user