Açıklama Yok

tasks.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  19. from app.blueprints.rest.endpoints import response_api_not_found
  20. from app.blueprints.rest.endpoints import response_api_success
  21. from app.blueprints.rest.endpoints import response_api_deleted
  22. from app.blueprints.rest.endpoints import response_api_error
  23. from app.blueprints.access_controls import ac_api_requires
  24. from app.blueprints.access_controls import ac_api_return_access_denied
  25. from app.business.tasks import tasks_delete
  26. from app.business.tasks import tasks_get
  27. from app.business.errors import ObjectNotFoundError
  28. from app.business.errors import BusinessProcessingError
  29. from app.models.authorization import CaseAccessLevel
  30. from app.schema.marshables import CaseTaskSchema
  31. from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access
  32. tasks_blueprint = Blueprint('tasks',
  33. __name__,
  34. url_prefix='/tasks')
  35. @tasks_blueprint.get('/<int:identifier>')
  36. @ac_api_requires()
  37. def get_case_task(identifier):
  38. try:
  39. task = tasks_get(identifier)
  40. if not ac_fast_check_current_user_has_case_access(task.task_case_id, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]):
  41. return ac_api_return_access_denied(caseid=task.task_case_id)
  42. task_schema = CaseTaskSchema()
  43. return response_api_success(task_schema.dump(task))
  44. except ObjectNotFoundError:
  45. return response_api_not_found()
  46. @tasks_blueprint.delete('/<int:identifier>')
  47. @ac_api_requires()
  48. def delete_case_task(identifier):
  49. try:
  50. task = tasks_get(identifier)
  51. if not ac_fast_check_current_user_has_case_access(task.task_case_id, [CaseAccessLevel.full_access]):
  52. return ac_api_return_access_denied(caseid=identifier)
  53. tasks_delete(task)
  54. return response_api_deleted()
  55. except ObjectNotFoundError:
  56. return response_api_not_found()
  57. except BusinessProcessingError as e:
  58. return response_api_error(e.get_message())