0001-agent-save-role-emails-during-provisionning-44754.patch
hobo/agent/common/migrations/0003_role_emails.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-07-02 16:39 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
import django.contrib.postgres.fields |
|
6 |
from django.db import migrations, models |
|
7 | ||
8 | ||
9 |
class Migration(migrations.Migration): |
|
10 | ||
11 |
dependencies = [ |
|
12 |
('common', '0002_auto_20160105_1702'), |
|
13 |
] |
|
14 | ||
15 |
operations = [ |
|
16 |
migrations.AddField( |
|
17 |
model_name='role', |
|
18 |
name='emails', |
|
19 |
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), default=[], size=None), |
|
20 |
), |
|
21 |
] |
hobo/agent/common/models.py | ||
---|---|---|
1 |
from django.contrib.postgres.fields import ArrayField |
|
1 | 2 |
from django.db import models |
2 | 3 | |
3 | 4 |
from django.contrib.auth.models import Group |
... | ... | |
6 | 7 |
uuid = models.CharField(max_length=32) |
7 | 8 |
description = models.TextField(default=u'') |
8 | 9 |
details = models.TextField(default=u'') |
10 |
emails = ArrayField(models.CharField(max_length=128), default=[]) |
hobo/provisionning/utils.py | ||
---|---|---|
122 | 122 |
try: |
123 | 123 |
with atomic(): |
124 | 124 |
role, created = Role.objects.get_or_create( |
125 |
name=role_name, defaults={ |
|
125 |
name=role_name, |
|
126 |
defaults={ |
|
126 | 127 |
'uuid': o['uuid'], |
127 |
'description': o['description']}) |
|
128 |
'description': o['description'], |
|
129 |
'emails': o['emails'], |
|
130 |
} |
|
131 |
) |
|
128 | 132 |
except IntegrityError: |
129 | 133 |
# Can happen if uuid and name already exist |
130 | 134 |
logger.error(u'cannot provision role "%s" (%s)', o['name'], o['uuid']) |
... | ... | |
143 | 147 |
if role.details != o.get('details', u''): |
144 | 148 |
role.details = o.get('details', u'') |
145 | 149 |
save = True |
150 |
if role.emails != o['emails']: |
|
151 |
role.emails = o['emails'] |
|
152 |
save = True |
|
146 | 153 |
if save: |
147 | 154 |
try: |
148 | 155 |
with atomic(): |
149 |
- |