Skip to content

Commit

Permalink
Merge pull request #238 from CybercentreCanada/hotfix/group_search_total
Browse files Browse the repository at this point in the history
Hotfix/group search total
  • Loading branch information
cccs-sgaron authored Jul 21, 2021
2 parents c5ab49c + 9d88967 commit 1f26d86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions assemblyline_ui/api/v4/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ def list_alerts(**kwargs):

try:
res = STORAGE.alert.search(
query, offset=offset, rows=rows, fl="alert_id", sort="reporting_ts desc",
query, offset=offset, rows=rows, fl="id", sort="reporting_ts desc",
access_control=user['access_control'],
filters=filters, as_obj=False, use_archive=use_archive, track_total_hits=track_total_hits)
res['items'] = sorted(STORAGE.alert.multiget([v['alert_id'] for v in res['items']],
res['items'] = sorted(STORAGE.alert.multiget([v['id'] for v in res['items']],
as_dictionary=False, as_obj=False),
key=lambda k: k['reporting_ts'], reverse=True)
return make_api_response(res)
Expand Down Expand Up @@ -355,7 +355,7 @@ def get_dict_item(parent, cur_item):
try:
res = STORAGE.alert.grouped_search(field, query=query, offset=offset, rows=rows, sort="reporting_ts desc",
group_sort="reporting_ts desc", access_control=user['access_control'],
filters=filters, fl=f"alert_id,{field}", as_obj=False,
filters=filters, fl=f"id,{field}", as_obj=False,
use_archive=use_archive, track_total_hits=track_total_hits)
alert_keys = []
hash_list = []
Expand All @@ -366,7 +366,7 @@ def get_dict_item(parent, cur_item):
counted_total += item['total']
group_count[item['value']] = item['total']
data = item['items'][0]
alert_keys.append(data['alert_id'])
alert_keys.append(data['id'])
if field in ['file.md5', 'file.sha1', 'file.sha256']:
hash_list.append(get_dict_item(data, field))

Expand Down
26 changes: 18 additions & 8 deletions assemblyline_ui/api/v4/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,11 @@ def list_submissions_for_group(group, **kwargs):
None
Arguments:
offset => Offset at which we start giving submissions
rows => Numbers of submissions to return
query => Query to filter to the submission list
offset => Offset at which we start giving submissions
rows => Numbers of submissions to return
query => Query to filter to the submission list
use_archive => List submissions from archive as well (Default: False)
track_total_hits => Track the total number of item that match the query (Default: 10 000)
Data Block:
None
Expand All @@ -698,6 +700,8 @@ def list_submissions_for_group(group, **kwargs):
offset = int(request.args.get('offset', 0))
rows = int(request.args.get('rows', 100))
filters = request.args.get('query', None) or None
track_total_hits = request.args.get('track_total_hits', False)
use_archive = request.args.get('use_archive', 'false').lower() == 'true'

if group == "ALL":
group_query = "id:*"
Expand All @@ -706,7 +710,8 @@ def list_submissions_for_group(group, **kwargs):
try:
return make_api_response(STORAGE.submission.search(group_query, offset=offset, rows=rows, filters=filters,
access_control=user['access_control'],
sort='times.submitted desc', as_obj=False))
sort='times.submitted desc', as_obj=False,
use_archive=use_archive, track_total_hits=track_total_hits))
except SearchException as e:
return make_api_response("", f"SearchException: {e}", 400)

Expand All @@ -721,9 +726,11 @@ def list_submissions_for_user(username, **kwargs):
None
Arguments:
offset => Offset at which we start giving submissions
rows => Numbers of submissions to return
query => Query to filter the submission list
offset => Offset at which we start giving submissions
rows => Numbers of submissions to return
query => Query to filter the submission list
use_archive => List submissions from archive as well (Default: False)
track_total_hits => Track the total number of item that match the query (Default: 10 000)
Data Block:
None
Expand All @@ -750,6 +757,8 @@ def list_submissions_for_user(username, **kwargs):
offset = int(request.args.get('offset', 0))
rows = int(request.args.get('rows', 100))
query = request.args.get('query', None) or None
track_total_hits = request.args.get('track_total_hits', False)
use_archive = request.args.get('use_archive', 'false').lower() == 'true'

account = STORAGE.user.get(username)
if not account:
Expand All @@ -758,7 +767,8 @@ def list_submissions_for_user(username, **kwargs):
try:
return make_api_response(STORAGE.submission.search(f"params.submitter:{username}", offset=offset, rows=rows,
filters=query, access_control=user['access_control'],
sort='times.submitted desc', as_obj=False))
sort='times.submitted desc', as_obj=False,
use_archive=use_archive, track_total_hits=track_total_hits))
except SearchException as e:
return make_api_response("", f"SearchException: {e}", 400)

Expand Down

0 comments on commit 1f26d86

Please sign in to comment.