From d86bb3e9b70cdaa4ec65015139882b987d84c25f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 22 Dec 2021 10:23:17 +0100 Subject: [PATCH] =?UTF-8?q?le=20fichier=20oubli=C3=A9=20en=209.1.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logos.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 app/api/logos.py diff --git a/app/api/logos.py b/app/api/logos.py new file mode 100644 index 000000000..4fdb10992 --- /dev/null +++ b/app/api/logos.py @@ -0,0 +1,97 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +############################################################################## +# +# Gestion scolarite IUT +# +# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Emmanuel Viennet emmanuel.viennet@viennet.net +# +############################################################################## + +"""API: gestion des logos +Contrib @jmp +""" + +from datetime import datetime +from flask import jsonify, g, send_file + +from app.api import bp +from app.api import requested_format +from app.api.auth import token_auth +from app.api.errors import error_response +from app.models import Departement +from app.scodoc.sco_logos import list_logos, find_logo +from app.scodoc.sco_permissions import Permission + + +@bp.route("/logos", methods=["GET"]) +@token_auth.login_required +def api_get_glob_logos(): + if not g.current_user.has_permission(Permission.ScoSuperAdmin, None): + return error_response(401, message="accès interdit") + required_format = requested_format() # json only + if required_format is None: + return error_response(400, "Illegal format") + logos = list_logos()[None] + return jsonify(list(logos.keys())) + + +@bp.route("/logos/", methods=["GET"]) +@token_auth.login_required +def api_get_glob_logo(logoname): + if not g.current_user.has_permission(Permission.ScoSuperAdmin, None): + return error_response(401, message="accès interdit") + logo = find_logo(logoname=logoname) + if logo is None: + return error_response(404, message="logo not found") + logo.select() + return send_file( + logo.filepath, + mimetype=f"image/{logo.suffix}", + last_modified=datetime.now(), + ) + + +@bp.route("/departements//logos", methods=["GET"]) +@token_auth.login_required +def api_get_local_logos(departement): + dept_id = Departement.from_acronym(departement).id + if not g.current_user.has_permission(Permission.ScoChangePreferences, departement): + return error_response(401, message="accès interdit") + logos = list_logos().get(dept_id, dict()) + return jsonify(list(logos.keys())) + + +@bp.route("/departements//logos/", methods=["GET"]) +@token_auth.login_required +def api_get_local_logo(departement, logoname): + # format = requested_format("jpg", ['png', 'jpg']) XXX ? + dept_id = Departement.from_acronym(departement).id + if not g.current_user.has_permission(Permission.ScoChangePreferences, departement): + return error_response(401, message="accès interdit") + logo = find_logo(logoname=logoname, dept_id=dept_id) + if logo is None: + return error_response(404, message="logo not found") + logo.select() + return send_file( + logo.filepath, + mimetype=f"image/{logo.suffix}", + last_modified=datetime.now(), + )