Skip to content

Commit

Permalink
Merge branch 'tkt_white_7595_workspace_counters_params' into 'white/dev'
Browse files Browse the repository at this point in the history
Add parameter to exclude stats from workspace filter

Closes #7595

See merge request faradaysec/faraday!2275
  • Loading branch information
Diego Nadares committed Oct 10, 2023
2 parents 38717d3 + eb5893e commit e8a5618
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG/current/7595.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"level": "community",
"md": "[ADD] New `exclude_stats` query param in workspace endpoint. #7595"
}
6 changes: 3 additions & 3 deletions faraday/server/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ def _generate_filter_query(self, filters, severity_count=False, host_vulns=False
return filter_query

def _filter(self, filters: str, extra_alchemy_filters: BooleanClauseList = None,
severity_count=False, host_vulns=False) -> Tuple[list, int]:
marshmallow_params = {'many': True, 'context': {}}
severity_count=False, host_vulns=False, exclude=[]) -> Tuple[list, int]:
marshmallow_params = {'many': True, 'context': {}, 'exclude': exclude}
try:
filters = FlaskRestlessSchema().load(json.loads(filters)) or {}
except (ValidationError, JSONDecodeError) as ex:
Expand All @@ -1055,11 +1055,11 @@ def _filter(self, filters: str, extra_alchemy_filters: BooleanClauseList = None,

if extra_alchemy_filters is not None:
filter_query = filter_query.filter(extra_alchemy_filters)
count = filter_query.count()
if limit:
filter_query = filter_query.limit(limit)
if offset:
filter_query = filter_query.offset(offset)
count = filter_query.count()
filter_query = self._add_to_filter(filter_query)
objs = self.schema_class(**marshmallow_params).dumps(filter_query)
return json.loads(objs), count
Expand Down
11 changes: 10 additions & 1 deletion faraday/server/api/modules/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,22 @@ def filter(self):
description: invalid q was sent to the server
"""
exclude = []
stats = True
histogram = flask.request.args.get('histogram', type=lambda v: v.lower() == 'true')
exclude_stats = flask.request.args.get('exclude_stats', type=lambda v: v.lower() == 'true')
if exclude_stats:
exclude = ['stats']
stats = False

histogram_days, histogram_dict = None, None
if histogram:
histogram_days, histogram_dict = request_histogram()
filters = flask.request.args.get('q', '{"filters": []}')
filtered_objs, count = self._filter(filters, severity_count=True, host_vulns=False)
filtered_objs, count = self._filter(filters, severity_count=stats, host_vulns=False,
exclude=exclude)
objects = []

for workspace_stat in filtered_objs:
workspace_stat_dict = dict(workspace_stat)
for key, _ in list(workspace_stat_dict.items()):
Expand Down

0 comments on commit e8a5618

Please sign in to comment.