Ei kuvausta

manage_case_state_db.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 List
  18. from app.models.cases import CaseState
  19. from app.schema.marshables import CaseStateSchema
  20. def get_case_states_list() -> List[dict]:
  21. """Get a list of case state
  22. Returns:
  23. List[dict]: List of case state
  24. """
  25. case_state = CaseState.query.all()
  26. return CaseStateSchema(many=True).dump(case_state)
  27. def get_case_state_by_id(cur_id: int) -> CaseState:
  28. """Get a case state
  29. Args:
  30. cur_id (int): case state id
  31. Returns:
  32. CaseState: Case state
  33. """
  34. case_state = CaseState.query.filter_by(state_id=cur_id).first()
  35. return case_state
  36. def get_case_state_by_name(cur_name: str) -> CaseState:
  37. """Get a case state
  38. Args:
  39. cur_name (str): case state name
  40. Returns:
  41. CaseState: Case state
  42. """
  43. return CaseState.query.filter_by(state_name=cur_name).first()
  44. def get_cases_using_state(cur_id: int) -> List[dict]:
  45. """Get a list of cases using a case state
  46. Args:
  47. cur_id (int): case state id
  48. Returns:
  49. List[dict]: List of cases
  50. """
  51. case_state = get_case_state_by_id(cur_id)
  52. return case_state.cases