Skip to content

Commit 866b435

Browse files
authored
Merge pull request #975 from dfir-iris/api_v2_delete_global_task
Api v2 delete global task
2 parents 0aa6ae3 + 13def32 commit 866b435

46 files changed

Lines changed: 379 additions & 325 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vulture.ignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
EvidenceStorage # Do not remove: this is used by package iris-module-interface (see https://github.com/dfir-iris/iris-module-interface, iris_interface/IrisModuleInterface.py)
1+
########## Do not remove: used by package iris-module-interface (see https://github.com/dfir-iris/iris-module-interface, iris_interface/IrisModuleInterface.py)
2+
EvidenceStorage
3+
deregister_from_hook
4+
get_mod_config_by_name
5+
register_hook
26
######### Alembic variables
37
revision # unused variable (/home/ubuntu/code/dfir-iris/iris-web/source/app/alembic/versions/00b43bc4e8ac_add_prevent_post_init_to_register_case_.py:14)
48
down_revision # unused variable (/home/ubuntu/code/dfir-iris/iris-web/source/app/alembic/versions/00b43bc4e8ac_add_prevent_post_init_to_register_case_.py:15)
@@ -269,7 +273,6 @@ get_case_client # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/
269273
ctx_get_user_cases # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/context/context_db.py:31)
270274
update_gtask_status # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/dashboard/dashboard_db.py:131)
271275
update_utask_status # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/dashboard/dashboard_db.py:147)
272-
get_task_status # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/dashboard/dashboard_db.py:166)
273276
_.is_evidence_registered # unused method (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/iris_engine/evidence_storage.py:24)
274277
_.add_evidence # unused method (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/iris_engine/evidence_storage.py:32)
275278
_.added_by_id # unused attribute (/home/ubuntu/code/dfir-iris/iris-web/source/app/datamgmt/iris_engine/modules_db.py:54)
@@ -319,11 +322,8 @@ case_organisations # unused variable (/home/ubuntu/code/dfir-iris/iris-web/sour
319322
CaseNoteForm # unused class (/home/ubuntu/code/dfir-iris/iris-web/source/app/forms.py:223)
320323
ac_get_effective_permissions_from_groups # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/access_control/utils.py:138)
321324
check_module_compatibility # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:46)
322-
get_mod_config_by_name # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:234)
323-
register_hook # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:323)
324325
_.wait_till_return # unused attribute (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:372)
325326
_.max_retry # unused attribute (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:374)
326-
deregister_from_hook # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/module_handler/module_handler.py:391)
327327
on_task_init # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/tasker/tasks.py:33)
328328
chunks # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/tasker/tasks.py:92)
329329
notify_server_ready_to_reboot # unused function (/home/ubuntu/code/dfir-iris/iris-web/source/app/iris_engine/updater/updater.py:70)

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ forbidden_modules = "sqlalchemy"
4040
allow_indirect_imports = true
4141

4242
[[tool.importlinter.contracts]]
43-
name = "Do not import API layer from the persistence layer"
43+
name = "Do not import API layer from the persistence layer (access_controls)"
4444
type = "forbidden"
45-
source_modules = "app.datamgmt.dashboard"
46-
forbidden_modules = "app.blueprints"
45+
source_modules = "app.datamgmt"
46+
forbidden_modules = "app.blueprints.access_controls"
4747
allow_indirect_imports = true
4848

4949
[[tool.importlinter.contracts]]
50-
name = "Do not import API layer from the persistence layer (access_controls)"
50+
name = "Do not import API layer from the persistence layer (iris_user)"
5151
type = "forbidden"
52-
source_modules = "app.datamgmt"
53-
forbidden_modules = "app.blueprints.access_controls"
52+
source_modules = "app.datamgmt.case.case_assets_db"
53+
forbidden_modules = "app.blueprints.iris_user"
5454
allow_indirect_imports = true
5555

5656
[[tool.importlinter.contracts]]

source/app/blueprints/pages/dashboard/dashboard_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from app import app
2626
from app.blueprints.iris_user import iris_current_user
27-
from app.datamgmt.dashboard.dashboard_db import get_tasks_status
27+
from app.datamgmt.case.case_tasks_db import get_tasks_status
2828
from app.forms import CaseGlobalTaskForm
2929
from app.iris_engine.access_control.utils import ac_get_user_case_counts
3030
from app.models.authorization import User

