Ei kuvausta

__init__.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # IRIS Source Code
  2. # Copyright (C) 2024 - 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, request
  19. from app.blueprints.access_controls import ac_api_requires
  20. from app.blueprints.rest.endpoints import response_api_success
  21. from app.datamgmt.dashboard.dashboard_db import list_user_cases, list_user_tasks, list_user_reviews
  22. from app.schema.marshables import CaseDetailsSchema, CaseTaskSchema, CaseSchema
  23. dashboard_blueprint = Blueprint('dashboard',
  24. __name__,
  25. url_prefix='/dashboard')
  26. # TODO this endpoint does not adhere to the conventions (verb in URL).
  27. # Prefer to use GET /api/v2/cases. Check it is possible. If not, evolve /api/v2/cases
  28. #@dashboard_blueprint.route('/cases/list', methods=['GET'])
  29. @ac_api_requires()
  30. def list_own_cases():
  31. cases = list_user_cases(
  32. request.args.get('show_closed', 'false', type=str).lower() == 'true'
  33. )
  34. return response_api_success(data=CaseDetailsSchema(many=True).dump(cases))
  35. # TODO this endpoint does not adhere to the conventions (verb in URL).
  36. # We should rather have /api/v2/tasks?
  37. #@dashboard_blueprint.route('/tasks/list', methods=['GET'])
  38. @ac_api_requires()
  39. def list_own_tasks():
  40. ct = list_user_tasks()
  41. return response_api_success(data=CaseTaskSchema(many=True).dump(ct))
  42. # TODO this endpoint does not adhere to the conventions (verb in URL).
  43. # We should rather have /api/v2/reviews?
  44. #@dashboard_blueprint.route('/reviews/list', methods=['GET'])
  45. @ac_api_requires()
  46. def list_own_reviews():
  47. reviews = list_user_reviews()
  48. return response_api_success(
  49. data=CaseSchema(
  50. many=True,
  51. only=["case_id", "case_name",
  52. "review_status.status_name", "status_id"]
  53. ).dump(reviews))