Нема описа

manage_task_status_routes.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # IRIS Source Code
  2. # Copyright (C) 2021 - Airbus CyberSecurity (SAS)
  3. # ir@cyberactionlab.net
  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.models.models import TaskStatus
  20. from app.blueprints.access_controls import ac_api_requires
  21. from app.blueprints.responses import response_error
  22. from app.blueprints.responses import response_success
  23. manage_task_status_rest_blueprint = Blueprint('manage_task_status_rest', __name__)
  24. @manage_task_status_rest_blueprint.route('/manage/task-status/list', methods=['GET'])
  25. @ac_api_requires()
  26. def list_task_status():
  27. lstatus = TaskStatus.query.with_entities(
  28. TaskStatus.id,
  29. TaskStatus.status_name,
  30. TaskStatus.status_bscolor,
  31. TaskStatus.status_description
  32. ).all()
  33. data = [row._asdict() for row in lstatus]
  34. return response_success("", data=data)
  35. @manage_task_status_rest_blueprint.route('/manage/task-status/<int:cur_id>', methods=['GET'])
  36. @ac_api_requires()
  37. def view_task_status(cur_id):
  38. lstatus = TaskStatus.query.with_entities(
  39. TaskStatus.id,
  40. TaskStatus.status_name,
  41. TaskStatus.status_bscolor,
  42. TaskStatus.status_description
  43. ).filter(
  44. TaskStatus.id == cur_id
  45. ).first()
  46. if not lstatus:
  47. return response_error(f"Task status ID #{cur_id} not found")
  48. return response_success(data=lstatus._asdict())