WIP: fix http redirects, fix some JS urls

This commit is contained in:
Emmanuel Viennet 2021-06-21 14:40:58 +02:00
parent ede5aa680d
commit 64615036ec
9 changed files with 99 additions and 79 deletions

View File

@ -7,6 +7,8 @@ import inspect
import types import types
import logging import logging
import werkzeug
from werkzeug.exceptions import BadRequest
import flask import flask
from flask import g from flask import g
from flask import abort, current_app from flask import abort, current_app
@ -14,7 +16,6 @@ from flask import request
from flask_login import current_user from flask_login import current_user
from flask_login import login_required from flask_login import login_required
from flask import current_app from flask import current_app
from werkzeug.exceptions import BadRequest
from app.auth.models import Permission from app.auth.models import Permission
@ -80,7 +81,8 @@ class ZResponse(object):
self.headers = {} self.headers = {}
def redirect(self, url): def redirect(self, url):
return flask.redirect(url) # http 302 current_app.logger.debug("ZResponse redirect to:" + str(url))
return flask.redirect(url.decode("utf-8")) # http 302 # #sco8 unicode
def setHeader(self, header, value): def setHeader(self, header, value):
self.headers[header.lower()] = value self.headers[header.lower()] = value
@ -188,6 +190,8 @@ def scodoc7func(context):
if not top_level: if not top_level:
return value return value
else: else:
if isinstance(value, werkzeug.wrappers.response.Response):
return value # redirected
# Build response, adding collected http headers: # Build response, adding collected http headers:
headers = [] headers = []
kw = {"response": value, "status": 200} kw = {"response": value, "status": 200}

View File

@ -231,6 +231,8 @@ def sco_header(
<script language="javascript" type="text/javascript" src="/ScoDoc/static/libjs/bubble.js"></script> <script language="javascript" type="text/javascript" src="/ScoDoc/static/libjs/bubble.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.onload=function(){enableTooltips("gtrcontent")}; window.onload=function(){enableTooltips("gtrcontent")};
var SCO_URL="%(ScoURL)s";
</script>""" </script>"""
% params % params
) )

View File

