misc: warn when a time related condition is used with no timeout (#69291) #1329
|
@ -145,6 +145,26 @@ def test_validate_condition(pub):
|
|||
resp = get_app(pub).get('/api/validate-condition?type=unknown&value_unknown=2')
|
||||
assert resp.json['msg'] == 'unknown condition type'
|
||||
|
||||
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=today > "2023"')
|
||||
assert resp.json == {'msg': ''}
|
||||
resp = get_app(pub).get(
|
||||
'/api/validate-condition?type=django&value_django=today > "2023"&warn-on-datetime=false'
|
||||
)
|
||||
assert resp.json == {'msg': ''}
|
||||
resp = get_app(pub).get(
|
||||
'/api/validate-condition?type=django&value_django=today > "2023"&warn-on-datetime=true'
|
||||
)
|
||||
assert resp.json['msg'].startswith('Warning: conditions are only evaluated when entering')
|
||||
|
||||
resp = get_app(pub).get(
|
||||
'/api/validate-condition?type=django&value_django=x|age_in_days > 10&warn-on-datetime=true'
|
||||
)
|
||||
assert resp.json['msg'].startswith('Warning: conditions are only evaluated when entering')
|
||||
resp = get_app(pub).get(
|
||||
'/api/validate-condition?type=django&value_django=x|age_in_days|abs > 10&warn-on-datetime=true'
|
||||
)
|
||||
assert resp.json['msg'].startswith('Warning: conditions are only evaluated when entering')
|
||||
|
||||
|
||||
def test_reverse_geocoding(pub):
|
||||
with responses.RequestsMock() as rsps:
|
||||
|
|
10
wcs/api.py
10
wcs/api.py
|
@ -18,6 +18,7 @@ import base64
|
|||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
|
||||
|
@ -1476,6 +1477,15 @@ def validate_condition(request, *args, **kwargs):
|
|||
Condition(condition).validate()
|
||||
except ValidationError as e:
|
||||
hint['msg'] = str(e)
|
||||
else:
|
||||
if request.GET.get('warn-on-datetime') == 'true' and condition['type'] == 'django':
|
||||
variables = re.compile(r'\b(today|now)\b')
|
||||
|
||||
filters = re.compile(r'\|age_in_(years|months|days|hours)')
|
||||
if variables.search(condition['value']) or filters.search(condition['value']):
|
||||
hint['msg'] = _(
|
||||
'Warning: conditions are only evaluated when entering the action, '
|
||||
'you may need to set a timeout if you want it to be evaluated regularly.'
|
||||
)
|
||||
return JsonResponse(hint)
|
||||
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ $(function() {
|
|||
$widget.find('select, input').each(function(idx, elem) {
|
||||
data[$(elem).attr('name').replace(prefix, '')] = $(elem).val();
|
||||
});
|
||||
data['warn-on-datetime'] = ($('#form_timeout').length && ! $('#form_timeout').val());
|
||||
$.ajax({
|
||||
url: $widget.data('validation-url'),
|
||||
data: data,
|
||||
|
|
Loading…
Reference in New Issue
Pourquoi une partie de la description du ticket (“ça pourrait commencer très bête et regarder s'il y a |date […] dans la condition”) est passée à la trappe ici ?
J'ajouterai qu'on pourrait aussi penser à détecter tout ce qui est « |age_in_.* » ?
Désolé j'avais raté ce commentaire, je pense que j'avais trouvé des utilisations tout à fait légitimes de |date, pour lesquelles ça me semblait mieux de ne pas inquiéter par un nouveau message.
Ok j'ai du mettre une deuxième regex pour ne pas imposer le \b derrière et rester lisible.
C’est bon pour moi, merci.