Make community auth cooloff message configurable per site

This commit is contained in:
Magnus Hagander
2021-04-30 11:44:25 +02:00
parent 2751223f94
commit 4babc316ec
4 changed files with 46 additions and 5 deletions

View 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

View File

@ -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),
]

View 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,

View 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%}