1
0
forked from ScoDoc/ScoDoc
This commit is contained in:
Emmanuel Viennet 2022-08-08 10:34:13 +02:00
parent c065abd0bb
commit f0c342fad5
5 changed files with 25 additions and 14 deletions

View File

@ -31,7 +31,7 @@ def verify_password(username, password):
@basic_auth.error_handler @basic_auth.error_handler
def basic_auth_error(status): def basic_auth_error(status):
"error response (401 for invalid auth.)" "error response (401 for invalid auth.)"
return error_response(status) return json_error(status)
@login.user_loader @login.user_loader
@ -55,7 +55,7 @@ def verify_token(token) -> User:
@token_auth.error_handler @token_auth.error_handler
def token_auth_error(status): def token_auth_error(status):
"Réponse en cas d'erreur d'auth." "Réponse en cas d'erreur d'auth."
return error_response(status) return json_error(status)
@token_auth.get_user_roles @token_auth.get_user_roles

View File

@ -77,9 +77,7 @@ def get_formsemestre_bulletin_etud_json(
if formsemestre.formation.is_apc(): if formsemestre.formation.is_apc():
bul = bulletin_but.BulletinBUT(formsemestre) bul = bulletin_but.BulletinBUT(formsemestre)
if not etud.id in bul.res.identdict: if not etud.id in bul.res.identdict:
return error_response( return json_error(404, "get_formsemestre_bulletin_etud_json: invalid etud")
404, "get_formsemestre_bulletin_etud_json: invalid etud"
)
return jsonify( return jsonify(
bul.bulletin_etud( bul.bulletin_etud(
etud, etud,

View File

@ -31,6 +31,8 @@
import datetime import datetime
import json import json
from flask import abort
from app.comp import res_sem from app.comp import res_sem
from app.comp.res_compat import NotesTableCompat from app.comp.res_compat import NotesTableCompat
from app.models import but_validations from app.models import but_validations
@ -92,6 +94,8 @@ def formsemestre_bulletinetud_published_dict(
sem = sco_formsemestre.get_formsemestre(formsemestre_id) sem = sco_formsemestre.get_formsemestre(formsemestre_id)
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
if not etudid in nt.identdict:
abort(404, "etudiant non inscrit dans ce semestre")
d = {"type": "classic", "version": "0"} d = {"type": "classic", "version": "0"}
if (not sem["bul_hide_xml"]) or force_publishing: if (not sem["bul_hide_xml"]) or force_publishing:
published = True published = True

View File

@ -53,7 +53,7 @@ import time
import PIL import PIL
from PIL import Image as PILImage from PIL import Image as PILImage
from flask import request, g from flask import request, g, has_request_context
from flask.helpers import make_response, url_for from flask.helpers import make_response, url_for
from app import log from app import log
@ -91,8 +91,15 @@ def photo_portal_url(etud):
def get_etud_photo_url(etudid, size="small"): def get_etud_photo_url(etudid, size="small"):
return url_for( return (
"scolar.get_photo_image", scodoc_dept=g.scodoc_dept, etudid=etudid, size=size url_for(
"scolar.get_photo_image",
scodoc_dept=g.scodoc_dept,
etudid=etudid,
size=size,
)
if has_request_context()
else ""
) )

View File

@ -32,10 +32,16 @@ print(f"SCODOC_URL={SCODOC_URL}")
print(f"API URL={API_URL}") print(f"API URL={API_URL}")
class APIError(Exception):
pass
def get_auth_headers(user, password) -> dict: def get_auth_headers(user, password) -> dict:
"Demande de jeton, dict à utiliser dans les en-têtes de requêtes http" "Demande de jeton, dict à utiliser dans les en-têtes de requêtes http"
r0 = requests.post(API_URL + "/tokens", auth=(user, password)) ans = requests.post(API_URL + "/tokens", auth=(user, password))
token = r0.json()["token"] if ans.status_code != 200:
raise APIError(f"Echec demande jeton par {user}")
token = ans.json()["token"]
return {"Authorization": f"Bearer {token}"} return {"Authorization": f"Bearer {token}"}
@ -51,10 +57,6 @@ def api_admin_headers() -> dict:
return get_auth_headers(API_USER_ADMIN, API_PASSWORD_ADMIN) return get_auth_headers(API_USER_ADMIN, API_PASSWORD_ADMIN)
class APIError(Exception):
pass
def GET(path: str, headers: dict = None, errmsg=None, dept=None): def GET(path: str, headers: dict = None, errmsg=None, dept=None):
"""Get and returns as JSON""" """Get and returns as JSON"""
if dept: if dept: