Brak opisu

alerts_routes.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # IRIS Source Code
  2. # Copyright (C) 2023 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from flask import Blueprint
  19. from flask import render_template
  20. from flask import redirect
  21. from flask import url_for
  22. from flask_login import current_user
  23. from flask_wtf import FlaskForm
  24. from typing import Union
  25. from werkzeug import Response
  26. from app.datamgmt.alerts.alerts_db import get_alert_by_id
  27. from app.datamgmt.manage.manage_access_control_db import user_has_client_access
  28. from app.models.authorization import Permissions
  29. from app.blueprints.responses import response_error
  30. from app.blueprints.access_controls import ac_requires
  31. alerts_blueprint = Blueprint(
  32. 'alerts',
  33. __name__,
  34. template_folder='templates'
  35. )
  36. @alerts_blueprint.route('/alerts', methods=['GET'])
  37. @ac_requires(Permissions.alerts_read, no_cid_required=True)
  38. def alerts_list_view_route(caseid, url_redir) -> Union[str, Response]:
  39. """
  40. List all alerts
  41. args:
  42. caseid (str): The case id
  43. returns:
  44. Response: The response
  45. """
  46. if url_redir:
  47. return redirect(url_for('alerts.alerts_list_view_route', cid=caseid))
  48. form = FlaskForm()
  49. return render_template('alerts.html', caseid=caseid, form=form)
  50. @alerts_blueprint.route('/alerts/<int:cur_id>/comments/modal', methods=['GET'])
  51. @ac_requires(Permissions.alerts_read, no_cid_required=True)
  52. def alert_comment_modal(cur_id, caseid, url_redir):
  53. """
  54. Get the modal for the alert comments
  55. args:
  56. cur_id (int): The alert id
  57. caseid (str): The case id
  58. returns:
  59. Response: The response
  60. """
  61. if url_redir:
  62. return redirect(url_for('alerts.alerts_list_view_route', cid=caseid, redirect=True))
  63. alert = get_alert_by_id(cur_id)
  64. if not alert:
  65. return response_error('Invalid alert ID')
  66. if not user_has_client_access(current_user.id, alert.alert_customer_id):
  67. return response_error('User not entitled to update alerts for the client', status=403)
  68. return render_template("modal_conversation.html", element_id=cur_id, element_type='alerts',
  69. title=f" alert #{alert.alert_id}")