@@ -129,7 +129,6 @@ func (impl *CvePolicyRepositoryImpl) GetAppEnvPolicies(clusterId int, environmen
129
129
sq = sq .Where ("env_id = ?" , environmentId ).Where ("app_id is null" )
130
130
return sq , nil
131
131
}).
132
- //WhereOr("env_id = ?", environmentId).
133
132
WhereOr ("global = true" ).
134
133
WhereOrGroup (func (sq * orm.Query ) (* orm.Query , error ) {
135
134
sq = sq .Where ("app_id = ?" , appId ).Where ("env_id = ?" , environmentId )
@@ -139,7 +138,6 @@ func (impl *CvePolicyRepositoryImpl) GetAppEnvPolicies(clusterId int, environmen
139
138
sq = sq .Where ("app_id = ?" , appId ).Where ("env_id is null" )
140
139
return sq , nil
141
140
})
142
- //WhereOr("app_id = ?", appId)
143
141
return q , nil
144
142
}).
145
143
Where ("deleted = false" ).
@@ -320,15 +318,27 @@ func (impl *CvePolicyRepositoryImpl) GetActiveByCveIdAndScope(cveId string, envI
320
318
Column ("cve_policy.*" ).
321
319
Where ("deleted = ?" , false ).
322
320
Where ("cve_store_id = ?" , cveId )
323
- if envId > 0 {
321
+ if appId == 0 && envId > 0 {
324
322
query = query .Where ("env_id = ?" , envId )
325
323
}
326
- if appId > 0 {
327
- query = query .Where ("app_id = ?" , appId )
328
- }
329
324
if clusterId > 0 {
330
325
query = query .Where ("cluster_id = ?" , clusterId )
331
326
}
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
+ }
332
342
err = query .Select ()
333
343
if err != nil {
334
344
impl .logger .Errorw ("error in getting active cvePolicies by cveId" , "cveId" , cveId , "err" , err )
0 commit comments