Skip to content

Commit 94411d6

Browse files
committed
feat(authorization): exclude default_group RBAC fields from System Settings form/serializer
default_group, default_group_role, and default_group_email_pattern auto- assign new users to a Dojo_Group at login — Dojo_Group_Member is inert under legacy authorization, so these fields drive nothing. Strip them from SystemSettingsForm.Meta and SystemSettingsSerializer.Meta via exclude=, drop the now-orphaned validation in dojo/system_settings/views.py and the queryset-init for default_group_role in the form __init__. The model fields remain so Pro can subclass / runtime-shadow the form & serializer to re-add them.
1 parent 8d3949d commit 94411d6

3 files changed

Lines changed: 10 additions & 29 deletions

File tree

dojo/api_v2/serializers.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,25 +3025,10 @@ class TagSerializer(serializers.Serializer):
30253025
class SystemSettingsSerializer(serializers.ModelSerializer):
30263026
class Meta:
30273027
model = System_Settings
3028-
fields = "__all__"
3029-
3030-
def validate(self, data):
3031-
if self.instance is not None:
3032-
default_group = self.instance.default_group
3033-
default_group_role = self.instance.default_group_role
3034-
3035-
if "default_group" in data:
3036-
default_group = data["default_group"]
3037-
if "default_group_role" in data:
3038-
default_group_role = data["default_group_role"]
3039-
3040-
if (default_group is None and default_group_role is not None) or (
3041-
default_group is not None and default_group_role is None
3042-
):
3043-
msg = "default_group and default_group_role must either both be set or both be empty."
3044-
raise ValidationError(msg)
3045-
3046-
return data
3028+
# default_group / default_group_role / default_group_email_pattern
3029+
# are RBAC-only auto-assignment knobs and inert under legacy
3030+
# authorization. Pro re-adds them via a subclass / runtime hook.
3031+
exclude = ("default_group", "default_group_role", "default_group_email_pattern")
30473032

30483033

30493034
class CeleryStatusSerializer(serializers.Serializer):

dojo/forms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,7 +3145,6 @@ class SystemSettingsForm(forms.ModelForm):
31453145

31463146
def __init__(self, *args, **kwargs):
31473147
super().__init__(*args, **kwargs)
3148-
self.fields["default_group_role"].queryset = get_group_member_roles()
31493148

31503149
self.fields["enable_product_tracking_files"].label = labels.SETTINGS_TRACKED_FILES_ENABLE_LABEL
31513150
self.fields["enable_product_tracking_files"].help_text = labels.SETTINGS_TRACKED_FILES_ENABLE_HELP
@@ -3173,7 +3172,11 @@ def clean(self):
31733172

31743173
class Meta:
31753174
model = System_Settings
3176-
fields = "__all__"
3175+
# default_group / default_group_role / default_group_email_pattern
3176+
# auto-assign new users to a Dojo_Group at login, which is inert
3177+
# under legacy authorization. Pro re-adds these fields via a
3178+
# subclass / runtime hook.
3179+
exclude = ("default_group", "default_group_role", "default_group_email_pattern")
31773180

31783181

31793182
class BenchmarkForm(forms.ModelForm):

dojo/system_settings/views.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ def validate_form(
5454
context: dict,
5555
) -> tuple[HttpRequest, bool]:
5656
if context["form"].is_valid():
57-
if (context["form"].cleaned_data["default_group"] is None and context["form"].cleaned_data["default_group_role"] is not None) or \
58-
(context["form"].cleaned_data["default_group"] is not None and context["form"].cleaned_data["default_group_role"] is None):
59-
messages.add_message(
60-
request,
61-
messages.WARNING,
62-
"Settings cannot be saved: Default group and Default group role must either both be set or both be empty.",
63-
extra_tags="alert-warning")
64-
elif context["form"].cleaned_data["minimum_password_length"] >= context["form"].cleaned_data["maximum_password_length"]:
57+
if context["form"].cleaned_data["minimum_password_length"] >= context["form"].cleaned_data["maximum_password_length"]:
6558
messages.add_message(
6659
request,
6760
messages.WARNING,

0 commit comments

Comments
 (0)