diff --git a/app_new/gmao_config/routes.py b/app_new/gmao_config/routes.py
index e286210..c695af8 100644
--- a/app_new/gmao_config/routes.py
+++ b/app_new/gmao_config/routes.py
@@ -8,6 +8,16 @@ from app_new.extensions import db
from app_new.outlook.models import GmaoContext
gmao_config_bp = Blueprint('gmao_config', __name__, template_folder='templates')
+LOOKBACK_MAX_HOURS = 24 * 365
+
+
+def _bounded_int(value, default, minimum=1, maximum=None):
+ try:
+ parsed = int(value)
+ except (TypeError, ValueError):
+ parsed = default
+ parsed = max(minimum, parsed)
+ return min(maximum, parsed) if maximum is not None else parsed
@gmao_config_bp.route('/')
@@ -65,7 +75,10 @@ def save():
context.auto_interpret_enabled = request.form.get('auto_interpret_enabled') == 'on'
context.auto_interpret_interval = max(1, int(request.form.get('auto_interpret_interval', 10)))
context.auto_interpret_max_emails = max(1, int(request.form.get('auto_interpret_max_emails', 5)))
- context.auto_interpret_lookback_hours = max(1, int(request.form.get('auto_interpret_lookback_hours', 24)))
+ context.auto_interpret_lookback_hours = _bounded_int(
+ request.form.get('auto_interpret_lookback_hours'), 24,
+ maximum=LOOKBACK_MAX_HOURS,
+ )
# Activation de la synchronisation PRONOTE
context.pronote_sync_enabled = request.form.get('pronote_sync_enabled') == 'on'
@@ -75,7 +88,10 @@ def save():
# Activation de la synchronisation Outlook
context.outlook_sync_enabled = request.form.get('outlook_sync_enabled') == 'on'
context.outlook_sync_interval = max(1, int(request.form.get('outlook_sync_interval', 10)))
- context.outlook_sync_lookback_hours = max(1, int(request.form.get('outlook_sync_lookback_hours', 24)))
+ context.outlook_sync_lookback_hours = _bounded_int(
+ request.form.get('outlook_sync_lookback_hours'), 24,
+ maximum=LOOKBACK_MAX_HOURS,
+ )
# Configuration IA
from app_new.core.models.settings import AppSettings
diff --git a/app_new/gmao_config/templates/gmao_config/index.html b/app_new/gmao_config/templates/gmao_config/index.html
index f03b2ec..c779871 100644
--- a/app_new/gmao_config/templates/gmao_config/index.html
+++ b/app_new/gmao_config/templates/gmao_config/index.html
@@ -249,9 +249,10 @@
value="{{ context.auto_interpret_max_emails or 5 }}">
-
- Lookback ENT / interprétation (heures)
+
+ Maximum : 8 760 heures (365 jours).
@@ -306,8 +307,9 @@
-
+ Maximum : 8 760 heures (365 jours).
@@ -415,4 +417,4 @@ function testInterpretation() {
});
}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/app_new/templates/gmao_config/index.html b/app_new/templates/gmao_config/index.html
index f03b2ec..c779871 100644
--- a/app_new/templates/gmao_config/index.html
+++ b/app_new/templates/gmao_config/index.html
@@ -249,9 +249,10 @@
value="{{ context.auto_interpret_max_emails or 5 }}">
-
- Lookback ENT / interprétation (heures)
+
+ Maximum : 8 760 heures (365 jours).
@@ -306,8 +307,9 @@
-
+ Maximum : 8 760 heures (365 jours).
@@ -415,4 +417,4 @@ function testInterpretation() {
});
}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/tests/integration/test_gmao_config_lookback.py b/tests/integration/test_gmao_config_lookback.py
new file mode 100644
index 0000000..04d1b72
--- /dev/null
+++ b/tests/integration/test_gmao_config_lookback.py
@@ -0,0 +1,30 @@
+from app_new.extensions import db
+from app_new.outlook.models import GmaoContext
+
+
+def test_gmao_config_accepts_one_year_lookback(authenticated_client, app, admin_user):
+ response = authenticated_client.post('/gmao-config/save', data={
+ 'auto_interpret_lookback_hours': '8760',
+ 'outlook_sync_lookback_hours': '8760',
+ })
+ assert response.status_code == 302
+ with app.app_context():
+ context = GmaoContext.query.filter_by(user_id=admin_user['id']).one()
+ assert context.auto_interpret_lookback_hours == 8760
+ assert context.outlook_sync_lookback_hours == 8760
+ db.session.delete(context)
+ db.session.commit()
+
+
+def test_gmao_config_caps_lookback_at_one_year(authenticated_client, app, admin_user):
+ response = authenticated_client.post('/gmao-config/save', data={
+ 'auto_interpret_lookback_hours': '9000',
+ 'outlook_sync_lookback_hours': '9000',
+ })
+ assert response.status_code == 302
+ with app.app_context():
+ context = GmaoContext.query.filter_by(user_id=admin_user['id']).one()
+ assert context.auto_interpret_lookback_hours == 8760
+ assert context.outlook_sync_lookback_hours == 8760
+ db.session.delete(context)
+ db.session.commit()