mirror of
https://github.com/veops/oneterm.git
synced 2025-10-29 01:52:56 +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) {
|
||||
//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 {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -126,9 +126,9 @@ 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
|
||||
if gt.LocalConn == nil || gt.RemoteConn == nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
ok = true
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user