Нема описа

overview_db.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # IRIS Source Code
  2. # DFIR-IRIS Team
  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. import datetime
  19. from sqlalchemy import and_
  20. from app.datamgmt.case.case_tasks_db import get_tasks_cases_mapping
  21. from app.datamgmt.manage.manage_cases_db import user_list_cases_view
  22. from app.models.cases import Cases
  23. from app.schema.marshables import CaseDetailsSchema
  24. def get_overview_db(user_id, show_full):
  25. """
  26. Get overview data from the database
  27. """
  28. condition = and_(Cases.case_id.in_(user_list_cases_view(user_id)))
  29. if not show_full:
  30. condition = and_(condition, Cases.close_date == None)
  31. open_cases = Cases.query.filter(
  32. condition
  33. ).join(
  34. Cases.owner
  35. ).join(
  36. Cases.client
  37. ).all()
  38. cases_list = []
  39. tasks_map = get_tasks_cases_mapping(open_cases_only=not show_full)
  40. tmap = {}
  41. for task in tasks_map:
  42. if tmap.get(task.task_case_id) is None:
  43. tmap[task.task_case_id] = {
  44. 'open_tasks': 0,
  45. 'closed_tasks': 0
  46. }
  47. if task.task_status_id in [1, 2, 3]:
  48. tmap[task.task_case_id]['open_tasks'] += 1
  49. elif task.task_status_id == 4:
  50. tmap[task.task_case_id]['closed_tasks'] += 1
  51. # open_cases_list = []
  52. for case in open_cases:
  53. c_case = CaseDetailsSchema().dump(case)
  54. c_case['case_open_since_days'] = (datetime.date.today() - case.open_date).days
  55. c_case['tasks_status'] = tmap.get(case.case_id)
  56. cases_list.append(c_case)
  57. return cases_list