From f79009be4f24069ea481908c68cd9f3741880951 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 2 Jul 2020 18:42:48 +0200 Subject: [PATCH] agent: save role emails during provisionning (#44754) --- .../common/migrations/0003_role_emails.py | 21 +++++++++++++++++++ hobo/agent/common/models.py | 2 ++ hobo/provisionning/utils.py | 11 ++++++++-- tests_multitenant/test_hobo_notify.py | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 hobo/agent/common/migrations/0003_role_emails.py diff --git a/hobo/agent/common/migrations/0003_role_emails.py b/hobo/agent/common/migrations/0003_role_emails.py new file mode 100644 index 0000000..707e3a4 --- /dev/null +++ b/hobo/agent/common/migrations/0003_role_emails.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2020-07-02 16:39 +from __future__ import unicode_literals + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0002_auto_20160105_1702'), + ] + + operations = [ + migrations.AddField( + model_name='role', + name='emails', + field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), default=[], size=None), + ), + ] diff --git a/hobo/agent/common/models.py b/hobo/agent/common/models.py index 6c3463f..094ee49 100644 --- a/hobo/agent/common/models.py +++ b/hobo/agent/common/models.py @@ -1,3 +1,4 @@ +from django.contrib.postgres.fields import ArrayField from django.db import models from django.contrib.auth.models import Group @@ -6,3 +7,4 @@ class Role(Group): uuid = models.CharField(max_length=32) description = models.TextField(default=u'') details = models.TextField(default=u'') + emails = ArrayField(models.CharField(max_length=128), default=[]) diff --git a/hobo/provisionning/utils.py b/hobo/provisionning/utils.py index 980189c..603a36f 100644 --- a/hobo/provisionning/utils.py +++ b/hobo/provisionning/utils.py @@ -122,9 +122,13 @@ class NotificationProcessing: try: with atomic(): role, created = Role.objects.get_or_create( - name=role_name, defaults={ + name=role_name, + defaults={ 'uuid': o['uuid'], - 'description': o['description']}) + 'description': o['description'], + 'emails': o.get('emails', []), + } + ) except IntegrityError: # Can happen if uuid and name already exist logger.error(u'cannot provision role "%s" (%s)', o['name'], o['uuid']) @@ -143,6 +147,9 @@ class NotificationProcessing: if role.details != o.get('details', u''): role.details = o.get('details', u'') save = True + if role.emails != o.get('emails', []): + role.emails = o.get('emails', []) + save = True if save: try: with atomic(): diff --git a/tests_multitenant/test_hobo_notify.py b/tests_multitenant/test_hobo_notify.py index e366315..57e6847 100644 --- a/tests_multitenant/test_hobo_notify.py +++ b/tests_multitenant/test_hobo_notify.py @@ -48,6 +48,7 @@ def test_hobo_notify_roles(caplog, tenants): u'name': u'Service petite enfance', u'slug': u'service-petite-enfance', u'description': u'Role du service petite enfance %s' % tenant.domain_url, + u'emails': [u'foo@bar.com', u'test@entrouvert.org'], } ] } @@ -59,6 +60,7 @@ def test_hobo_notify_roles(caplog, tenants): assert role.uuid == u'12345' assert role.name == u'Service petite enfance' assert role.description == u'Role du service petite enfance %s' % tenant.domain_url + assert role.emails == [u'foo@bar.com', u'test@entrouvert.org'] # test full provisionning for tenant in tenants: -- 2.20.1