Skip to content

Commit 3008f93

Browse files
committed
fix
1 parent e17ca74 commit 3008f93

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pkg/policyGovernance/security/imageScanning/repository/CvePolicyControlRepository.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func (impl *CvePolicyRepositoryImpl) GetAppEnvPolicies(clusterId int, environmen
129129
sq = sq.Where("env_id = ?", environmentId).Where("app_id is null")
130130
return sq, nil
131131
}).
132-
//WhereOr("env_id = ?", environmentId).
133132
WhereOr("global = true").
134133
WhereOrGroup(func(sq *orm.Query) (*orm.Query, error) {
135134
sq = sq.Where("app_id = ?", appId).Where("env_id = ?", environmentId)
@@ -139,7 +138,6 @@ func (impl *CvePolicyRepositoryImpl) GetAppEnvPolicies(clusterId int, environmen
139138
sq = sq.Where("app_id = ?", appId).Where("env_id is null")
140139
return sq, nil
141140
})
142-
//WhereOr("app_id = ?", appId)
143141
return q, nil
144142
}).
145143
Where("deleted = false").
@@ -320,15 +318,27 @@ func (impl *CvePolicyRepositoryImpl) GetActiveByCveIdAndScope(cveId string, envI
320318
Column("cve_policy.*").
321319
Where("deleted = ?", false).
322320
Where("cve_store_id = ?", cveId)
323-
if envId > 0 {
321+
if appId == 0 && envId > 0 {
324322
query = query.Where("env_id = ?", envId)
325323
}
326-
if appId > 0 {
327-
query = query.Where("app_id = ?", appId)
328-
}
329324
if clusterId > 0 {
330325
query = query.Where("cluster_id = ?", clusterId)
331326
}
327+
if appId > 0 && envId > 0 {
328+
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
329+
q = q.WhereOrGroup(func(sq *orm.Query) (*orm.Query, error) {
330+
sq = sq.Where("app_id = ?", appId).Where("env_id = ?", envId)
331+
return sq, nil
332+
}).
333+
WhereOrGroup(func(sq *orm.Query) (*orm.Query, error) {
334+
sq = sq.Where("app_id = ?", appId).Where("env_id is null")
335+
return sq, nil
336+
})
337+
return q, nil
338+
})
339+
} else if appId > 0 && envId == 0 {
340+
query = query.Where("app_id = ?", appId)
341+
}
332342
err = query.Select()
333343
if err != nil {
334344
impl.logger.Errorw("error in getting active cvePolicies by cveId", "cveId", cveId, "err", err)

0 commit comments

Comments
 (0)