From 9fb8796e0ddb106f2192782feffe4b70d441d7c4 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 27 Aug 2021 18:17:45 +0200 Subject: [PATCH] Corrige calcul URL "zope compatibles" en http/https en mode production --- app/decorators.py | 14 ++++++++------ app/scodoc/sco_evaluations.py | 1 + config.py | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/decorators.py b/app/decorators.py index a6399cd7c..a1a91f484 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -41,13 +41,15 @@ class ZRequest(object): "Emulating Zope 2 REQUEST" def __init__(self): - self.URL = request.base_url - + if current_app.config["DEBUG"]: + self.URL = request.base_url + self.BASE0 = request.url_root + else: + self.URL = request.base_url.replace("http://", "https://") + self.BASE0 = request.url_root.replace("http://", "https://") self.URL0 = self.URL - self.BASE0 = request.url_root - self.QUERY_STRING = request.query_string.decode( - "utf-8" - ) # query_string is bytes + # query_string is bytes: + self.QUERY_STRING = request.query_string.decode("utf-8") self.REQUEST_METHOD = request.method self.AUTHENTICATED_USER = current_user self.REMOTE_ADDR = request.remote_addr diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index 59e5d264e..4ab2e05d4 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -37,6 +37,7 @@ import flask from flask import url_for from flask import g from flask_login import current_user +from flask import request from app.scodoc.notes_log import log, logCallStack import app.scodoc.sco_utils as scu diff --git a/config.py b/config.py index a25603254..a7329be33 100755 --- a/config.py +++ b/config.py @@ -45,6 +45,7 @@ class ProdConfig(Config): SQLALCHEMY_DATABASE_URI = ( os.environ.get("SCODOC_DATABASE_URI") or "postgresql:///SCODOC" ) + PREFERRED_URL_SCHEME = "https" class DevConfig(Config): @@ -59,6 +60,7 @@ class DevConfig(Config): class TestConfig(DevConfig): TESTING = True + DEBUG = True SQLALCHEMY_DATABASE_URI = ( os.environ.get("SCODOC_TEST_DATABASE_URI") or "postgresql:///SCODOC_TEST" )