source/app/blueprints/rest/alerts_routes.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ def alerts_update_route(alert_id) -> Response:
369369
# Save the changes
370370
db.session.commit()
371371

372-
updated_alert = call_modules_hook('on_postload_alert_update', data=updated_alert)
372+
updated_alert = call_modules_hook('on_postload_alert_update', updated_alert)
373373

374374
if do_resolution_hook:
375-
updated_alert = call_modules_hook('on_postload_alert_resolution_update', data=updated_alert)
375+
updated_alert = call_modules_hook('on_postload_alert_resolution_update', updated_alert)
376376

377377
if do_status_hook:
378-
updated_alert = call_modules_hook('on_postload_alert_status_update', data=updated_alert)
378+
updated_alert = call_modules_hook('on_postload_alert_status_update', updated_alert)
379379

380380
if activity_data:
381381
activity_data_as_string = ','.join(activity_data)
@@ -455,7 +455,7 @@ def alerts_batch_update_route() -> Response:
455455

456456
db.session.commit()
457457

458-
alert = call_modules_hook('on_postload_alert_update', data=alert)
458+
alert = call_modules_hook('on_postload_alert_update', alert)
459459

460460
if activity_data:
461461
track_activity(f"updated alert #{alert_id}: {','.join(activity_data)}", ctx_less=True)
@@ -509,7 +509,7 @@ def alerts_batch_delete_route() -> Response:
509509
if not success:
510510
return response_error(logs)
511511

512-
alert = call_modules_hook('on_postload_alert_delete', data={"alert_ids": alert_ids})
512+
alert = call_modules_hook('on_postload_alert_delete', {"alert_ids": alert_ids})
513513

514514
track_activity(f"deleted alerts #{','.join(str(alert_id) for alert_id in alert_ids)}", ctx_less=True)
515515

@@ -551,7 +551,7 @@ def alerts_delete_route(alert_id) -> Response:
551551
db.session.delete(alert)
552552
db.session.commit()
553553

554-
alert = call_modules_hook('on_postload_alert_delete', data=alert_id)
554+
alert = call_modules_hook('on_postload_alert_delete', alert_id)
555555

556556
track_activity(f"delete alert #{alert_id}", ctx_less=True)
557557

@@ -613,15 +613,15 @@ def alerts_escalate_route(alert_id) -> Response:
613613

614614
ac_set_new_case_access(iris_current_user, case.case_id, case.client_id)
615615

616-
case = call_modules_hook('on_postload_case_create', data=case)
616+
case = call_modules_hook('on_postload_case_create', case)
617617

618618
add_obj_history_entry(case, 'created')
619619
track_activity(f"new case {case.name} created from alert",
620620
ctx_less=True)
621621

622622
add_obj_history_entry(alert, f"Alert escalated to case #{case.case_id}")
623623

624-
alert = call_modules_hook('on_postload_alert_escalate', data=alert)
624+
alert = call_modules_hook('on_postload_alert_escalate', alert)
625625

626626
# Return the updated alert as JSON
627627
return response_success(data=CaseSchema().dump(case))
@@ -687,7 +687,7 @@ def alerts_merge_route(alert_id) -> Response:
687687
iocs_list=iocs_import_list, assets_list=assets_import_list, note=note,
688688
import_as_event=import_as_event, case_tags=case_tags)
689689

690-
alert = call_modules_hook('on_postload_alert_merge', data=alert, caseid=target_case_id)
690+
alert = call_modules_hook('on_postload_alert_merge', alert, caseid=target_case_id)
691691

692692
track_activity(f"merge alert #{alert_id} into existing case #{target_case_id}", caseid=target_case_id)
693693
add_obj_history_entry(alert, f"Alert merged into existing case #{target_case_id}")
@@ -747,7 +747,7 @@ def alerts_unmerge_route(alert_id) -> Response:
747747
track_activity(f"unmerge alert #{alert_id} from case #{target_case_id}", caseid=target_case_id)
748748
add_obj_history_entry(alert, f"Alert unmerged from case #{target_case_id}")
749749

750-
alert = call_modules_hook('on_postload_alert_unmerge', data=alert)
750+
alert = call_modules_hook('on_postload_alert_unmerge', alert)
751751

