Projet

Général

Profil

0001-misc-add-feature-flag-to-disable-jsonp-sources-66396.patch

Frédéric Péters, 22 juin 2022 09:14

Télécharger (2,76 ko)

Voir les différences:

Subject: [PATCH] misc: add feature flag to disable jsonp sources (#66396)

 tests/admin_pages/test_datasource.py | 30 ++++++++++++++++++++++++++++
 wcs/data_sources.py                  |  4 +++-
 2 files changed, 33 insertions(+), 1 deletion(-)
tests/admin_pages/test_datasource.py
271 271
    ]
272 272

  
273 273

  
274
def test_data_sources_type_options_jsonp(pub):
275
    create_superuser(pub)
276

  
277
    data_source = NamedDataSource(name='foobar')
278
    data_source.store()
279

  
280
    if not pub.site_options.has_section('options'):
281
        pub.site_options.add_section('options')
282
    pub.site_options.set('options', 'disable-jsonp-sources', 'false')
283
    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
284
        pub.site_options.write(fd)
285

  
286
    app = login(get_app(pub))
287
    resp = app.get('/backoffice/settings/data-sources/%s/edit' % data_source.id)
288
    assert 'jsonp' in [x[0] for x in resp.form['data_source$type'].options]
289

  
290
    pub.site_options.set('options', 'disable-jsonp-sources', 'true')
291
    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
292
        pub.site_options.write(fd)
293

  
294
    resp = app.get('/backoffice/settings/data-sources/%s/edit' % data_source.id)
295
    assert 'jsonp' not in [x[0] for x in resp.form['data_source$type'].options]
296

  
297
    # make sure it's still displayed for sources using it.
298
    data_source.data_source = {'type': 'jsonp', 'value': 'http://some.url'}
299
    data_source.store()
300
    resp = app.get('/backoffice/settings/data-sources/%s/edit' % data_source.id)
301
    assert 'jsonp' in [x[0] for x in resp.form['data_source$type'].options]
302

  
303

  
274 304
def test_data_sources_category(pub):
275 305
    create_superuser(pub)
276 306

  
wcs/data_sources.py
139 139
        if len(options) > 1:
140 140
            options.append(OptGroup(_('Generic Data Sources')))
141 141
        options.append(('json', _('JSON URL'), 'json', {'data-maybe-datetimes': 'true'}))
142
        if allow_jsonp:
142
        if allow_jsonp and (
143
            value.get('type') == 'jsonp' or not get_publisher().has_site_option('disable-jsonp-sources')
144
        ):
143 145
            options.append(('jsonp', _('JSONP URL'), 'jsonp'))
144 146
        if allow_geojson:
145 147
            options.append(('geojson', _('GeoJSON URL'), 'geojson'))
146
-