Нема описа

manage_case_state.py 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # IRIS Source Code
  2. # contact@dfir-iris.org
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 3 of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. from typing import Union
  18. from flask import Blueprint
  19. from flask import Response
  20. from flask import url_for
  21. from flask import render_template
  22. from werkzeug.utils import redirect
  23. from app.datamgmt.manage.manage_case_state_db import get_case_state_by_id
  24. from app.forms import CaseStateForm
  25. from app.models.authorization import Permissions
  26. from app.blueprints.responses import response_error
  27. from app.blueprints.access_controls import ac_requires
  28. manage_case_state_blueprint = Blueprint('manage_case_state',
  29. __name__,
  30. template_folder='templates')
  31. @manage_case_state_blueprint.route('/manage/case-states/update/<int:state_id>/modal',
  32. methods=['GET'])
  33. @ac_requires(Permissions.server_administrator, no_cid_required=True)
  34. def update_case_state_modal(state_id: int, caseid: int, url_redir: bool) -> Union[str, Response]:
  35. """Update a case state
  36. Args:
  37. state_id (int): case state id
  38. caseid (int): case id
  39. url_redir (bool): redirect to url
  40. Returns:
  41. Flask Response object or str
  42. """
  43. if url_redir:
  44. return redirect(url_for('manage_case_state_blueprint.update_case_state_modal',
  45. state_id=state_id, caseid=caseid))
  46. state_form = CaseStateForm()
  47. case_state = get_case_state_by_id(state_id)
  48. if not case_state:
  49. return response_error(f"Invalid case state ID {state_id}")
  50. state_form.state_name.render_kw = {'value': case_state.state_name}
  51. state_form.state_description.render_kw = {'value': case_state.state_description}
  52. return render_template("modal_case_state.html", form=state_form,
  53. case_state=case_state)
  54. @manage_case_state_blueprint.route('/manage/case-states/add/modal', methods=['GET'])
  55. @ac_requires(Permissions.server_administrator, no_cid_required=True)
  56. def add_case_state_modal(caseid: int, url_redir: bool) -> Union[str, Response]:
  57. """Add a case state
  58. Args:
  59. caseid (int): case id
  60. url_redir (bool): redirect to url
  61. Returns:
  62. Flask Response object or str
  63. """
  64. if url_redir:
  65. return redirect(url_for('manage_case_state_blueprint.add_case_state_modal',
  66. caseid=caseid))
  67. state_form = CaseStateForm()
  68. return render_template("modal_case_state.html", form=state_form, case_state=None)