Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: GAIA-226 #893

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions anagrafica/migrations/0054_convert_to_crypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2019-10-29 22:14
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
from django_cryptography.fields import encrypt

app_with_model = 'anagrafica'
model_with_column = 'Persona'
column_to_encrypt = 'cognome'
column_field_class = models.CharField
column_attrs = {'max_length': 150}
column_null_status = False
temporary_column = f'temp_{column_to_encrypt}'

def replicate_to_temporary(apps, schema_editor):
Model = apps.get_model(app_with_model, model_with_column)
for row in Model.objects.all():
setattr(row, temporary_column, getattr(row, column_to_encrypt, None))
setattr(row, column_to_encrypt, None)
row.save(update_fields=[temporary_column, column_to_encrypt])

def replicate_to_real(apps, schema_editor):
Model = apps.get_model(app_with_model, model_with_column)
for row in Model.objects.all():
setattr(row, column_to_encrypt, getattr(row, temporary_column))
row.save(update_fields=[column_to_encrypt])

class Migration(migrations.Migration):

dependencies = [
(app_with_model, '0053_merge'),
]

operations = [
# create temporary column
migrations.AddField(
model_name=model_with_column.lower(),
name=temporary_column,
field=column_field_class(
verbose_name=temporary_column, null=True, **column_attrs),
),
# allow null entries in the real column
migrations.AlterField(
model_name=model_with_column.lower(),
name=column_to_encrypt,
field=column_field_class(
verbose_name=column_to_encrypt, null=True, **column_attrs),
),
# push all data from real to temporary
migrations.RunPython(replicate_to_temporary),
# encrypt the real column (still allowing null values)
migrations.AlterField(
model_name=model_with_column.lower(),
name=column_to_encrypt,
field=encrypt(column_field_class(
verbose_name=column_to_encrypt, null=True, **column_attrs)),
),
# push all data from temporary to real (encrypting in the processes)
migrations.RunPython(replicate_to_real),
# remove the temporary column
migrations.RemoveField(
model_name=model_with_column.lower(),
name=temporary_column),
# disallow null values (if applicable)
migrations.AlterField(
model_name=model_with_column.lower(),
name=column_to_encrypt,
field=encrypt(column_field_class(
verbose_name=column_to_encrypt, null=column_null_status,
**column_attrs)),
),
]
3 changes: 2 additions & 1 deletion anagrafica/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import codicefiscale
import phonenumbers
import mptt
from django_cryptography.fields import encrypt
from mptt.querysets import TreeQuerySet
from autoslug import AutoSlugField

Expand Down Expand Up @@ -58,7 +59,7 @@ class Persona(ModelloSemplice, ConMarcaTemporale, ConAllegati, ConVecchioID):

# Informazioni anagrafiche
nome = TitleCharField("Nome", max_length=64, db_index=True)
cognome = TitleCharField("Cognome", max_length=64, db_index=True)
cognome = encrypt(TitleCharField("Cognome", max_length=64, db_index=True))
codice_fiscale = UpperCaseCharField("Codice Fiscale", max_length=16, blank=False,
unique=True, db_index=True, validators=[valida_codice_fiscale,])
data_nascita = models.DateField("Data di nascita", db_index=True, null=True)
Expand Down
20 changes: 20 additions & 0 deletions base/migrations/0020_auto_20191027_2220.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2019-10-27 22:20
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('base', '0019_auto_20190109_1053'),
]

operations = [
migrations.AlterField(
model_name='autorizzazione',
name='destinatario_ruolo',
field=models.CharField(choices=[('PRES', 'Presidenza'), ('COM', 'Commissario'), ('US-GEN', 'Gestione dei Soci'), ('US-TRASF', 'Gestione dei Trasferimenti'), ('US-EST', 'Gestione delle Estensioni'), ('US-FOT', 'Gestione delle Fototessere'), ('US-TIT', 'Gestione dei Titoli nella Sede'), ('US-RIS', 'Gestione delle Riserve'), ('ATT-PART', "Gestione dei Partecipanti all'Attività"), ('CB-PART', 'Gestione dei Partecipanti al Corso Base'), ('US-APP', 'Gestione degli Appartenenti alla Sede'), ('SA-SAN', 'Gestione delle Donazioni Sangue'), ('ASP', 'Autogestione Aspirante')], db_index=True, max_length=16),
),
]
2 changes: 1 addition & 1 deletion config/pgsql.cnf.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[client]
host = db
port = 5432
database = qq
database = postgres
user = postgres
password =
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ xlrd
WeasyPrint
https://github.com/emfcamp/python-barcode/archive/0.7.zip # pyBarcode==0.7
https://github.com/nephila/django-filer/archive/296fa6170a3749532b85ceb033eeae0fb839e9a6.zip
django-cryptography==0.3
19 changes: 19 additions & 0 deletions static_page/migrations/0002_auto_20191027_2220.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2019-10-27 22:20
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('static_page', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='page',
options={'verbose_name': 'Pagina statica', 'verbose_name_plural': 'Pagine statiche'},
),
]
20 changes: 20 additions & 0 deletions ufficio_soci/migrations/0019_auto_20191027_2220.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2019-10-27 22:20
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ufficio_soci', '0018_auto_20190416_1051'),
]

operations = [
migrations.AlterField(
model_name='riduzione',
name='descrizione',
field=models.CharField(help_text='Dicitura riportata sulle ricevute e nella causale della quota', max_length=500),
),
]