Нема описа

dashboard_routes.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 flask import redirect
  20. from flask import render_template
  21. from flask import url_for
  22. from flask_login import current_user
  23. from flask_wtf import FlaskForm
  24. from app import app
  25. from app.datamgmt.dashboard.dashboard_db import get_tasks_status
  26. from app.forms import CaseGlobalTaskForm
  27. from app.iris_engine.access_control.utils import ac_get_user_case_counts
  28. from app.models.authorization import User
  29. from app.models.models import GlobalTasks
  30. from app.blueprints.access_controls import ac_requires
  31. dashboard_blueprint = Blueprint(
  32. 'index',
  33. __name__,
  34. template_folder='templates'
  35. )
  36. # Logout user
  37. @dashboard_blueprint.route('/')
  38. def root():
  39. if app.config['DEMO_MODE_ENABLED'] == 'True':
  40. return redirect(url_for('demo-landing.demo_landing'))
  41. return redirect(url_for('index.index'))
  42. @dashboard_blueprint.route('/dashboard')
  43. @ac_requires()
  44. def index(caseid, url_redir):
  45. """
  46. Index page. Load the dashboard data, create the add customer form
  47. :return: Page
  48. """
  49. if url_redir:
  50. return redirect(url_for('index.index', cid=caseid if caseid is not None else 1, redirect=True))
  51. msg = None
  52. acgucc = ac_get_user_case_counts(current_user.id)
  53. data = {
  54. "user_open_count": acgucc[2],
  55. "cases_open_count": acgucc[1],
  56. "cases_count": acgucc[0],
  57. }
  58. # Create the customer form to be able to quickly add a customer
  59. form = FlaskForm()
  60. return render_template('index.html', data=data, form=form, msg=msg)
  61. @dashboard_blueprint.route('/global/tasks/add/modal', methods=['GET'])
  62. @ac_requires(no_cid_required=True)
  63. def add_gtask_modal(caseid, url_redir):
  64. if url_redir:
  65. return redirect(url_for('index.index', cid=caseid if caseid is not None else 1, redirect=True))
  66. task = GlobalTasks()
  67. form = CaseGlobalTaskForm()
  68. form.task_assignee_id.choices = [(user.id, user.name) for user in User.query.filter(User.active == True).order_by(User.name).all()]
  69. form.task_status_id.choices = [(a.id, a.status_name) for a in get_tasks_status()]
  70. return render_template("modal_add_global_task.html", form=form, task=task, uid=current_user.id, user_name=None)
  71. @dashboard_blueprint.route('/global/tasks/update/<int:cur_id>/modal', methods=['GET'])
  72. @ac_requires(no_cid_required=True)
  73. def edit_gtask_modal(cur_id, caseid, url_redir):
  74. if url_redir:
  75. return redirect(url_for('index.index', cid=caseid if caseid is not None else 1, redirect=True))
  76. form = CaseGlobalTaskForm()
  77. task = GlobalTasks.query.filter(GlobalTasks.id == cur_id).first()
  78. form.task_assignee_id.choices = [(user.id, user.name) for user in
  79. User.query.filter(User.active == True).order_by(User.name).all()]
  80. form.task_status_id.choices = [(a.id, a.status_name) for a in get_tasks_status()]
  81. # Render the task
  82. form.task_title.render_kw = {'value': task.task_title}
  83. form.task_description.data = task.task_description
  84. user_name, = User.query.with_entities(User.name).filter(User.id == task.task_userid_update).first()
  85. return render_template("modal_add_global_task.html", form=form, task=task,
  86. uid=task.task_assignee_id, user_name=user_name)