Skip to content

Commit 2ca71a6

Browse files
author
Diego Nadares
committed
Merge branch 'tkt_white_7676_fix_hosts_stats_on_bulk_delete' into 'white/dev'
Resolve "Bulk delete no modifica las estadísticas de assets" Closes #7676 See merge request faradaysec/faraday!2340
2 parents 4cff802 + d6149ce commit 2ca71a6

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

CHANGELOG/current/7676.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"level": "community",
3+
"md": "[FIX] Fix hosts stats when bulk delete is applied to vulns. #7676"
4+
}

faraday/server/api/modules/vulns.py

+33-33
Original file line numberDiff line numberDiff line change
@@ -1396,39 +1396,6 @@ def bulk_delete(self, workspace_name, **kwargs):
13961396
workspace_name=workspace_name, **kwargs), 200
13971397
bulk_delete.__doc__ = BulkDeleteWorkspacedMixin.bulk_delete.__doc__
13981398

1399-
def _perform_bulk_delete(self, values, **kwargs):
1400-
# Get host and service ids in order to update host stats
1401-
host_ids = db.session.query(
1402-
VulnerabilityGeneric.host_id,
1403-
VulnerabilityGeneric.service_id
1404-
)
1405-
1406-
by_severity = kwargs.get('by', None)
1407-
if by_severity == 'severity':
1408-
for severity in values:
1409-
if severity not in VulnerabilityABC.SEVERITIES:
1410-
flask.abort(http.client.BAD_REQUEST, "Severity type not valid")
1411-
1412-
host_ids = host_ids.filter(
1413-
VulnerabilityGeneric.severity.in_(values)
1414-
).all()
1415-
else:
1416-
host_ids = host_ids.filter(
1417-
VulnerabilityGeneric.id.in_(values)
1418-
).all()
1419-
1420-
response = super()._perform_bulk_delete(values, **kwargs)
1421-
deleted = response.json.get('deleted', 0)
1422-
if deleted > 0:
1423-
from faraday.server.tasks import update_host_stats # pylint:disable=import-outside-toplevel
1424-
host_id_list = [data[0] for data in host_ids if data[0]]
1425-
service_id_list = [data[1] for data in host_ids if data[1]]
1426-
if faraday_server.celery_enabled:
1427-
update_host_stats.delay(host_id_list, service_id_list)
1428-
else:
1429-
update_host_stats(host_id_list, service_id_list)
1430-
return response
1431-
14321399
def _bulk_update_query(self, ids, **kwargs):
14331400
# It IS better to as is but warn of ON CASCADE
14341401
query = self.model_class.query.filter(self.model_class.id.in_(ids))
@@ -1510,5 +1477,38 @@ def _post_bulk_update(self, ids, extracted_data, workspace_name, **kwargs):
15101477
else:
15111478
update_host_stats(host_id_list, service_id_list)
15121479

1480+
def _perform_bulk_delete(self, values, **kwargs):
1481+
# Get host and service ids in order to update host stats
1482+
host_ids = db.session.query(
1483+
VulnerabilityGeneric.host_id,
1484+
VulnerabilityGeneric.service_id
1485+
)
1486+
1487+
by_severity = kwargs.get('by', None)
1488+
if by_severity == 'severity':
1489+
for severity in values:
1490+
if severity not in VulnerabilityABC.SEVERITIES:
1491+
flask.abort(http.client.BAD_REQUEST, "Severity type not valid")
1492+
1493+
host_ids = host_ids.filter(
1494+
VulnerabilityGeneric.severity.in_(values)
1495+
).all()
1496+
else:
1497+
host_ids = host_ids.filter(
1498+
VulnerabilityGeneric.id.in_(values)
1499+
).all()
1500+
1501+
response = super()._perform_bulk_delete(values, **kwargs)
1502+
deleted = response.json.get('deleted', 0)
1503+
if deleted > 0:
1504+
from faraday.server.tasks import update_host_stats # pylint:disable=import-outside-toplevel
1505+
host_id_list = [data[0] for data in host_ids if data[0]]
1506+
service_id_list = [data[1] for data in host_ids if data[1]]
1507+
if faraday_server.celery_enabled:
1508+
update_host_stats.delay(host_id_list, service_id_list)
1509+
else:
1510+
update_host_stats(host_id_list, service_id_list)
1511+
return response
1512+
15131513

15141514
VulnerabilityView.register(vulns_api)

0 commit comments

Comments
 (0)