Skip to content

Commit 37f0d14

Browse files
committed
Added a new field name_from_draft to Person, to hold the name field equivalent as captured from drafts, in case name has been modified by the user and we're asked to remove that info under GDPR. Added history for Email, and also an origin field to capture from where we got an email address (draft name, username, meeting registration, etc.) Added a log.assertion() to Email.save() in order to ensure we don't create any email without setting origin.
- Legacy-Id: 15126
1 parent 61a1685 commit 37f0d14

3 files changed

Lines changed: 58 additions & 29 deletions

File tree

ietf/person/migrations/0003_auto_20180426_0517.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

ietf/person/migrations/0004_auto_20180427_0646.py renamed to ietf/person/migrations/0003_auto_20180504_1519.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
# -*- coding: utf-8 -*-
2-
# Generated by Django 1.11.12 on 2018-04-27 06:46
2+
# Generated by Django 1.11.12 on 2018-05-04 15:19
33
from __future__ import unicode_literals
44

55
import datetime
66
from django.conf import settings
7+
import django.core.validators
78
from django.db import migrations, models
89
import django.db.models.deletion
10+
import ietf.utils.models
911

1012

1113
class Migration(migrations.Migration):
1214

1315
dependencies = [
1416
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15-
('person', '0003_auto_20180426_0517'),
17+
('person', '0002_auto_20180330_0808'),
1618
]
1719

1820
operations = [
21+
migrations.CreateModel(
22+
name='HistoricalEmail',
23+
fields=[
24+
('address', models.CharField(db_index=True, max_length=64, validators=[django.core.validators.EmailValidator()])),
25+
('time', models.DateTimeField(blank=True, editable=False)),
26+
('primary', models.BooleanField(default=False)),
27+
('origin', models.CharField(default=b'', editable=False, max_length=150)),
28+
('active', models.BooleanField(default=True)),
29+
('history_id', models.AutoField(primary_key=True, serialize=False)),
30+
('history_date', models.DateTimeField()),
31+
('history_change_reason', models.CharField(max_length=100, null=True)),
32+
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
33+
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
34+
],
35+
options={
36+
'ordering': ('-history_date', '-history_id'),
37+
'get_latest_by': 'history_date',
38+
'verbose_name': 'historical email',
39+
},
40+
),
1941
migrations.CreateModel(
2042
name='HistoricalPerson',
2143
fields=[
@@ -24,10 +46,10 @@ class Migration(migrations.Migration):
2446
('name', models.CharField(db_index=True, help_text=b'Preferred form of name.', max_length=255, verbose_name=b'Full Name (Unicode)')),
2547
('ascii', models.CharField(help_text=b'Name as rendered in ASCII (Latin, unaccented) characters.', max_length=255, verbose_name=b'Full Name (ASCII)')),
2648
('ascii_short', models.CharField(blank=True, help_text=b'Example: A. Nonymous. Fill in this with initials and surname only if taking the initials and surname of the ASCII name above produces an incorrect initials-only form. (Blank is OK).', max_length=32, null=True, verbose_name=b'Abbreviated Name (ASCII)')),
27-
('affiliation', models.CharField(blank=True, help_text=b'Employer, university, sponsor, etc.', max_length=255)),
2849
('biography', models.TextField(blank=True, help_text=b'Short biography for use on leadership pages. Use plain text or reStructuredText markup.')),
2950
('photo', models.TextField(blank=True, default=None, max_length=100)),
3051
('photo_thumb', models.TextField(blank=True, default=None, max_length=100)),
52+
('name_from_draft', models.CharField(editable=False, help_text=b'Name as found in a draft submission.', max_length=255, null=True, verbose_name=b'Full Name (from submission)')),
3153
('history_id', models.AutoField(primary_key=True, serialize=False)),
3254
('history_date', models.DateTimeField()),
3355
('history_change_reason', models.CharField(max_length=100, null=True)),
@@ -49,7 +71,30 @@ class Migration(migrations.Migration):
4971
model_name='personhistory',
5072
name='user',
5173
),
74+
migrations.RemoveField(
75+
model_name='person',
76+
name='address',
77+
),
78+
migrations.RemoveField(
79+
model_name='person',
80+
name='affiliation',
81+
),
82+
migrations.AddField(
83+
model_name='email',
84+
name='origin',
85+
field=models.CharField(default=b'', editable=False, max_length=150),
86+
),
87+
migrations.AddField(
88+
model_name='person',
89+
name='name_from_draft',
90+
field=models.CharField(editable=False, help_text=b'Name as found in a draft submission.', max_length=255, null=True, verbose_name=b'Full Name (from submission)'),
91+
),
5292
migrations.DeleteModel(
5393
name='PersonHistory',
5494
),
95+
migrations.AddField(
96+
model_name='historicalemail',
97+
name='person',
98+
field=ietf.utils.models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='person.Person'),
99+
),
55100
]

