hobo_notify: construct new roles using the uuid as their id (#8400)

To prevent any possibility of duplication we choose to use the uuid as
the id of new roles. So when a new Role is built in concurrent threads,
it will get the same id in both threads and so one will overwrite the
pickle written by the other preventing duplication.
This commit is contained in:
Benjamin Dauvergne 2015-09-28 20:39:19 +02:00
parent 475abd5a6c
commit 1e124b0cf2
2 changed files with 12 additions and 7 deletions

View File

@ -114,8 +114,9 @@ def test_process_notification():
assert old_role.details == 'Rôle du service état civil'
assert old_role.emails == ['etat-civil@example.com']
assert old_role.emails_to_members is True
new_role = Role.get_on_index('12345', 'slug')
new_role = Role.get('12345')
assert new_role.name == 'Service enfance'
assert new_role.slug == '12345'
assert new_role.details == 'Rôle du service petite enfance'
assert new_role.emails == ['petite-enfance@example.com']
assert new_role.emails_to_members is False

View File

@ -102,15 +102,19 @@ class CmdHoboNotify(Command):
emails_to_members = o['emails_to_members']
# Find existing role
try:
role = Role.get_on_index(uuid, 'slug')
role = Role.get(uuid)
except KeyError:
try:
role = Role.get_on_index(slug, 'slug')
role = Role.get_on_index(uuid, 'slug')
except KeyError:
# New role
if action != 'provision':
continue
role = Role(name=name)
try:
role = Role.get_on_index(slug, 'slug')
except KeyError:
# New role
if action != 'provision':
continue
role = Role()
role.id = uuid
if action == 'provision':
# Provision/rename
role.name = name