From 2c680cb3657e45811315222a44630dcd8ae07084 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Tue, 27 Dec 2022 22:42:27 +0100 Subject: [PATCH 1/3] Add default user auth group to registration settings --- bookwyrm/forms/admin.py | 1 + .../0173_default_user_auth_group_setting.py | 34 +++++++++++++++++++ bookwyrm/models/site.py | 4 +++ bookwyrm/templates/settings/registration.html | 17 ++++++++++ 4 files changed, 56 insertions(+) create mode 100644 bookwyrm/migrations/0173_default_user_auth_group_setting.py diff --git a/bookwyrm/forms/admin.py b/bookwyrm/forms/admin.py index acff6cfaa..1ad158119 100644 --- a/bookwyrm/forms/admin.py +++ b/bookwyrm/forms/admin.py @@ -91,6 +91,7 @@ class RegistrationForm(CustomForm): "invite_request_question", "invite_question_text", "require_confirm_email", + "default_user_auth_group", ] widgets = { diff --git a/bookwyrm/migrations/0173_default_user_auth_group_setting.py b/bookwyrm/migrations/0173_default_user_auth_group_setting.py new file mode 100644 index 000000000..1f7e26612 --- /dev/null +++ b/bookwyrm/migrations/0173_default_user_auth_group_setting.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.16 on 2022-12-27 21:34 + +from django.db import migrations, models +import django.db.models.deletion + + +def backfill_sitesettings(apps, schema_editor): + db_alias = schema_editor.connection.alias + group_model = apps.get_model("auth", "Group") + editor_group = group_model.objects.using(db_alias).filter(name="editor").first() + + sitesettings_model = apps.get_model("bookwyrm", "SiteSettings") + sitesettings_model.objects.update(default_user_auth_group=editor_group) + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0175_merge_0173_author_website_0174_merge_20230111_1523"), + ] + + operations = [ + migrations.AddField( + model_name="sitesettings", + name="default_user_auth_group", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.RESTRICT, + to="auth.group", + ), + ), + migrations.RunPython(backfill_sitesettings, migrations.RunPython.noop), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 747565161..e40609f36 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -3,6 +3,7 @@ import datetime from urllib.parse import urljoin import uuid +import django.contrib.auth.models as auth_models from django.core.exceptions import PermissionDenied from django.db import models, IntegrityError from django.dispatch import receiver @@ -70,6 +71,9 @@ class SiteSettings(SiteModel): allow_invite_requests = models.BooleanField(default=True) invite_request_question = models.BooleanField(default=False) require_confirm_email = models.BooleanField(default=True) + default_user_auth_group = models.ForeignKey( + auth_models.Group, null=True, blank=True, on_delete=models.PROTECT + ) invite_question_text = models.CharField( max_length=255, blank=True, default="What is your favourite book?" diff --git a/bookwyrm/templates/settings/registration.html b/bookwyrm/templates/settings/registration.html index 6126f6b92..3ebfff9ae 100644 --- a/bookwyrm/templates/settings/registration.html +++ b/bookwyrm/templates/settings/registration.html @@ -38,6 +38,23 @@ {% trans "Allow registration" %} +
+ +
+ +
+