Keine Beschreibung

manage_templates_routes.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 app.forms import AddReportTemplateForm
  23. from app.models.authorization import Permissions
  24. from app.models.models import CaseTemplateReport
  25. from app.models.models import Languages
  26. from app.models.models import ReportType
  27. from app.blueprints.access_controls import ac_requires
  28. manage_templates_blueprint = Blueprint(
  29. 'manage_templates',
  30. __name__,
  31. template_folder='templates'
  32. )
  33. @manage_templates_blueprint.route('/manage/templates')
  34. @ac_requires(Permissions.server_administrator, no_cid_required=True)
  35. def manage_report_templates(caseid, url_redir):
  36. if url_redir:
  37. redirect(url_for('manage_templates.manage_report_templates', cid=caseid))
  38. form = AddReportTemplateForm()
  39. form.report_language.choices = [(c.id, c.name.capitalize()) for c in Languages.query.all()]
  40. # Return default page of case management
  41. return render_template('manage_templates.html', form=form)
  42. @manage_templates_blueprint.route('/manage/templates/add/modal', methods=['GET'])
  43. @ac_requires(Permissions.server_administrator, no_cid_required=True)
  44. def add_template_modal(caseid, url_redir):
  45. if url_redir:
  46. redirect(url_for('manage_templates.manage_report_templates', cid=caseid))
  47. report_template = CaseTemplateReport()
  48. form = AddReportTemplateForm()
  49. form.report_language.choices = [(c.id, c.name.capitalize()) for c in Languages.query.all()]
  50. form.report_type.choices = [(c.id, c.name) for c in ReportType.query.all()]
  51. return render_template("modal_add_report_template.html", form=form, report_template=report_template)