Make community auth cooloff message configurable per site
authorMagnus Hagander <magnus@hagander.net>
Fri, 30 Apr 2021 09:44:25 +0000 (11:44 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 30 Apr 2021 09:46:58 +0000 (11:46 +0200)
pgweb/account/admin.py
pgweb/account/migrations/0008_cooloff_message.py [new file with mode: 0644]
pgweb/account/models.py
templates/account/communityauth_cooloff.html

index 90076f71a9bca3fb125d9f8b10e0364361fad59d..cb91cbbe9826c3197bdeba5e9c9863a2de98ecc9 100644 (file)
@@ -40,6 +40,9 @@ class CommunityAuthSiteAdminForm(forms.ModelForm):
         if d.get('push_ssh', False) and not d.get('push_changes', False):
             self.add_error('push_ssh', 'SSH changes can only be pushed if general change push is enabled')
 
+        if d.get('cooloff_hours', 0) > 0 and not d.get('cooloff_message', ''):
+            self.add_error('cooloff_message', 'Cooloff message must be specified if cooloff period is')
+
         return d
 
 
diff --git a/pgweb/account/migrations/0008_cooloff_message.py b/pgweb/account/migrations/0008_cooloff_message.py
new file mode 100644 (file)
index 0000000..a5f9751
--- /dev/null
@@ -0,0 +1,35 @@
+# Generated by Django 2.2.11 on 2021-04-30 09:21
+
+from django.db import migrations, models
+
+
+def set_message(apps, schema_editor):
+    m = apps.get_model("account", "CommunityAuthSite")
+    m.objects.filter(cooloff_hours__gt=0) \
+             .update(cooloff_message='Please try again later, or contact the postgresql.org webmasters if you have an urgent need to log in.')
+
+
+def unset_message(apps, schema_editor):
+    # We're going to drop the column, so nothing to do
+    return
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('account', '0007_all_emails_view'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='communityauthsite',
+            name='cooloff_message',
+            field=models.TextField(blank=True, help_text='Message (HTML format allowed, will be wrapped in <P>) to show users who have not passed the cool-off period'),
+        ),
+        migrations.AlterField(
+            model_name='communityauthsite',
+            name='cooloff_hours',
+            field=models.PositiveIntegerField(default=0, help_text='Number of hours a user must have existed in the systems before allowed to log in to this site'),
+        ),
+        migrations.RunPython(set_message, unset_message),
+    ]
index 602c0a2c94541daa76c6a65e9432aa3cd04cedf6..0244a27e2ca25c155d116cd9a741b91a72107d9b 100644 (file)
@@ -20,8 +20,10 @@ class CommunityAuthSite(models.Model):
                                 help_text="Use tools/communityauth/generate_cryptkey.py to create a key")
     comment = models.TextField(null=False, blank=True)
     org = models.ForeignKey(CommunityAuthOrg, null=False, blank=False, on_delete=models.CASCADE)
-    cooloff_hours = models.IntegerField(null=False, blank=False, default=0,
-                                        help_text="Number of hours a user must have existed in the systems before allowed to log in to this site")
+    cooloff_hours = models.PositiveIntegerField(null=False, blank=False, default=0,
+                                                help_text="Number of hours a user must have existed in the systems before allowed to log in to this site")
+    cooloff_message = models.TextField(null=False, blank=True,
+                                       help_text="Message (HTML format allowed, will be wrapped in <P>) to show users who have not passed the cool-off period")
     push_changes = models.BooleanField(null=False, blank=False, default=False,
                                        help_text="Supports receiving http POSTs with changes to accounts")
     push_ssh = models.BooleanField(null=False, blank=False, default=False,
index d37ae62880239532dfbddddcf2e2df1fe0c68c0b..ef53a39f4cd7fd72092fe428b49b4292eeecd1d2 100644 (file)
@@ -3,8 +3,9 @@
 <h1>Community authentication</h1>
 <p>
 The site you are trying to log in to ({{site.name}}) requires a
-cool-off period between account creation and logging in. Please
-try again later, or contact the postgresql.org webmasters if you
-have an urgent need to log in.
+cool-off period between account creation and logging in.
+</p>
+<p>
+{{site.cooloff_message|safe}}
 </p>
 {%endblock%}