752752
# Return the updated case as JSON
753753
return response_success(data=AlertSchema().dump(alert), msg=message)
@@ -816,7 +816,7 @@ def alerts_batch_merge_route() -> Response:
816816

817817
add_obj_history_entry(alert, f"Alert merged into existing case #{target_case_id}")
818818

819-
alert = call_modules_hook('on_postload_alert_merge', data=alert)
819+
alert = call_modules_hook('on_postload_alert_merge', alert)
820820

821821
if note:
822822
case.description += f"\n\n### Escalation note\n\n{note}\n\n" if case.description else f"\n\n{note}\n\n"
@@ -877,7 +877,7 @@ def alerts_batch_escalate_route() -> Response:
877877

878878
alert.alert_status_id = AlertStatus.query.filter_by(status_name='Merged').first().status_id
879879
db.session.commit()
880-
alert = call_modules_hook('on_postload_alert_escalate', data=alert)
880+
alert = call_modules_hook('on_postload_alert_escalate', alert)
881881

882882
alerts_list.append(alert)
883883

@@ -890,7 +890,7 @@ def alerts_batch_escalate_route() -> Response:
890890

891891
ac_set_new_case_access(iris_current_user, case.case_id, case.client_id)
892892

893-
case = call_modules_hook('on_postload_case_create', data=case)
893+
case = call_modules_hook('on_postload_case_create', case)
894894

895895
add_obj_history_entry(case, 'created')
896896
track_activity(f"new case {case.name} created from alerts",
@@ -963,7 +963,7 @@ def alert_comment_delete(alert_id, com_id):
963963
if not success:
964964
return response_error(msg)
965965

966-
call_modules_hook('on_postload_alert_comment_delete', data=com_id)
966+
call_modules_hook('on_postload_alert_comment_delete', com_id)
967967

968968
track_activity(f"comment {com_id} on alert {alert_id} deleted", ctx_less=True)
969969

@@ -1065,7 +1065,7 @@ def case_comment_add(alert_id):
10651065
"comment": comment_schema.dump(comment),
10661066
"alert": AlertSchema().dump(alert)
10671067
}
1068-
call_modules_hook('on_postload_alert_commented', data=hook_data)
1068+
call_modules_hook('on_postload_alert_commented', hook_data)
10691069

10701070
track_activity(f"alert \"{alert.alert_id}\" commented", ctx_less=True)
10711071
return response_success("Alert commented", data=comment_schema.dump(comment))

source/app/blueprints/rest/case/case_assets_routes.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from app.datamgmt.case.case_assets_db import get_case_asset_comments
4545
from app.datamgmt.case.case_assets_db import get_similar_assets
4646
from app.datamgmt.case.case_db import get_case_client_id
47+
from app.datamgmt.comments import get_comment
4748
from app.datamgmt.manage.manage_attribute_db import get_default_custom_attributes
4849
from app.datamgmt.manage.manage_users_db import get_user_cases_fast
4950
from app.datamgmt.states import get_assets_state
@@ -166,7 +167,7 @@ def case_assets_state(caseid):
166167
def deprecated_add_asset(caseid):
167168
asset_schema = CaseAssetsSchema()
168169
try:
169-
request_data = call_modules_hook('on_preload_asset_create', data=request.get_json(), caseid=caseid)
170+
request_data = call_modules_hook('on_preload_asset_create', request.get_json(), caseid=caseid)
170171
ioc_links = request_data.get('ioc_links')
171172
asset = asset_schema.load(request_data)
172173
created_asset = assets_create(iris_current_user, caseid, asset, ioc_links)
@@ -243,7 +244,7 @@ def case_upload_asset(caseid):
243244

244245
row['analysis_status_id'] = analysis_status_id
245246

246-
request_data = call_modules_hook('on_preload_asset_create', data=row, caseid=caseid)
247+
request_data = call_modules_hook('on_preload_asset_create', row, caseid=caseid)
247248

248249
add_asset_schema.is_unique_for_cid(caseid, request_data)
249250
asset_sc = add_asset_schema.load(request_data)
@@ -253,7 +254,7 @@ def case_upload_asset(caseid):
253254
user_id=iris_current_user.id
254255
)
255256

256-
asset = call_modules_hook('on_postload_asset_create', data=asset, caseid=caseid)
257+
asset = call_modules_hook('on_postload_asset_create', asset, caseid=caseid)
257258