ietf/person/models.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ietf.utils.storage import NoLocationMigrationFileSystemStorage
2626
from ietf.utils.mail import formataddr
2727
from ietf.person.name import unidecode_name
28+
from ietf.utils import log
2829
from ietf.utils.models import ForeignKey, OneToOneField
2930

3031

@@ -39,10 +40,10 @@ class Person(models.Model):
3940
ascii = models.CharField("Full Name (ASCII)", max_length=255, help_text="Name as rendered in ASCII (Latin, unaccented) characters.")
4041
# The short ascii-form of the name. Also in alias table if non-null
4142
ascii_short = models.CharField("Abbreviated Name (ASCII)", max_length=32, null=True, blank=True, help_text="Example: A. Nonymous. Fill in this with initials and surname only if taking the initials and surname of the ASCII name above produces an incorrect initials-only form. (Blank is OK).")
42-
affiliation = models.CharField(max_length=255, blank=True, help_text="Employer, university, sponsor, etc.")
4343
biography = models.TextField(blank=True, help_text="Short biography for use on leadership pages. Use plain text or reStructuredText markup.")
4444
photo = models.ImageField(storage=NoLocationMigrationFileSystemStorage(), upload_to=settings.PHOTOS_DIRNAME, blank=True, default=None)
4545
photo_thumb = models.ImageField(storage=NoLocationMigrationFileSystemStorage(), upload_to=settings.PHOTOS_DIRNAME, blank=True, default=None)
46+
name_from_draft = models.CharField("Full Name (from submission)", null=True, max_length=255, editable=False, help_text="Name as found in a draft submission.")
4647

4748
def __unicode__(self):
4849
return self.plain_name()
@@ -195,7 +196,6 @@ def json_dict(self, hostscheme):
195196
ct1['href'] = urljoin(hostscheme, self.json_url())
196197
ct1['name'] = self.name
197198
ct1['ascii'] = self.ascii
198-
ct1['affiliation']= self.affiliation
199199
return ct1
200200

201201
class Alias(models.Model):
@@ -226,12 +226,15 @@ class Meta:
226226
verbose_name_plural = "Aliases"
227227

228228
class Email(models.Model):
229+
history = HistoricalRecords()
229230
address = models.CharField(max_length=64, primary_key=True, validators=[validate_email])
230231
person = ForeignKey(Person, null=True)
231232
time = models.DateTimeField(auto_now_add=True)
232233
primary = models.BooleanField(default=False)
234+
origin = models.CharField(max_length=150, default='', editable=False) # User.username or Document.name
233235
active = models.BooleanField(default=True) # Old email addresses are *not* purged, as history
234-
# information points to persons through these
236+
# information points to persons through these
237+
235238
def __unicode__(self):
236239
return self.address or "Email object with id: %s"%self.pk
237240

@@ -275,6 +278,10 @@ def email_address(self):
275278
return
276279
return self.address
277280

281+
def save(self, *args, **kwargs):
282+
if not self.origin:
283+
log.assertion('self.origin')
284+
super(Email, self).save(*args, **kwargs)
278285

279286
# "{key.id}{salt}{hash}
280287
KEY_STRUCT = "i12s32s"

0 commit comments

Comments
 (0)