Skip to content

Commit 845f4c1

Browse files
authored
Merge branch 'main' into feature/CDD-3295-dual-category-chart-interface
2 parents 4a09d4b + 7f00724 commit 845f4c1

64 files changed

Lines changed: 2343 additions & 327 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

auth_content/models/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

cms/auth_content/auth_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
from collections.abc import Callable
3+
4+
from django import forms
5+
6+
from cms.dynamic_content import help_texts
7+
8+
9+
def _create_form_field(
10+
field: dict[str, str | Callable | None], wildcard_id_value=None
11+
) -> forms.CharField:
12+
choices = [
13+
("", field["field_choice_default"]),
14+
]
15+
16+
if field["field_choice_wildcard"]:
17+
choices += [(wildcard_id_value, field["field_choice_wildcard"])]
18+
19+
if field["field_choice_callable"]:
20+
choices += field["field_choice_callable"]()
21+
22+
return forms.CharField(
23+
required=False,
24+
label=field["field_label"],
25+
widget=forms.Select(choices=choices),
26+
help_text=help_texts.NON_PUBLIC_PAGE_REQUIRED,
27+
)
28+
29+
30+
def is_auth_enabled() -> bool:
31+
return str(os.environ.get("AUTH_ENABLED", "")).lower() in {"true", "1"}
File renamed without changes.

auth_content/migrations/0002_alter_permissionset_geography_type_and_more.py renamed to cms/auth_content/migrations/0002_alter_permissionset_geography_type_and_more.py

File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 5.2.13 on 2026-05-22 08:25
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("auth_content", "0002_alter_permissionset_geography_type_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="permissionset",
15+
name="display_name",
16+
field=models.CharField(
17+
blank=True,
18+
help_text="\nThis is an (optional) user readable name for the permission set. If not set, a default autogenerated name will be used.\n",
19+
max_length=255,
20+
null=True,
21+
),
22+
),
23+
migrations.AddConstraint(
24+
model_name="permissionset",
25+
constraint=models.UniqueConstraint(
26+
condition=models.Q(("display_name__isnull", False)),
27+
fields=("display_name",),
28+
name="unique_non_null_display_name",
29+
),
30+
),
31+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from cms.auth_content.models import users
2+
from cms.auth_content.models import permission_sets

auth_content/models/permission_sets.py renamed to cms/auth_content/models/permission_sets.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from collections.abc import Callable
21
from itertools import starmap
32

4-
from django import forms
53
from django.core.exceptions import ValidationError
64
from django.db import models
7-
from wagtail.admin.forms import WagtailAdminModelForm
5+
from wagtail.admin.forms import WagtailAdminPageForm
86
from wagtail.admin.panels import FieldPanel, mark_safe
97

10-
from auth_content.constants import PERMISSION_SET_FIELDS, WILDCARD_ID_VALUE
8+
from cms.auth_content.auth_utils import _create_form_field
9+
from cms.auth_content.constants import PERMISSION_SET_FIELDS, WILDCARD_ID_VALUE
10+
from cms.dynamic_content import help_texts
1111
from cms.metrics_interface.field_choices_callables import (
1212
get_all_geography_names_and_codes,
1313
get_all_geography_type_names_and_ids,
@@ -18,41 +18,14 @@
1818
)
1919

2020

21-
def get_theme_child_map():
22-
"""Returns an object of all parent to child mappings
23-
e.g.
24-
{
25-
infectious_disease: [vaccine_preventable, respiratory ....],
26-
extreme_event: [weather_alert, mortality_report...]
27-
...
28-
}
29-
30-
"""
31-
return {}
32-
33-
34-
def _create_form_field(field: dict[str, str | Callable | None]) -> forms.CharField:
35-
choices = [
36-
("", field["field_choice_default"]),
37-
]
38-
39-
if field["field_choice_wildcard"]:
40-
choices += [(WILDCARD_ID_VALUE, field["field_choice_wildcard"])]
41-
42-
if field["field_choice_callable"]:
43-
choices += field["field_choice_callable"]()
44-
45-
return forms.CharField(
46-
required=True, label=field["field_label"], widget=forms.Select(choices=choices)
47-
)
48-
49-
50-
class PermissionSetForm(WagtailAdminModelForm):
21+
class PermissionSetForm(WagtailAdminPageForm):
5122
def __init__(self, *args, **kwargs):
5223
super().__init__(*args, **kwargs)
5324

5425
for field in PERMISSION_SET_FIELDS:
55-
self.fields[field["field_name"]] = _create_form_field(field)
26+
self.fields[field["field_name"]] = _create_form_field(
27+
field, WILDCARD_ID_VALUE
28+
)
5629

5730
if self.instance and self.instance.pk:
5831
self._initialize_dependent_fields()
@@ -110,6 +83,9 @@ def clean(self):
11083

11184
return cleaned_data
11285

86+
class Media:
87+
js = ["js/permission_set.js"]
88+
11389

11490
class PermissionSet(models.Model):
11591
name = models.CharField(
@@ -118,6 +94,12 @@ class PermissionSet(models.Model):
11894
editable=False,
11995
help_text="Auto-generated display name",
12096
)
97+
display_name = models.CharField(
98+
max_length=255,
99+
blank=True,
100+
null=True,
101+
help_text=help_texts.PERMISSION_SET_DISPLAY_NAME,
102+
)
121103
theme = models.CharField(max_length=255, blank=False, default="")
122104
sub_theme = models.CharField(max_length=255, blank=False, default="")
123105
topic = models.CharField(max_length=255, blank=False, default="")
@@ -133,6 +115,7 @@ def permission_set_details(self):
133115
return mark_safe("<br>".join(parts))
134116

135117
panels = [
118+
FieldPanel("display_name"),
136119
FieldPanel("theme"),
137120
FieldPanel("sub_theme"),
138121
FieldPanel("topic"),
@@ -153,7 +136,12 @@ class Meta:
153136
"geography",
154137
],
155138
name="unique_permission_set",
156-
)
139+
),
140+
models.UniqueConstraint(
141+
fields=["display_name"],
142+
condition=models.Q(display_name__isnull=False),
143+
name="unique_non_null_display_name",
144+
),
157145
]
158146

159147
def save(self, *args, **kwargs):
@@ -241,4 +229,4 @@ def _find_label_in_choices(choices: list[tuple], value: str) -> str:
241229
)
242230

243231
def __str__(self):
244-
return self.name or f"Permission Set {self.id}"
232+
return self.display_name or self.name or f"Permission Set {self.id}"

0 commit comments

Comments
 (0)