@ -248,6 +248,7 @@ def do_evaluation_create(
evaluation_type=None, evaluation_type=None,
numero=None, numero=None,
REQUEST=None, REQUEST=None,
**kw # ceci pour absorber les arguments excedentaires de tf #sco8
): ):
"""Create an evaluation""" """Create an evaluation"""
if not sco_permissions_check.can_edit_evaluation( if not sco_permissions_check.can_edit_evaluation(

View File

@ -53,15 +53,17 @@ from PIL import Image as PILImage
from cStringIO import StringIO from cStringIO import StringIO
import glob import glob
from flask import request
from config import Config from config import Config
import app.scodoc.sco_utils as scu from app.scodoc import sco_etud
import app.scodoc.notesdb as ndb
from app.scodoc.notes_log import log
from app.scodoc.scolog import logdb
from app.scodoc import sco_portal_apogee from app.scodoc import sco_portal_apogee
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
from app.scodoc import sco_etud from app.scodoc.notes_log import log
from app.scodoc.scolog import logdb
import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu
# Full paths on server's filesystem. Something like "/opt/scodoc/var/scodoc/photos" # Full paths on server's filesystem. Something like "/opt/scodoc/var/scodoc/photos"
PHOTO_DIR = os.path.join(Config.INSTANCE_HOME, "var", "scodoc", "photos") PHOTO_DIR = os.path.join(Config.INSTANCE_HOME, "var", "scodoc", "photos")
@ -89,7 +91,10 @@ def etud_photo_url(context, etud, size="small", fast=False, REQUEST=None):
"""url to the image of the student, in "small" size or "orig" size. """url to the image of the student, in "small" size or "orig" size.
If ScoDoc doesn't have an image and a portal is configured, link to it. If ScoDoc doesn't have an image and a portal is configured, link to it.
""" """
photo_url = "get_photo_image?etudid=%s&size=%s" % (etud["etudid"], size) photo_url = scu.ScoURL() + "/get_photo_image?etudid=%s&size=%s" % (
etud["etudid"],
size,
)
if fast: if fast:
return photo_url return photo_url
path = photo_pathname(context, etud, size=size) path = photo_pathname(context, etud, size=size)
@ -98,7 +103,7 @@ def etud_photo_url(context, etud, size="small", fast=False, REQUEST=None):
ext_url = photo_portal_url(context, etud) ext_url = photo_portal_url(context, etud)
if not ext_url: if not ext_url:
# fallback: Photo "unknown" # fallback: Photo "unknown"
photo_url = UNKNOWN_IMAGE_URL photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL
else: else:
# essaie de copier la photo du portail # essaie de copier la photo du portail
new_path, _ = copy_portal_photo_to_fs(context, etud, REQUEST=REQUEST) new_path, _ = copy_portal_photo_to_fs(context, etud, REQUEST=REQUEST)
@ -141,7 +146,7 @@ def _http_jpeg_file(context, filename, REQUEST=None):
RESPONSE.setHeader("Last-Modified", last_modified_str) RESPONSE.setHeader("Last-Modified", last_modified_str)
RESPONSE.setHeader("Cache-Control", "max-age=3600") RESPONSE.setHeader("Cache-Control", "max-age=3600")
RESPONSE.setHeader("Content-Length", str(file_size)) RESPONSE.setHeader("Content-Length", str(file_size))
header = REQUEST.get_header("If-Modified-Since", None) header = request.headers.get("If-Modified-Since")
if header is not None: if header is not None:
header = header.split(";")[0] header = header.split(";")[0]
# Some proxies seem to send invalid date strings for this # Some proxies seem to send invalid date strings for this

View File

@ -32,7 +32,7 @@ $().ready(function(){
$(elems[i]).qtip({ $(elems[i]).qtip({
content: { content: {
ajax: { ajax: {
url: "etud_info_html?etudid=" + get_etudid_from_elem(elems[i]) + qs, url: SCO_URL + "/etud_info_html?etudid=" + get_etudid_from_elem(elems[i]) + qs,
type: "GET" type: "GET"
//success: function(data, status) { //success: function(data, status) {
// this.set('content.text', data); // this.set('content.text', data);

View File

@ -5,7 +5,7 @@ $().ready(function(){
for (var i = 0; i < spans.length; i++) { for (var i = 0; i < spans.length; i++) {
var sp = spans[i]; var sp = spans[i];
var etudid = sp.id; var etudid = sp.id;
$(sp).load('etud_photo_html?etudid='+etudid); $(sp).load(SCO_URL + '/etud_photo_html?etudid=' + etudid);
} }
}); });
@ -160,7 +160,7 @@ $().ready(function(){
{ {
content: { content: {
ajax: { ajax: {
url: "etud_info_html?with_photo=0&etudid=" + get_etudid_from_elem(elems[i]) url: SCO_URL + "/etud_info_html?with_photo=0&etudid=" + get_etudid_from_elem(elems[i])
}, },
text: "Loading..." text: "Loading..."
}, },

View File

@ -77,3 +77,11 @@ def sco_get_version(REQUEST):
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
def sco_test_view(REQUEST=None): def sco_test_view(REQUEST=None):
return """Vous avez vu sco_test_view !""" return """Vous avez vu sco_test_view !"""
import flask
@bp.route("/essrep")
def essrep():
return flask.Response(status=200, response="Bonjour")

View File

@ -1482,7 +1482,7 @@ sco_publish(
) )
@bp.route("/evaluation_edit") @bp.route("/evaluation_edit", methods=["GET", "POST"])
@permission_required(Permission.ScoEnsView) @permission_required(Permission.ScoEnsView)
@scodoc7func(context) @scodoc7func(context)
def evaluation_edit(context, evaluation_id, REQUEST): def evaluation_edit(context, evaluation_id, REQUEST):
@ -1492,7 +1492,7 @@ def evaluation_edit(context, evaluation_id, REQUEST):
) )
@bp.route("/evaluation_create") @bp.route("/evaluation_create", methods=["GET", "POST"])
@permission_required(Permission.ScoEnsView) @permission_required(Permission.ScoEnsView)
@scodoc7func(context) @scodoc7func(context)
def evaluation_create(context, moduleimpl_id, REQUEST): def evaluation_create(context, moduleimpl_id, REQUEST):

View File

@ -184,7 +184,7 @@ def about(context, REQUEST):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@bp.route("/edit_preferences") @bp.route("/edit_preferences", methods=["GET", "POST"])
@permission_required(Permission.ScoChangePreferences) @permission_required(Permission.ScoChangePreferences)
@scodoc7func(context) @scodoc7func(context)
def edit_preferences(context, REQUEST): def edit_preferences(context, REQUEST):