Projet

Général

Profil

0001-ics-do-not-raise-if-ics-acess-url-do-not-provide-par.patch

Nicolas Roche, 09 avril 2020 15:47

Télécharger (3,05 ko)

Voir les différences:

Subject: [PATCH] ics: do not raise if ics acess url do not provide parameter
 (#41449)

 tests/test_api.py            |  3 +++
 wcs/backoffice/management.py | 11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
tests/test_api.py
2289 2289
    local_user.roles = [role.id]
2290 2290
    local_user.store()
2291 2291

  
2292 2292
    def remove_dtstamp(body):
2293 2293
        # remove dtstamp as the precise timing may vary between two consecutive
2294 2294
        # calls and we shouldn't care.
2295 2295
        return re.sub('DTSTAMP:.*', 'DTSTAMP:--', body)
2296 2296

  
2297
    # check we get 404 on uncomplete url
2298
    assert get_app(pub).get(sign_uri('/api/forms/test/ics/', user=local_user), status=404)
2299

  
2297 2300
    # check it gets the data
2298 2301
    resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar', user=local_user))
2299 2302
    resp2 = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar/', user=local_user))
2300 2303
    assert remove_dtstamp(resp.text) == remove_dtstamp(resp2.text)
2301 2304
    assert resp.headers['content-type'] == 'text/calendar; charset=utf-8'
2302 2305
    assert resp.text.count('BEGIN:VEVENT') == 10
2303 2306
    # check that description contains form name, display id, workflow status,
2304 2307
    # backoffice url and attached user
wcs/backoffice/management.py
1918 1918
            # of the field to use as start date (may be a date field or a
1919 1919
            # string field).
1920 1920
            # ics/<component>/<component2> with <component2> as the identifier
1921 1921
            # of the field to use as end date (ditto, date or string field)
1922 1922
            def _q_traverse(self, path):
1923 1923
                if not path[-1]:
1924 1924
                    # allow trailing slash
1925 1925
                    path = path[:-1]
1926
                start_date_field_varname = path[0]
1927
                end_date_field_varname = None
1928
                if len(path) == 2:
1929
                    end_date_field_varname = path[1]
1930
                elif len(path) > 2:
1926
                if len(path) == 1 or len(path) == 2:
1927
                    start_date_field_varname = path[0]
1928
                    end_date_field_varname = None
1929
                    if len(path) == 2:
1930
                        end_date_field_varname = path[1]
1931
                else:
1931 1932
                    raise errors.TraversalError()
1932 1933

  
1933 1934
                start_date_field_id = None
1934 1935
                end_date_field_id = None
1935 1936
                for field in formdef.get_all_fields():
1936 1937
                    if getattr(field, 'varname', None) == start_date_field_varname:
1937 1938
                        start_date_field_id = field.id
1938 1939
                    if end_date_field_varname and getattr(field, 'varname', None) == end_date_field_varname:
1939
-