admin: do not reuse function slugs (#35617)
This commit is contained in:
parent
ca3c69e416
commit
0bfff4a3a8
|
@ -3082,11 +3082,21 @@ def test_workflows_functions(pub):
|
|||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function'])
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
|
||||
|
||||
# test new function with older name
|
||||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
resp = resp.click('add function')
|
||||
resp.forms[0]['name'] = 'Other Function'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(
|
||||
['_receiver', '_other-function', '_other-function-2'])
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
|
||||
assert Workflow.get(workflow.id).roles['_other-function-2'] == 'Other Function'
|
||||
|
||||
# test removal
|
||||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
resp = resp.click('Other Renamed Function')
|
||||
resp = resp.forms[0].submit('delete')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function-2'])
|
||||
|
||||
# make sure it's not possible to remove the "_receiver" key
|
||||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
|
|
|
@ -950,7 +950,11 @@ class FunctionsDirectory(Directory):
|
|||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
name = form.get_widget('name').parse()
|
||||
slug = '_%s' % misc.simplify(name)
|
||||
base_slug = slug = '_%s' % misc.simplify(name)
|
||||
base_idx = 2
|
||||
while slug in self.workflow.roles:
|
||||
slug = '%s-%s' % (base_slug, base_idx)
|
||||
base_idx += 1
|
||||
self.workflow.roles[slug] = name
|
||||
# go over all existing status and update their visibility
|
||||
# restrictions if necessary
|
||||
|
|
Loading…
Reference in New Issue