Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
e2832dd
CDD-3175: Initial Commit
kathryn-dale Mar 12, 2026
fa872b3
Create initial permission set
kathryn-dale Mar 12, 2026
f2876dc
create dropdown
kathryn-dale Mar 12, 2026
263420b
Update auth_content migration
kathryn-dale Mar 12, 2026
6353029
Add conditional sub_theme dropdown
kathryn-dale Mar 13, 2026
46a9748
Update migration file and tidy up child_theme.js
kathryn-dale Mar 13, 2026
d353ec4
CDD-3116 Add more search_fields to common/composite/dashboard/topic m…
Feb 17, 2026
94d8eed
pip: (deps): bump python-dotenv from 1.2.1 to 1.2.2
dependabot[bot] Mar 10, 2026
52fa1a8
Testing dummy secret with gitleaks
abdihakim92x1 Feb 25, 2026
cc9481d
Testing dummy secret with gitleaks
abdihakim92x1 Feb 25, 2026
2cba565
Added secret scan to the existing action.yaml
abdihakim92x1 Feb 25, 2026
d6eef0e
Changed run to pull request as well
abdihakim92x1 Feb 25, 2026
e9114c8
Replaced gitleaks with official marketplace version
abdihakim92x1 Feb 27, 2026
c097e63
Reverted to script installation of gitleaks
abdihakim92x1 Mar 4, 2026
54c9001
Changed job name
abdihakim92x1 Mar 4, 2026
b2d74c9
Changed ubuntu version
abdihakim92x1 Mar 5, 2026
d295227
Changed x64 to arm64
abdihakim92x1 Mar 5, 2026
eb7d6ea
Using official gitleaks action
abdihakim92x1 Mar 6, 2026
d6187e6
Updated ubuntu version
abdihakim92x1 Mar 6, 2026
e600e17
Git License added
abdihakim92x1 Mar 10, 2026
e4c7cb2
Gitleaks arg removed
abdihakim92x1 Mar 10, 2026
16ccfa1
Aligned with documentation
abdihakim92x1 Mar 11, 2026
a67a300
Skip gitleaks action for dependabot
abdihakim92x1 Mar 13, 2026
89525e8
pip dev: (deps-dev): bump black from 26.3.0 to 26.3.1
dependabot[bot] Mar 12, 2026
29c4013
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Mar 17, 2026
98d47ae
CDD-3175: populate the Topic dropdown
luketowell Mar 17, 2026
3c0a0b7
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Mar 18, 2026
2c01f79
Wire up geographyType model
luketowell Mar 18, 2026
96526f5
Update theme functionality to pull available themes from the db via t…
luketowell Mar 19, 2026
7446975
CDD-3175: added endpoints for retrieving subtheme/topics/metrics and …
luketowell Mar 20, 2026
e4bc21a
Update the model and the permission_set javascript when handling wild…
luketowell Mar 20, 2026
9c7ca66
Update to add serializer to handle request and response for subthemes…
luketowell Mar 20, 2026
5b2f370
CDD-3175: updated the JS to add wildcard and empty object options
luketowell Mar 20, 2026
b362c43
CDD-3175: Updated the topics and metrics endpoints to retrieve data f…
luketowell Mar 20, 2026
fd83953
CDD-3175: wired up the logic for selecting geography types
luketowell Mar 20, 2026
6d37e21
CDD-3175: update permission set for geographies
luketowell Mar 23, 2026
ad8123c
CDD-3175: updates for limiting the creation of duplicate permission sets
luketowell Mar 23, 2026
60d108f
CDD-3175: updates for handling the naming of permission sets
luketowell Mar 23, 2026
57c71cb
CDD-3085: updated validations and wildcard functionality
luketowell Mar 23, 2026
085bf1c
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Mar 24, 2026
aec0c5c
CDD-3175: update migrations and add tidy up javascript and validation
luketowell Mar 24, 2026
d679e8d
CDD-3175: remove console logs from javascript
luketowell Mar 24, 2026
9875ae4
CDD-3175: Update PermissionSet model
luketowell Mar 24, 2026
5be1690
CDD-3175: Update wagtail hooks
luketowell Mar 24, 2026
dc45208
CDD-3175: remove print statements and tidy up field_choice_callables
luketowell Mar 24, 2026
8178091
CDD-3175: Update method descriptions
luketowell Mar 24, 2026
cc5bd4a
CDD-3175: tidied up the geography serializer
luketowell Mar 24, 2026
e07efdf
CDD-3175: formatting
luketowell Mar 24, 2026
6995b9e
Update documentation
luketowell Mar 24, 2026
843f340
CDD-3175: linting
luketowell Mar 25, 2026
7b91090
CDD-3175: tests
luketowell Mar 25, 2026
3ee2a70
CDD-3176: Add initial model
kathryn-dale Mar 26, 2026
6017395
CDD-3175: Initial Commit
kathryn-dale Mar 12, 2026
0b2c039
Create initial permission set
kathryn-dale Mar 12, 2026
527b15f
Add conditional sub_theme dropdown
kathryn-dale Mar 13, 2026
058e529
Update migration file and tidy up child_theme.js
kathryn-dale Mar 13, 2026
d0041f1
pip: (deps): bump python-dotenv from 1.2.1 to 1.2.2
dependabot[bot] Mar 10, 2026
db3eed6
Testing dummy secret with gitleaks
abdihakim92x1 Feb 25, 2026
2edb76e
Testing dummy secret with gitleaks
abdihakim92x1 Feb 25, 2026
d818ec1
Added secret scan to the existing action.yaml
abdihakim92x1 Feb 25, 2026
7082593
Reverted to script installation of gitleaks
abdihakim92x1 Mar 4, 2026
1a7b248
Changed job name
abdihakim92x1 Mar 4, 2026
9938b77
Changed ubuntu version
abdihakim92x1 Mar 5, 2026
f62bbad
Using official gitleaks action
abdihakim92x1 Mar 6, 2026
ea9e6e4
Updated ubuntu version
abdihakim92x1 Mar 6, 2026
f820650
Gitleaks arg removed
abdihakim92x1 Mar 10, 2026
ed11e83
CDD-3175: populate the Topic dropdown
luketowell Mar 17, 2026
d38cc2d
Update theme functionality to pull available themes from the db via t…
luketowell Mar 19, 2026
2b2bfa6
Update to add serializer to handle request and response for subthemes…
luketowell Mar 20, 2026
a69ab5e
CDD-3175: updated the JS to add wildcard and empty object options
luketowell Mar 20, 2026
b09b509
CDD-3175: Updated the topics and metrics endpoints to retrieve data f…
luketowell Mar 20, 2026
817dfb8
CDD-3085: updated validations and wildcard functionality
luketowell Mar 23, 2026
c3dec5d
WIP: Separate model files and create permission set block
kathryn-dale Mar 26, 2026
d823c58
add name back in
kathryn-dale Mar 26, 2026
e47447a
working draft
kathryn-dale Mar 30, 2026
2cb5fc9
Merge branch 'task/CDD-3175-permission-sets-cms' into task/CDD-3176-a…
kathryn-dale Mar 30, 2026
a9032f2
Split models into two files
kathryn-dale Mar 30, 2026
6b1c4d3
CDD-3175: removed duplicate functionality
luketowell Mar 30, 2026
2552243
CDD-3175: refactored naming of endpoints
luketowell Mar 30, 2026
1f306f6
Add unit testing
kathryn-dale Mar 30, 2026
59d2dcd
CDD-3175: update to fix wildcard selection
luketowell Mar 31, 2026
c3436a5
Simplified version
kathryn-dale Mar 31, 2026
a8eb2be
remove old code
kathryn-dale Mar 31, 2026
780a5a6
Remove old code
kathryn-dale Mar 31, 2026
8b15e75
CDD-3175: update for PR comments
luketowell Mar 31, 2026
c05163f
CDD-3175: update for PR comments
luketowell Apr 1, 2026
beebd08
remove old file
kathryn-dale Apr 1, 2026
1c16ace
CDD-3175: Update method annotation
luketowell Apr 2, 2026
0b66789
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Apr 2, 2026
4a3c3b7
CDD-3175: Update method annotation
luketowell Apr 2, 2026
ef470ee
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Apr 2, 2026
4deebb3
Update checkboxes
kathryn-dale Apr 2, 2026
dc3724a
Merge branch 'task/CDD-3175-permission-sets-cms' into task/CDD-3176-a…
kathryn-dale Apr 2, 2026
bccf9d8
Linting fixes
kathryn-dale Apr 2, 2026
8d5787c
remove merge issue
kathryn-dale Apr 2, 2026
cca3cf3
linting things
kathryn-dale Apr 2, 2026
e1502f5
CDD-3175: Update urls for permission set endpoints
luketowell Apr 2, 2026
0c73acd
Merge branch 'main' into task/CDD-3175-permission-sets-cms
luketowell Apr 7, 2026
f07060c
Merge branch 'task/CDD-3175-permission-sets-cms' into task/CDD-3176-a…
luketowell Apr 7, 2026
58c3fa7
CDD-3176: remove duplicated tests
luketowell Apr 7, 2026
7251853
CDD-3172: Update to add the functionality for retrieving user permiss…
luketowell Apr 7, 2026
34d6b85
CDD-3172: linting
luketowell Apr 7, 2026
7577419
CDD-3175: Update to add ability to get by id and to create initial pe…
luketowell Apr 9, 2026
7848563
CDD-3175: add group by functionality
luketowell Apr 10, 2026
f37ee3e
CDD-3172: small refactor of permission_hierarchy and users and topics
luketowell Apr 10, 2026
b77e195
Remove testing changes to truncated_dataset
luketowell Apr 13, 2026
5930ec6
Remove group by geography
luketowell Apr 14, 2026
0ac42ee
refactor permission grouping to group by id rather than name
luketowell Apr 14, 2026
67f8ab6
CDD-3172: linting
luketowell Apr 15, 2026
e460266
Merge branch 'main' into task/CDD-3172-permission-hierarchy
luketowell Apr 15, 2026
d9c4998
CDD-3172: tests
luketowell Apr 16, 2026
15627ab
CDD-3172: tests
luketowell Apr 16, 2026
2ad0df8
CDD-3172: tests and refactoring
luketowell Apr 20, 2026
cfcd612
Merge branch 'main' into task/CDD-3172-permission-hierarchy
luketowell Apr 20, 2026
fef62a8
Merge branch 'main' into task/CDD-3172-permission-hierarchy
luketowell Apr 22, 2026
862e777
CDD-3172: Update response format
luketowell Apr 20, 2026
bcf067d
sonar feedback: update based on sonarqube output
luketowell Apr 22, 2026
8838794
sonar feedback: update based on sonarqube output
luketowell Apr 22, 2026
c023a71
Linting
luketowell Apr 22, 2026
26363e2
CDD-3171: Update permission set form now it's a page not a snippet
kathryn-dale Apr 28, 2026
d0540cb
Update topic page to include theme/subtheme/topic fields
kathryn-dale Apr 28, 2026
e35df35
WIP: filter getPages based on is_public field
kathryn-dale Apr 28, 2026
c8578bc
Move auth content underneath CMS
kathryn-dale Apr 28, 2026
654b337
Expose themes/subthemes/topics on topic and metric doc child pages
kathryn-dale Apr 28, 2026
0674583
Merge branch 'main' into task/CDD-3172-permission-hierarchy
luketowell Apr 29, 2026
c1dd464
CDD-3172: move class for blocks
luketowell Apr 29, 2026
97160a7
WIP: Add theme/subtheme/topic to pages
kathryn-dale Apr 29, 2026
372eadd
linting and permission set url changes
luketowell Apr 29, 2026
710a865
CDD-3172: refactored naming of geography method and updated the tests…
luketowell Apr 29, 2026
fb29a38
CDD-3172: updated test to better name test and updated permission hie…
luketowell Apr 29, 2026
f588ee2
CDD-2172: Add examples for each of the potential responses for get pe…
luketowell Apr 30, 2026
0584f99
CDD-2172: linting
luketowell Apr 30, 2026
5b78d1e
Merge branch 'main' into task/CDD-3172-permission-hierarchy
luketowell Apr 30, 2026
8bc0bbd
CDD-3147: Update Cognito User for permission sets
mattjreynolds Apr 17, 2026
2a79ee3
CDD-3147: Improve logging of JWT
mattjreynolds Apr 22, 2026
2ab8c2e
CDD-3147: Update readme for using JWT locally
mattjreynolds Apr 30, 2026
5f7d315
CDD-3147: Update readme for using JWT locally
mattjreynolds Apr 30, 2026
3f999f1
CDD-3119 Add a new SimpleMenu model.
Mar 19, 2026
685ab94
CDD-3119 Add panels attribute to SimpleMenu model.
Apr 7, 2026
b10c77b
CDD-3119 Beef up the SimpleMenu serializer tests.
Apr 9, 2026
5fefbfe
CDD-3232 Update chart response styles.
Apr 13, 2026
f34051e
pip dev: (deps-dev): bump pre-commit from 4.5.1 to 4.6.0
dependabot[bot] Apr 27, 2026
8a16873
pip: (deps): bump idna from 3.11 to 3.12
dependabot[bot] Apr 27, 2026
a613fbf
pip dev: (deps-dev): bump gitpython from 3.1.46 to 3.1.47
dependabot[bot] Apr 27, 2026
f637ec3
pip: (deps): bump click from 8.3.2 to 8.3.3
dependabot[bot] Apr 28, 2026
7342f33
pip: (deps): bump psycopg2-binary from 2.9.10 to 2.9.12
dependabot[bot] Apr 28, 2026
80f8a7e
pip: (deps): bump pydantic from 2.13.2 to 2.13.3
dependabot[bot] Apr 28, 2026
8e3cef0
build: remove simplejson dependency
jrdh Apr 28, 2026
de89d0b
CDD-3313: Add topic page link to headline metrics card (#3151)
tushortz Apr 29, 2026
c53721c
pip: (deps): bump idna from 3.12 to 3.13
dependabot[bot] Apr 29, 2026
b336a45
topics: add HIV topic
aidan Apr 24, 2026
5f9a0d1
CDD-3087: new CMS page for logged-out functionality (#3163)
luketowell Apr 30, 2026
f21867e
pip: (deps): bump filelock from 3.28.0 to 3.29.0
dependabot[bot] Apr 29, 2026
21ec84a
Merge branch 'task/CDD-3147-update-cognito-user-for-permission-sets' …
kathryn-dale Apr 30, 2026
fc0366c
WIP: pseudo code / note form of solution
kathryn-dale Apr 30, 2026
168dd31
WIP: filter pages on permission sets
kathryn-dale May 1, 2026
112e4c7
Permission check updates and form handling
itsthatianguy May 5, 2026
6069ae6
WIP: Fix comparison function
kathryn-dale May 6, 2026
7891edf
Finish getPages endpoint
kathryn-dale May 6, 2026
828301a
CDD-3172: Remove permission_sets from CMS API
mattjreynolds May 7, 2026
0152d03
CDD-3172: Update docstring
mattjreynolds May 7, 2026
9d3e9b4
remove redundant code
kathryn-dale May 7, 2026
8cf08b2
Merge branch 'main' into task/CDD-3172-permission-hierarchy
mattjreynolds May 7, 2026
230a893
fixes for existing unit tests
itsthatianguy May 7, 2026
dbbd0fb
Merge branch 'task/CDD-3172-permission-hierarchy' into task/CDD-3171-…
kathryn-dale May 7, 2026
e0030e5
Update imports
kathryn-dale May 7, 2026
d021645
add endpoint back in for testing
kathryn-dale May 8, 2026
8f67ea2
fix import
kathryn-dale May 8, 2026
36e5f18
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 8, 2026
69afe07
New tests, and fixes and updates to existing tests
itsthatianguy May 8, 2026
aee34c0
Naming fixes
itsthatianguy May 8, 2026
89025af
test coverage
itsthatianguy May 12, 2026
2806c50
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 19, 2026
ccd0cc1
CDD-3171: Tweaks
kathryn-dale May 19, 2026
c6ce9c2
CDD-3171: Add display name to permission sets
kathryn-dale May 19, 2026
b186842
remove log file
kathryn-dale May 19, 2026
4e83f82
Fix js file
kathryn-dale May 19, 2026
d7883c6
Linting
kathryn-dale May 19, 2026
376c782
Update migration
kathryn-dale May 19, 2026
c63e778
refactor for sonarqube checks
kathryn-dale May 19, 2026
27fc8d9
Fix constraints on permission sets
kathryn-dale May 19, 2026
e328d6d
update unit tests
kathryn-dale May 19, 2026
35802ee
fix allowed_pages overwrite
kathryn-dale May 20, 2026
834cfdc
Fix unit test
kathryn-dale May 20, 2026
6e130fb
Fix test
kathryn-dale May 20, 2026
6de2df7
linting
kathryn-dale May 20, 2026
222acd2
CDD-3171: Move permission_set.js insert to Media class
mattjreynolds May 20, 2026
5219d16
CDD-3171: Add ignores for importlint
mattjreynolds May 22, 2026
16540f5
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
mattjreynolds May 22, 2026
5320494
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 22, 2026
f55076e
Update architectural constraints
kathryn-dale May 22, 2026
39226d0
linting
kathryn-dale May 22, 2026
23cec20
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 26, 2026
ab3aad9
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
mattjreynolds May 26, 2026
084949c
Update wildcard value in viewsets
kathryn-dale May 27, 2026
6b88ea7
Update test
kathryn-dale May 27, 2026
147916a
remove comment
kathryn-dale May 27, 2026
ebc6fcd
Update import
kathryn-dale May 27, 2026
efb3ff8
fix test name
kathryn-dale May 27, 2026
7a1f09d
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 27, 2026
9d66874
linting
mattjreynolds May 27, 2026
a23fd65
combine imports
mattjreynolds May 27, 2026
fd5306e
refactor for simplicity
kathryn-dale May 27, 2026
81e3678
linting
kathryn-dale May 27, 2026
8708ada
CDD-3173: prototype authorization curl call on /api/downloads/v2
dandammann May 27, 2026
7c3cb93
Merge branch 'main' into task/CDD-3171-update-getpages-endpoint-for-n…
kathryn-dale May 28, 2026
095c1f9
Merge branch 'task/CDD-3171-update-getpages-endpoint-for-non-public-i…
dandammann May 28, 2026
e98220f
CDD-3173: get rid of check_permissions_by_name() and make /api/downlo…
dandammann May 28, 2026
bf2dac1
CDD-3173: let cms/dashboard/viewsets.py from CDD-3171 use my fully eq…
dandammann May 29, 2026
f6dc300
CDD-3173: add debugging code to user_manager.py to be able to test th…
dandammann May 29, 2026
6d65dde
CDD-3173: evaluate metric- and geography-related permissions separately
dandammann May 29, 2026
2d3677e
CDD-3173: lint
dandammann May 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion auth_content/models/__init__.py

This file was deleted.

File renamed without changes.
298 changes: 298 additions & 0 deletions cms/auth_content/auth_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
import logging
from collections.abc import Callable

from django import forms

from cms.auth_content.constants import WILDCARD_ID_VALUE
from cms.dynamic_content import help_texts
from metrics.data.models.core_models.supporting import (
Geography,
GeographyType,
Metric,
Topic,
)

logger = logging.getLogger(__name__)


def check_permissions_by_name(
permission_sets,
theme_name,
sub_theme_name,
topic_name,
metric_name,
geography_type,
geography_name,
) -> bool:
"""
This is a wrapper that converts permission resource names
into ids. It is only used to check CHART permissions.
"""

logger.info("Entered check_permissions_by_name()")

theme_id, sub_theme_id, topic_id = Topic.objects.get_id_by_name(
theme_name, sub_theme_name, topic_name
)
metric_id = Metric.objects.get_id_by_name(metric_name)
geography_type_id = GeographyType.objects.get_id_by_name(geography_type)
geography_id = Geography.objects.get_id_by_name(geography_name)

# Be safe, just in case a NAME doesn't have an ID
if any(
value == -2
for value in (
theme_id,
sub_theme_id,
topic_id,
metric_id,
geography_type_id,
geography_id,
)
):
return False

return check_permission_set(
permission_sets,
theme_id,
sub_theme_id,
topic_id,
metric_id,
geography_type_id,
geography_id,
)


def check_permission_set(
permission_sets,
theme_id,
sub_theme_id,
topic_id,
metric_id,
geography_type,
geography_id,
) -> bool:
"""
This is a wrapper that only checks for global permissions, and
delegates further checks to our core permission checking function.
It is only used to check CHART permissions.

@param {dict} permission_sets which contains a permission_sets list, eg:
{
"permission_sets": [
{
"theme": {"id": "100", "name": "immunisation"},
"sub_theme": {"id": "200", "name": "childhood-vaccines"},
"topic": {"id": "-1", "name": "* (All)"},
"metric": {"id": "-1", "name": "* (All)"},
"geography_type": {"id": "300", "name": "Nation"},
"geography": {"id": "-1", "name": "* (All)"},
}
],
"summary": {"has_global_access": False},
}
"""

logger.info("Entered check_permission_set()")

if not isinstance(permission_sets, dict):
return False
if not isinstance(permission_sets.get("permission_sets"), list):
return False
if not isinstance(permission_sets.get("summary"), dict):
return False
if not isinstance(permission_sets.get("summary").get("has_global_access"), bool):
return False

if permission_sets.get("summary").get("has_global_access"):
return True

return check_permissions(
permission_sets.get("permission_sets"),
theme_id,
sub_theme_id,
topic_id,
metric_id,
geography_type,
geography_id,
)


def check_permissions(
permission_sets,
theme_id,
sub_theme_id,
topic_id,
metric_id=None,
geography_type=None,
geography_id=None,
) -> bool:
"""
This is our core permission-checking function It is
used to check both PAGE & CHART permissions.

Metric- and geography-related permissions must be
evaluated separately (spec says).

@param {list} permission_sets, eg:
[
{
"theme": {"id": "100", "name": "immunisation"},
"sub_theme": {"id": "200", "name": "childhood-vaccines"},
"topic": {"id": "-1", "name": "* (All)"},
"metric": {"id": "-1", "name": "* (All)"},
"geography_type": {"id": "300", "name": "Nation"},
"geography": {"id": "-1", "name": "* (All)"},
}
]
"""

logger.info("Entered check_permissions()")

if not isinstance(permission_sets, list):
return False

for permission_set in permission_sets:
if geography_type and geography_id:
# CHART permissions
if check_metric_related_permissions(
permission_set, theme_id, sub_theme_id, topic_id, metric_id
) and check_geography_permissions(
permission_set, geography_type, geography_id
):
return True
else:
# PAGE permissions
if check_metric_related_permissions(
permission_set, theme_id, sub_theme_id, topic_id, metric_id
):
return True

return False


def check_metric_related_permissions(
permission_set,
theme_id,
sub_theme_id,
topic_id,
metric_id=None,
) -> bool:
"""
Make sure that every theme, sub_theme, topic and metric
match or have a wildcard at the end (only look at the
first 4 attributes of permission_set).

@param {dict} permission_set, eg:
{
"theme": {"id": "100", "name": "immunisation"},
"sub_theme": {"id": "200", "name": "childhood-vaccines"},
"topic": {"id": "-1", "name": "* (All)"},
"metric": {"id": "-1", "name": "* (All)"},
"geography_type": {"id": "300", "name": "Nation"},
"geography": {"id": "-1", "name": "* (All)"},
}
"""

logger.info("Entered check_metric_related_permissions()")

if not isinstance(permission_set, dict):
return False

theme_id = str(theme_id)
sub_theme_id = str(sub_theme_id)
topic_id = str(topic_id)
metric_id = str(metric_id)

permission_theme_id = str(permission_set.get("theme", {}).get("id"))
permission_sub_theme_id = str(permission_set.get("sub_theme", {}).get("id"))
permission_topic_id = str(permission_set.get("topic", {}).get("id"))
permission_metric_id = str(permission_set.get("metric", {}).get("id"))

if permission_theme_id == WILDCARD_ID_VALUE:
return True

if permission_theme_id == theme_id and permission_sub_theme_id == WILDCARD_ID_VALUE:
return True

if (
permission_theme_id == theme_id
and permission_sub_theme_id == sub_theme_id
and permission_topic_id in {WILDCARD_ID_VALUE, topic_id}
):
return True

if (
permission_theme_id == theme_id
and permission_sub_theme_id == sub_theme_id
and permission_topic_id == topic_id
and permission_metric_id in {WILDCARD_ID_VALUE, metric_id}
):
return True

return False


def check_geography_permissions(
permission_set,
geography_type=None,
geography_id=None,
) -> bool:
"""
Make sure that both geography_type and geography
match or have a wildcard at the end (only look at the
first 2 attributes of permission_set).

@param {dict} permission_set, eg:
{
"theme": {"id": "100", "name": "immunisation"},
"sub_theme": {"id": "200", "name": "childhood-vaccines"},
"topic": {"id": "-1", "name": "* (All)"},
"metric": {"id": "-1", "name": "* (All)"},
"geography_type": {"id": "300", "name": "Nation"},
"geography": {"id": "-1", "name": "* (All)"},
}
"""

logger.info("Entered check_geography_permissions()")

if not isinstance(permission_set, dict):
return False

geography_type = str(geography_type)
geography_id = str(geography_id)

permission_geography_type = str(permission_set.get("geography_type", {}).get("id"))
permission_geography_id = str(permission_set.get("geography", {}).get("id"))

if permission_geography_type == WILDCARD_ID_VALUE:
return True

if permission_geography_type == geography_type and permission_geography_id in {
WILDCARD_ID_VALUE,
geography_id,
}:
return True

return False


def _create_form_field(
field: dict[str, str | Callable | None], wildcard_id_value=None
) -> forms.CharField:
choices = [
("", field["field_choice_default"]),
]

if field["field_choice_wildcard"]:
choices += [(wildcard_id_value, field["field_choice_wildcard"])]

if field["field_choice_callable"]:
choices += field["field_choice_callable"]()

return forms.CharField(
required=False,
label=field["field_label"],
widget=forms.Select(choices=choices),
help_text=help_texts.NON_PUBLIC_PAGE_REQUIRED,
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.2.13 on 2026-05-22 08:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("auth_content", "0002_alter_permissionset_geography_type_and_more"),
]

operations = [
migrations.AddField(
model_name="permissionset",
name="display_name",
field=models.CharField(
blank=True,
help_text="\nThis is an (optional) user readable name for the permission set. If not set, a default autogenerated name will be used.\n",
max_length=255,
null=True,
),
),
migrations.AddConstraint(
model_name="permissionset",
constraint=models.UniqueConstraint(
condition=models.Q(("display_name__isnull", False)),
fields=("display_name",),
name="unique_non_null_display_name",
),
),
]
2 changes: 2 additions & 0 deletions cms/auth_content/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from cms.auth_content.models import users
from cms.auth_content.models import permission_sets
Loading
Loading