core: enforce unique group name on database level
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -103,9 +103,6 @@ class GroupSerializer(ModelSerializer):
|
|||||||
"users": {
|
"users": {
|
||||||
"default": list,
|
"default": list,
|
||||||
},
|
},
|
||||||
# TODO: This field isn't unique on the database which is hard to backport
|
|
||||||
# hence we just validate the uniqueness here
|
|
||||||
"name": {"validators": [UniqueValidator(Group.objects.all())]},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
authentik/core/migrations/0040_alter_group_name.py
Normal file
21
authentik/core/migrations/0040_alter_group_name.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.0.8 on 2024-08-08 12:09
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from authentik.lib.migrations import fallback_names
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentik_core", "0039_source_group_matching_mode_alter_group_name_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(fallback_names("authentik_core", "group", "name")),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="group",
|
||||||
|
name="name",
|
||||||
|
field=models.TextField(unique=True, verbose_name="name"),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -173,7 +173,7 @@ class Group(SerializerModel, AttributesMixin):
|
|||||||
|
|
||||||
group_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
|
group_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
|
||||||
|
|
||||||
name = models.TextField(_("name"))
|
name = models.TextField(verbose_name=_("name"), unique=True)
|
||||||
is_superuser = models.BooleanField(
|
is_superuser = models.BooleanField(
|
||||||
default=False, help_text=_("Users added to this group will be superusers.")
|
default=False, help_text=_("Users added to this group will be superusers.")
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user