Projet

Général

Profil

0001-admin-do-not-reuse-function-slugs-35617.patch

Frédéric Péters, 27 août 2019 19:38

Télécharger (2,53 ko)

Voir les différences:

Subject: [PATCH] admin: do not reuse function slugs (#35617)

 tests/test_admin_pages.py | 12 +++++++++++-
 wcs/admin/workflows.py    |  6 +++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
tests/test_admin_pages.py
3082 3082
    assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function'])
3083 3083
    assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
3084 3084

  
3085
    # test new function with older name
3086
    resp = app.get('/backoffice/workflows/%s/' % workflow.id)
3087
    resp = resp.click('add function')
3088
    resp.forms[0]['name'] = 'Other Function'
3089
    resp = resp.forms[0].submit('submit')
3090
    assert set(Workflow.get(workflow.id).roles.keys()) == set(
3091
            ['_receiver', '_other-function', '_other-function-2'])
3092
    assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
3093
    assert Workflow.get(workflow.id).roles['_other-function-2'] == 'Other Function'
3094

  
3085 3095
    # test removal
3086 3096
    resp = app.get('/backoffice/workflows/%s/' % workflow.id)
3087 3097
    resp = resp.click('Other Renamed Function')
3088 3098
    resp = resp.forms[0].submit('delete')
3089
    assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver'])
3099
    assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function-2'])
3090 3100

  
3091 3101
    # make sure it's not possible to remove the "_receiver" key
3092 3102
    resp = app.get('/backoffice/workflows/%s/' % workflow.id)
wcs/admin/workflows.py
950 950

  
951 951
        if form.is_submitted() and not form.has_errors():
952 952
            name = form.get_widget('name').parse()
953
            slug = '_%s' % misc.simplify(name)
953
            base_slug = slug = '_%s' % misc.simplify(name)
954
            base_idx = 2
955
            while slug in self.workflow.roles:
956
                slug = '%s-%s' % (base_slug, base_idx)
957
                base_idx += 1
954 958
            self.workflow.roles[slug] = name
955 959
            # go over all existing status and update their visibility
956 960
            # restrictions if necessary
957
-