From 4babc316ec79bd71506ee9e3cf9b512cc1f32a61 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Fri, 30 Apr 2021 11:44:25 +0200 Subject: [PATCH] Make community auth cooloff message configurable per site --- pgweb/account/admin.py | 3 ++ .../migrations/0008_cooloff_message.py | 35 +++++++++++++++++++ pgweb/account/models.py | 6 ++-- templates/account/communityauth_cooloff.html | 7 ++-- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 pgweb/account/migrations/0008_cooloff_message.py diff --git a/pgweb/account/admin.py b/pgweb/account/admin.py index 90076f71..cb91cbbe 100644 --- a/pgweb/account/admin.py +++ b/pgweb/account/admin.py @@ -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 index 00000000..a5f97511 --- /dev/null +++ b/pgweb/account/migrations/0008_cooloff_message.py @@ -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

) 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), + ] diff --git a/pgweb/account/models.py b/pgweb/account/models.py index 602c0a2c..0244a27e 100644 --- a/pgweb/account/models.py +++ b/pgweb/account/models.py @@ -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

) 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, diff --git a/templates/account/communityauth_cooloff.html b/templates/account/communityauth_cooloff.html index d37ae628..ef53a39f 100644 --- a/templates/account/communityauth_cooloff.html +++ b/templates/account/communityauth_cooloff.html @@ -3,8 +3,9 @@

Community authentication

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. +

+

+{{site.cooloff_message|safe}}

{%endblock%}