Show secondary emails on the admin form
authorMagnus Hagander <magnus@hagander.net>
Fri, 29 Jan 2021 09:55:14 +0000 (10:55 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 29 Jan 2021 09:55:14 +0000 (10:55 +0100)
pgweb/account/admin.py
pgweb/util/templates/forms/widgets/extra_email_list_widget.html [new file with mode: 0644]

index b47ba90e0256b6f1d265782307deab702c3417f3..0e8210b9bb0a17be99c548cb8e4c762de0c735ff 100644 (file)
@@ -11,7 +11,7 @@ from pgweb.util.widgets import TemplateRenderWidget
 from pgweb.util.db import exec_to_dict
 from pgweb.account.views import OAUTH_PASSWORD_STORE
 
-from .models import CommunityAuthSite, CommunityAuthOrg
+from .models import CommunityAuthSite, CommunityAuthOrg, SecondaryEmail
 
 
 class CommunityAuthSiteAdminForm(forms.ModelForm):
@@ -50,6 +50,7 @@ class CommunityAuthSiteAdmin(admin.ModelAdmin):
 class PGUserChangeForm(UserChangeForm):
     passwordinfo = forms.CharField(label="Password information", required=False)
     logininfo = forms.CharField(label="Community login history", required=False)
+    extraemail = forms.CharField(label="Additional email addresses", required=False)
 
     def __init__(self, *args, **kwargs):
         super(PGUserChangeForm, self).__init__(*args, **kwargs)
@@ -75,6 +76,14 @@ class PGUserChangeForm(UserChangeForm):
                 }),
             })
 
+        self.fields['email'].help_text = "Be EXTREMELY careful when changing an email address! It is almost ALWAYS better to reset the password on the user and have them change it on their own! Sync issues are common!"
+        self.fields['extraemail'].widget = TemplateRenderWidget(
+            template='forms/widgets/extra_email_list_widget.html',
+            context={
+                'emails': SecondaryEmail.objects.filter(user=self.instance).order_by('-confirmed', 'email'),
+            },
+        )
+
     def password_type(self, obj):
         if obj.password == OAUTH_PASSWORD_STORE:
             return "OAuth integrated"
@@ -106,6 +115,8 @@ class PGUserAdmin(UserAdmin):
         )
         if 'passwordinfo' not in fs[0][1]['fields']:
             fs[0][1]['fields'] = list(fs[0][1]['fields']) + ['passwordinfo', ]
+        if 'extraemail' not in fs[1][1]['fields']:
+            fs[1][1]['fields'] = list(fs[1][1]['fields']) + ['extraemail', ]
         return fs
 
 
diff --git a/pgweb/util/templates/forms/widgets/extra_email_list_widget.html b/pgweb/util/templates/forms/widgets/extra_email_list_widget.html
new file mode 100644 (file)
index 0000000..764c366
--- /dev/null
@@ -0,0 +1,4 @@
+<ul>
+{%for e in emails%}  <li>{{e.email}}{%if not e.confirmed%} (NOT CONFIRMED){%endif%}
+{%endfor%}
+</ul>