mirror of
https://github.com/baserow/baserow.git
synced 2026-12-06 17:28:38 +00:00
Merge branch '593-allow-for-group-registrations-while-public-registration-is-closed' into 'develop'
Resolve #593: Allow for group registrations while public registration is closed Closes #593 See merge request bramw/baserow!561
This commit is contained in:
commit
90fb43fb64
10 files changed
+89
-6
No files matched your search
@@ -6,9 +6,10 @@ from baserow.core.models import Settings
|
||||
class SettingsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Settings
|
||||
fields = ("allow_new_signups",)
|
||||
fields = ("allow_new_signups", "allow_signups_via_group_invitations")
|
||||
extra_kwargs = {
|
||||
"allow_new_signups": {"required": False},
|
||||
"allow_signups_via_group_invitations": {"required": False},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,7 +98,9 @@ class CoreHandler:
|
||||
settings_instance = self.get_settings()
|
||||
|
||||
settings_instance = set_allowed_attrs(
|
||||
kwargs, ["allow_new_signups"], settings_instance
|
||||
kwargs,
|
||||
["allow_new_signups", "allow_signups_via_group_invitations"],
|
||||
settings_instance,
|
||||
)
|
||||
|
||||
settings_instance.save()
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.2.6 on 2022-02-19 14:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0013_alter_application_name_squashed_0014_alter_group_name"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="settings",
|
||||
name="allow_signups_via_group_invitations",
|
||||
field=models.BooleanField(
|
||||
default=True,
|
||||
help_text="Indicates whether invited users can create an account "
|
||||
"when signing up, even if allow_new_signups is disabled.",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -63,6 +63,11 @@ class Settings(models.Model):
|
||||
help_text="Indicates whether new users can create a new account when signing "
|
||||
"up.",
|
||||
)
|
||||
allow_signups_via_group_invitations = models.BooleanField(
|
||||
default=True,
|
||||
help_text="Indicates whether invited users can create an account when signing "
|
||||
"up, even if allow_new_signups is disabled.",
|
||||
)
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
|
||||
@@ -103,9 +103,6 @@ class UserHandler:
|
||||
|
||||
core_handler = CoreHandler()
|
||||
|
||||
if not core_handler.get_settings().allow_new_signups:
|
||||
raise DisabledSignupError("Sign up is disabled.")
|
||||
|
||||
email = normalize_email_address(email)
|
||||
|
||||
if User.objects.filter(Q(email=email) | Q(username=email)).exists():
|
||||
@@ -125,6 +122,15 @@ class UserHandler:
|
||||
"user."
|
||||
)
|
||||
|
||||
settings = core_handler.get_settings()
|
||||
allow_new_signups = settings.allow_new_signups
|
||||
allow_signup_for_invited_user = (
|
||||
settings.allow_signups_via_group_invitations
|
||||
and group_invitation is not None
|
||||
)
|
||||
if not (allow_new_signups or allow_signup_for_invited_user):
|
||||
raise DisabledSignupError("Sign up is disabled.")
|
||||
|
||||
user = User(first_name=name, email=email, username=email)
|
||||
|
||||
try:
|
||||
|
||||
@@ -220,6 +220,20 @@ def test_create_user_with_invitation(data_fixture):
|
||||
group_invitation_token=signer.dumps(invitation.id),
|
||||
)
|
||||
|
||||
data_fixture.update_settings(
|
||||
allow_new_signups=False, allow_signups_via_group_invitations=False
|
||||
)
|
||||
with pytest.raises(DisabledSignupError):
|
||||
user_handler.create_user(
|
||||
"Test1",
|
||||
"test0@test.nl",
|
||||
valid_password,
|
||||
group_invitation_token=signer.dumps(invitation.id),
|
||||
)
|
||||
|
||||
data_fixture.update_settings(
|
||||
allow_new_signups=False, allow_signups_via_group_invitations=True
|
||||
)
|
||||
user = user_handler.create_user(
|
||||
"Test1",
|
||||
"test0@test.nl",
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
tools, e.g. to various REST clients.
|
||||
* Added search to gallery views.
|
||||
* Views supporting search are properly updated when a column with a matching default value is added.
|
||||
* Allow for group registrations while public registration is closed
|
||||
* Allow for signup via group invitation while public registration is closed.
|
||||
|
||||
## Released (2022-01-13 1.8.2)
|
||||
|
||||
|
||||
@@ -240,6 +240,8 @@
|
||||
"groupSignupRestrictions": "Signup restrictions",
|
||||
"settingAllowNewAccountsName": "Allow creating new accounts",
|
||||
"settingAllowNewAccountsDescription": "By default, any user visiting your Baserow domain can sign up for a new account.",
|
||||
"settingAllowSignupsViaGroupInvitationsName": "Allow signups via group invitations",
|
||||
"settingAllowSignupsViaGroupInvitationDescription": "Even if the creation of new accounts is disabled, this option permits directly invited users to still create an account.",
|
||||
"enabled": "enabled"
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,28 @@
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!settings.allow_new_signups" class="admin-settings__item">
|
||||
<div class="admin-settings__label">
|
||||
<div class="admin-settings__name">
|
||||
{{ $t('settings.settingAllowSignupsViaGroupInvitationsName') }}
|
||||
</div>
|
||||
<div class="admin-settings__description">
|
||||
{{
|
||||
$t('settings.settingAllowSignupsViaGroupInvitationDescription')
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-settings__control">
|
||||
<SwitchInput
|
||||
:value="settings.allow_signups_via_group_invitations"
|
||||
:large="true"
|
||||
@input="
|
||||
updateSettings({ allow_signups_via_group_invitations: $event })
|
||||
"
|
||||
>{{ $t('settings.enabled') }}</SwitchInput
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</h1>
|
||||
<LangPicker />
|
||||
</div>
|
||||
<template v-if="!settings.allow_new_signups">
|
||||
<template v-if="!isSignupEnabled">
|
||||
<div class="alert alert--simple alert--error alert--has-icon">
|
||||
<div class="alert__icon">
|
||||
<i class="fas fa-exclamation"></i>
|
||||
@@ -54,6 +54,13 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isSignupEnabled() {
|
||||
return (
|
||||
this.settings.allow_new_signups ||
|
||||
(this.settings.allow_signups_via_group_invitations &&
|
||||
this.invitation?.id)
|
||||
)
|
||||
},
|
||||
...mapGetters({
|
||||
settings: 'settings/get',
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user