Self hosted FLOSS fitness/workout, nutrition and weight tracker
feat: migrate legacy email verification data to django-allauth
pankaj-basnet34cf522d891b
diff --git a/.gitignore b/.gitignoreindex 713daebbb..acc5370bf 100644--- a/.gitignore+++ b/.gitignore@@ -50,7 +50,6 @@ settings/*_extra.py*.sqlite/CACHE-database.sqlite.orig# Sphinx documentationdocs/_build/@@ -91,6 +90,3 @@ venv-wger# macOS.DS_Store--# feature/2258-migrate-to-django-allauth # TODO: delete this pbc260322-/z-feature-notes-todos\ No newline at end of filediff --git a/wger/core/api/views.py b/wger/core/api/views.pyindex 7e83edd6c..942649e7b 100644--- a/wger/core/api/views.py+++ b/wger/core/api/views.py@@ -136,9 +136,9 @@ class UserProfileViewSet(viewsets.ModelViewSet):request.user.email = data['email']request.user.save()request.user.userprofile.save()- # EmailAddress.objects.add_email(request, request.user, request.user.email)+ # adds new email if it is not already registeredEmailAddress.objects.add_email(request, request.user, request.user.email, confirm=True)- logger.debug('adding email with verified flag and also, sends email confirmation')+ logger.debug('adding new email with verified flag , send verification email')return Response(serializer.data)@@ -358,9 +358,7 @@ class UserAPIRegistrationViewSet(viewsets.ViewSet):user.userprofile.save()token = create_token(user)- # Email the user with the activation link- email_obj = EmailAddress.objects.get_for_user(request.user, request.user.email)- email_obj.send_confirmation(request)+ EmailAddress.objects.add_email(request, request.user, request.user.email, confirm=True)return Response({'message': 'api user successfully registered', 'token': token.key},diff --git a/wger/core/fixtures/test-user-data.json b/wger/core/fixtures/test-user-data.jsonindex cd51b2dd9..022388dd4 100644--- a/wger/core/fixtures/test-user-data.json+++ b/wger/core/fixtures/test-user-data.json@@ -480,7 +480,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": false,"show_comments": false,"show_english_ingredients": false,"user": 1,@@ -512,7 +511,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": false,"show_comments": false,"show_english_ingredients": false,"user": 2,@@ -544,7 +542,6 @@"model": "core.userprofile","fields": {"is_temporary": true,- "email_verified": false,"show_comments": false,"show_english_ingredients": false,"user": 3,@@ -576,7 +573,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 4,@@ -608,7 +604,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": false,"show_comments": false,"show_english_ingredients": false,"user": 5,@@ -640,7 +635,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": false,"show_comments": false,"show_english_ingredients": false,"user": 6,@@ -672,7 +666,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 7,@@ -704,7 +697,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 8,@@ -736,7 +728,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 9,@@ -768,7 +759,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 10,@@ -800,7 +790,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 11,@@ -832,7 +821,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 12,@@ -864,7 +852,6 @@"model": "core.userprofile","fields": {"is_temporary": false,- "email_verified": true,"show_comments": false,"show_english_ingredients": false,"user": 13,@@ -895,7 +882,6 @@"pk": 14,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -927,7 +913,6 @@"pk": 15,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -959,7 +944,6 @@"pk": 16,"model": "core.userprofile","fields": {- "email_verified": false,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -991,7 +975,6 @@"pk": 17,"model": "core.userprofile","fields": {- "email_verified": false,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1023,7 +1006,6 @@"pk": 18,"model": "core.userprofile","fields": {- "email_verified": false,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1055,7 +1037,6 @@"pk": 19,"model": "core.userprofile","fields": {- "email_verified": false,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1087,7 +1068,6 @@"pk": 20,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1119,7 +1099,6 @@"pk": 21,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1151,7 +1130,6 @@"pk": 22,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1183,7 +1161,6 @@"pk": 23,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,@@ -1215,7 +1192,6 @@"pk": 24,"model": "core.userprofile","fields": {- "email_verified": true,"workout_reminder": 20,"height": 180,"show_english_ingredients": false,diff --git a/wger/core/migrations/0022_move_email_verified_to_emailaddress.py b/wger/core/migrations/0022_move_email_verified_to_emailaddress.pynew file mode 100644index 000000000..1de01cd70--- /dev/null+++ b/wger/core/migrations/0022_move_email_verified_to_emailaddress.py@@ -0,0 +1,31 @@+from django.db import migrations++"""+Migration script to copy 'email_verified' column of UserProfile to 'verified' column of EmailAddress table+"""++def migrate_verification_status(apps, schema_editor):+ UserProfile = apps.get_model('core', 'UserProfile')+ EmailAddress = apps.get_model('account', 'EmailAddress')++ for profile in UserProfile.objects.all():+ if profile.user.email:+ # Create allauth table using existing userprofile fields+ EmailAddress.objects.get_or_create(+ user=profile.user,+ email=profile.user.email,+ defaults={+ 'verified': profile.email_verified,+ 'primary': True+ }+ )++class Migration(migrations.Migration):+ dependencies = [+ ('core', '0021_add_unit_type_to_repetitionunit'),+ ('account', '0001_initial'),+ ]++ operations = [+ migrations.RunPython(migrate_verification_status),+ ]\ No newline at end of filediff --git a/wger/core/models/profile.py b/wger/core/models/profile.pyindex e8e609583..f93fae573 100644--- a/wger/core/models/profile.py+++ b/wger/core/models/profile.py@@ -106,14 +106,6 @@ class UserProfile(models.Model):The gym this user belongs to, if any"""- # this field still used in wger\wger\core\templates\user\preferences.html (user.preferences)- email_verified = models.OneToOneField(- EmailAddress,- editable=False,- on_delete=models.CASCADE,- )- """Flag indicating whether the user's email has been verified"""-is_temporary = models.BooleanField(default=False, editable=False)"""Flag to mark a temporary user (demo account)diff --git a/wger/core/templates/account/email/email_confirmation_signup_message.html b/wger/core/templates/account/email_confirm.htmlsimilarity index 88%rename from wger/core/templates/account/email/email_confirmation_signup_message.htmlrename to wger/core/templates/account/email_confirm.htmlindex 5349205a2..9b6bb95bd 100644--- a/wger/core/templates/account/email/email_confirmation_signup_message.html+++ b/wger/core/templates/account/email_confirm.html@@ -8,6 +8,6 @@<p>{% blocktranslate %}Please click <a href="{{ activate_url }}">here</a> to confirm your email{% endblocktranslate %}</p>{# Note: Allauth doesn't pass 'expiry' by default in the same way, we usually rely on settings #}- <p><i>{% translate 'the wger Team' %}</i></p>+ <p><i>{% translate 'the wger Team @2026' %}</i></p></body></html>\ No newline at end of filediff --git a/wger/core/tests/test_user.py b/wger/core/tests/test_user.pyindex d0e061bc9..2adfdac45 100644--- a/wger/core/tests/test_user.py+++ b/wger/core/tests/test_user.py@@ -22,6 +22,9 @@ from django.urls import (reverse_lazy,)+# Third Party+from allauth.account.models import EmailAddress+# wgerfrom wger.core.demo import create_temporary_userfrom wger.core.tests.base_testcase import (@@ -288,7 +291,7 @@ class UserTrustworthinessTestCase(WgerTestCase):# Get a temporary useruser = create_temporary_user(self.request)user.userprofile.is_temporary = False- user.userprofile.email_verified = True+ EmailAddress.objects.create(user=user, email=user.email, verified=True)user.date_joined = datetime.datetime.now()# User does not pass trustworthiness check@@ -302,7 +305,7 @@ class UserTrustworthinessTestCase(WgerTestCase):# Get a temporary useruser = create_temporary_user(self.request)user.userprofile.is_temporary = False- user.userprofile.email_verified = False+ EmailAddress.objects.create(user=user, email=user.email, verified=False)user.date_joined = datetime.datetime.now() - datetime.timedelta(days=30)# User does not pass trustworthiness check@@ -310,29 +313,29 @@ class UserTrustworthinessTestCase(WgerTestCase):def test_is_trustworthy_old_email(self):"""- Tests that old accounts are not considered trustworthy+ Tests that old accounts with verified email are considered trustworthy"""# Get a temporary useruser = create_temporary_user(self.request)user.userprofile.is_temporary = False- user.userprofile.email_verified = True+ EmailAddress.objects.create(user=user, email=user.email, verified=True)user.date_joined = datetime.datetime.now() - datetime.timedelta(days=30)- # User does not pass trustworthiness check+ # User pass trustworthiness checkself.assertTrue(user.userprofile.is_trustworthy)def test_is_trustworthy_admin(self):"""- Tests that superusers are always trustworthy+ Tests that superusers are always trustworthy even if email is unverified"""# Get a temporary useruser = create_temporary_user(self.request)user.is_superuser = Trueuser.userprofile.is_temporary = False- user.userprofile.email_verified = False+ EmailAddress.objects.create(user=user, email=user.email, verified=False)user.date_joined = datetime.datetime.now()- # User does not pass trustworthiness check+ # User pass trustworthiness checkself.assertTrue(user.userprofile.is_trustworthy)diff --git a/wger/urls.py b/wger/urls.pyindex 4edbcd3ea..bd955edf6 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -27,7 +27,6 @@ from django.contrib.sitemaps.views import (from django.urls import path# Third Party-# from django_email_verification import urls as email_urls ## TODO: delete this (((pbc260321)))from drf_spectacular.views import (SpectacularAPIView,SpectacularRedocView,@@ -357,11 +356,8 @@ urlpatterns += ['api/v2/schema/redoc',SpectacularRedocView.as_view(url_name='schema'),name='api-redoc',- ),- # path('email/', include(email_urls)), ## TODO: delete this (((pbc260321)))- # path('accounts/', include('allauth.urls')),+ ),path('email/', include('allauth.account.urls')),- # path('accounts/', include('allauth.account.urls')),]#