Reformatage #29
3 changed files with 33 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
||||||
from django.apps import apps as global_apps
|
from django.apps import apps as global_apps
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
def forwards(apps, schema_editor):
|
def forwards(apps, schema_editor):
|
||||||
User = apps.get_model('auth', 'User')
|
User = apps.get_model('auth', 'User')
|
||||||
|
@ -11,7 +13,7 @@ def forwards(apps, schema_editor):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
SocialAccount = apps.get_model('socialaccount', 'SocialAccount')
|
SocialAccount = apps.get_model('socialaccount', 'SocialAccount')
|
||||||
EmailAddress = apps.get_model('account', 'EmailAddress')
|
OldEmailAddress = apps.get_model('account', 'EmailAddress')
|
||||||
except LookupError:
|
except LookupError:
|
||||||
# Allauth not installed
|
# Allauth not installed
|
||||||
# Simply create CAS accounts for every profile
|
# Simply create CAS accounts for every profile
|
||||||
|
@ -31,6 +33,11 @@ def forwards(apps, schema_editor):
|
||||||
migrate_user(user)
|
migrate_user(user)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
NewEmailAddress = apps.get_model('simple_email_confirmation',
|
||||||
|
'EmailAddress')
|
||||||
|
from simple_email_confirmation.models import EmailAddressManager
|
||||||
|
|
||||||
# Transfer from allauth to authens
|
# Transfer from allauth to authens
|
||||||
# Assumes usernames have the format <clipper>@<promo>
|
# Assumes usernames have the format <clipper>@<promo>
|
||||||
# Assumes no clashing clipper accounts have ever been found
|
# Assumes no clashing clipper accounts have ever been found
|
||||||
|
@ -42,25 +49,22 @@ def forwards(apps, schema_editor):
|
||||||
is_ens_mail = lambda mail: (
|
is_ens_mail = lambda mail: (
|
||||||
mail is not None and (mail.endswith(".ens.fr") or mail.endswith(".ens.psl.eu")))
|
mail is not None and (mail.endswith(".ens.fr") or mail.endswith(".ens.psl.eu")))
|
||||||
new_conns = []
|
new_conns = []
|
||||||
|
new_mails = []
|
||||||
|
|
||||||
for user in oldusers:
|
for user in oldusers:
|
||||||
# Sanitize mail addresses
|
# Move EmailAddress to new model
|
||||||
addresses = user.emailaddress_set.all()
|
addresses = user.emailaddress_set.all()
|
||||||
if len(addresses) > 0:
|
for addr in addresses:
|
||||||
email = user.email
|
newaddr = NewEmailAddress(
|
||||||
is_email_ens = is_ens_mail(email)
|
user=user, email=addr.email,
|
||||||
for address in addresses:
|
set_at=timezone.now(),
|
||||||
if is_ens_mail(address.email):
|
confirmed_at=(timezone.now() if addr.verified else None),
|
||||||
if email is None:
|
key=EmailAddressManager().generate_key(),
|
||||||
email = address.email
|
)
|
||||||
is_email_ens = True
|
if addr.primary and user.email != addr.email:
|
||||||
continue
|
print("Adresse principale inconsistante",
|
||||||
if address.primary or email is None or is_email_ens:
|
user.email, addr.email)
|
||||||
email = address.email
|
new_mails.append(newaddr)
|
||||||
is_email_ens = False
|
|
||||||
if email != user.email:
|
|
||||||
user.email = email
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
# Create new CASAccount connexion
|
# Create new CASAccount connexion
|
||||||
saccounts = user.socialaccount_set.all()
|
saccounts = user.socialaccount_set.all()
|
||||||
|
@ -71,13 +75,14 @@ def forwards(apps, schema_editor):
|
||||||
saccount = saccounts[0]
|
saccount = saccounts[0]
|
||||||
clipper = saccount.uid
|
clipper = saccount.uid
|
||||||
if "@" not in user.username:
|
if "@" not in user.username:
|
||||||
print(saccount)
|
print(user.username)
|
||||||
continue
|
continue
|
||||||
entrance_year = "20" + saccount.extra_data.get(
|
entrance_year = "20" + saccount.extra_data.get(
|
||||||
"entrance_year", user.username.split("@")[1])
|
"entrance_year", user.username.split("@")[1])
|
||||||
new_conns.append(CASAccount(user=user, cas_login=clipper,
|
new_conns.append(CASAccount(user=user, cas_login=clipper,
|
||||||
entrance_year=int(entrance_year)))
|
entrance_year=int(entrance_year)))
|
||||||
|
|
||||||
|
NewEmailAddress.objects.bulk_create(new_mails)
|
||||||
CASAccount.objects.bulk_create(new_conns)
|
CASAccount.objects.bulk_create(new_conns)
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -91,3 +96,6 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
if global_apps.is_installed('allauth'):
|
if global_apps.is_installed('allauth'):
|
||||||
dependencies.append(('socialaccount', '0003_extra_data_default_dict'))
|
dependencies.append(('socialaccount', '0003_extra_data_default_dict'))
|
||||||
|
|
||||||
|
if global_apps.is_installed('simple_email_confirmation'):
|
||||||
|
dependencies.append(('simple_email_confirmation', '0001_initial'))
|
||||||
|
|
|
@ -35,8 +35,13 @@ INSTALLED_APPS = [
|
||||||
|
|
||||||
'django_elasticsearch_dsl',
|
'django_elasticsearch_dsl',
|
||||||
|
|
||||||
|
#'allauth',
|
||||||
|
#'allauth.account', # Uncomment for transition
|
||||||
|
#'allauth.socialaccount', # Allauth -> Authens
|
||||||
|
|
||||||
'widget_tweaks',
|
'widget_tweaks',
|
||||||
|
|
||||||
|
'simple_email_confirmation',
|
||||||
'authens',
|
'authens',
|
||||||
'tastypie',
|
'tastypie',
|
||||||
'braces',
|
'braces',
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
django==2.2.*
|
django==2.2.*
|
||||||
django-cas-ng==3.5.*
|
|
||||||
django-taggit==0.22.*
|
django-taggit==0.22.*
|
||||||
python-ldap==3.0.*
|
python-ldap==3.0.*
|
||||||
django-tinymce==2.7.*
|
django-tinymce==2.7.*
|
||||||
|
@ -10,3 +9,4 @@ django-tastypie==0.14.*
|
||||||
lxml==4.2.*
|
lxml==4.2.*
|
||||||
django-elasticsearch-dsl==0.4.*
|
django-elasticsearch-dsl==0.4.*
|
||||||
django-allauth-ens==1.1.*
|
django-allauth-ens==1.1.*
|
||||||
|
django-simple-email-confirmation
|
||||||
|
|
Loading…
Reference in a new issue