258259
if not asset:
259260
errors.append('Unable to add asset for internal reason')
@@ -305,7 +306,7 @@ def asset_update(cur_id, caseid):
305306
if not asset:
306307
return response_error("Invalid asset ID for this case")
307308

308-
request_data = call_modules_hook('on_preload_asset_update', data=request.get_json(), caseid=caseid)
309+
request_data = call_modules_hook('on_preload_asset_update', request.get_json(), caseid=caseid)
309310
request_data['asset_id'] = asset.asset_id
310311
schema = CaseAssetsSchema()
311312
updated_asset = schema.load(request_data, instance=asset, partial=True)
@@ -375,7 +376,7 @@ def case_comment_asset_add(cur_id, caseid):
375376
"comment": comment_schema.dump(comment),
376377
"asset": CaseAssetsSchema().dump(asset)
377378
}
378-
call_modules_hook('on_postload_asset_commented', data=hook_data, caseid=caseid)
379+
call_modules_hook('on_postload_asset_commented', hook_data, caseid=caseid)
379380

380381
track_activity(f"asset \"{asset.asset_name}\" commented", caseid=caseid)
381382
return response_success("Asset commented", data=comment_schema.dump(comment))
@@ -407,11 +408,13 @@ def case_comment_asset_edit(cur_id, com_id, caseid):
407408
@ac_requires_case_identifier(CaseAccessLevel.full_access)
408409
@ac_api_requires()
409410
def case_comment_asset_delete(cur_id, com_id, caseid):
410-
success, msg = delete_asset_comment(cur_id, com_id)
411-
if not success:
412-
return response_error(msg)
411+
comment = get_comment(iris_current_user, com_id)
412+
if not comment:
413+
return response_error('You are not allowed to delete this comment')
414+
415+
delete_asset_comment(cur_id, comment)
413416

414-
call_modules_hook('on_postload_asset_comment_delete', data=com_id, caseid=caseid)
417+
call_modules_hook('on_postload_asset_comment_delete', com_id, caseid=caseid)
415418

416419
track_activity(f'comment {com_id} on asset {cur_id} deleted', caseid=caseid)
417-
return response_success(msg)
420+
return response_success('Comment deleted')

source/app/blueprints/rest/case/case_evidences_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def case_comment_evidence_add(cur_id, caseid):
189189
"comment": comment_schema.dump(comment),
190190
"evidence": CaseEvidenceSchema().dump(evidence)
191191
}
192-
call_modules_hook('on_postload_evidence_commented', data=hook_data, caseid=caseid)
192+
call_modules_hook('on_postload_evidence_commented', hook_data, caseid=caseid)
193193

194194
track_activity(f"evidence \"{evidence.filename}\" commented", caseid=caseid)
195195
return response_success("Evidence commented", data=comment_schema.dump(comment))
@@ -225,7 +225,7 @@ def case_comment_evidence_delete(cur_id, com_id, caseid):
225225
if not success:
226226
return response_error(msg)
227227

228-
call_modules_hook('on_postload_evidence_comment_delete', data=com_id, caseid=caseid)
228+
call_modules_hook('on_postload_evidence_comment_delete', com_id, caseid=caseid)
229229

230230
track_activity(f"comment {com_id} on evidence {cur_id} deleted", caseid=caseid)
231231
return response_success(msg)

source/app/blueprints/rest/case/case_ioc_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def case_upload_ioc(caseid):
179179
row['ioc_type_id'] = type_id.type_id
180180
row.pop('ioc_type', None)
181181

182-
request_data = call_modules_hook('on_preload_ioc_create', data=row, caseid=caseid)
182+
request_data = call_modules_hook('on_preload_ioc_create', row, caseid=caseid)
183183

184184
ioc = add_ioc_schema.load(request_data)
185185
ioc.custom_attributes = get_default_custom_attributes('ioc')
@@ -191,7 +191,7 @@ def case_upload_ioc(caseid):
191191
continue
192192

193193
add_ioc(ioc, iris_current_user.id, caseid)
194-
ioc = call_modules_hook('on_postload_ioc_create', data=ioc, caseid=caseid)
194+
ioc = call_modules_hook('on_postload_ioc_create', ioc, caseid=caseid)
195195
ret.append(request_data)
196196
track_activity(f'added ioc "{ioc.ioc_value}"', caseid=caseid)
197197

