misc: warn when a time related condition is used with no timeout (#69291)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7a29133b1d
commit
afa1f8879e
|
@ -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