@@ -304,7 +304,7 @@ def case_comment_ioc_add(cur_id, caseid):
304304
'comment': comment_schema.dump(comment),
305305
'ioc': IocSchema().dump(ioc)
306306
}
307-
call_modules_hook('on_postload_ioc_commented', data=hook_data, caseid=ioc.case_id)
307+
call_modules_hook('on_postload_ioc_commented', hook_data, caseid=ioc.case_id)
308308

309309
track_activity(f'ioc "{ioc.ioc_value}" commented', caseid=ioc.case_id)
310310
return response_success('IOC commented', data=comment_schema.dump(comment))
@@ -342,7 +342,7 @@ def case_comment_ioc_delete(cur_id, com_id, caseid):
342342
if not success:
343343
return response_error(msg)
344344

345-
call_modules_hook('on_postload_ioc_comment_delete', data=com_id, caseid=caseid)
345+
call_modules_hook('on_postload_ioc_comment_delete', com_id, caseid=caseid)
346346

347347
track_activity(f'comment {com_id} on ioc {cur_id} deleted', caseid=caseid)
348348
return response_success(msg)

source/app/blueprints/rest/case/case_notes_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def case_note_save(cur_id, caseid):
138138

139139
try:
140140
note = notes_get(cur_id)
141-
request_data = call_modules_hook('on_preload_note_update', data=request.get_json(), caseid=note.note_case_id)
141+
request_data = call_modules_hook('on_preload_note_update', request.get_json(), caseid=note.note_case_id)
142142

143143
request_data['note_id'] = note.note_id
144144
addnote_schema.load(request_data, partial=True, instance=note)
@@ -207,7 +207,7 @@ def case_note_add(caseid):
207207

208208
try:
209209

210-
request_data = call_modules_hook('on_preload_note_create', data=request.get_json(), caseid=caseid)
210+
request_data = call_modules_hook('on_preload_note_create', request.get_json(), caseid=caseid)
211211
note_schema = CaseNoteSchema()
212212
note_schema.verify_directory_id(request_data, caseid=caseid)
213213

@@ -426,7 +426,7 @@ def case_comment_note_add(cur_id, caseid):
426426
"comment": comment_schema.dump(comment),
427427
"note": CaseNoteSchema().dump(note)
428428
}
429-
call_modules_hook('on_postload_note_commented', data=hook_data, caseid=caseid)
429+
call_modules_hook('on_postload_note_commented', hook_data, caseid=caseid)
430430

431431
track_activity(f"note \"{note.note_title}\" commented", caseid=caseid)
432432
return response_success("Note commented", data=comment_schema.dump(comment))
@@ -462,7 +462,7 @@ def case_comment_note_delete(cur_id, com_id, caseid):
462462
if not success:
463463
return response_error(msg)
464464

465-
call_modules_hook('on_postload_note_comment_delete', data=com_id, caseid=caseid)
465+
call_modules_hook('on_postload_note_comment_delete', com_id, caseid=caseid)
466466

467467
track_activity(f"comment {com_id} on note {cur_id} deleted", caseid=caseid)
468468
return response_success(msg)

source/app/blueprints/rest/case/case_tasks_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def case_comment_task_add(cur_id: int, caseid: int):
230230
"comment": comment_schema.dump(comment),
231231
"task": CaseTaskSchema().dump(task)
232232
}
233-
call_modules_hook('on_postload_task_commented', data=hook_data, caseid=caseid)
233+
call_modules_hook('on_postload_task_commented', hook_data, caseid=caseid)
234234

235235
track_activity(f"task \"{task.task_title}\" commented", caseid=caseid)
236236
return response_success("Task commented", data=comment_schema.dump(comment))
@@ -270,7 +270,7 @@ def case_comment_task_delete(cur_id: int, com_id: int, caseid: int):
270270
if not success:
271271
return response_error(msg)
272272

273-
call_modules_hook('on_postload_task_comment_delete', data=com_id, caseid=caseid)
273+
call_modules_hook('on_postload_task_comment_delete', com_id, caseid=caseid)
274274

275275
track_activity(f"comment {com_id} on task {cur_id} deleted", caseid=caseid)
276276
return response_success(msg)

0 commit comments

Comments
 (0)