Skip to content

Commit c03593a

Browse files
Filter programmes by team's programme_types from JWT
The Mavis API now includes programme_types in the JWT cis2_info payload, allowing us to show only the programmes available to the user's team rather than all programmes.
1 parent b50da05 commit c03593a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

mavis/reporting/api_client/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,21 @@ def get_variables(self) -> list[dict]:
8888
]
8989

9090
def get_programmes(self) -> list[dict]:
91-
return [
91+
all_programmes = [
9292
{"value": "flu", "text": "Flu"},
9393
{"value": "hpv", "text": "HPV"},
9494
{"value": "menacwy", "text": "MenACWY"},
9595
{"value": "td_ipv", "text": "Td/IPV"},
9696
]
9797

98+
cis2_info = (self.session or {}).get("cis2_info", {})
99+
programme_types = cis2_info.get("programme_types", [])
100+
101+
if not programme_types:
102+
return all_programmes
103+
104+
return [p for p in all_programmes if p["value"] in programme_types]
105+
98106
def get_year_groups(self) -> list[dict]:
99107
return [
100108
{"value": "0", "text": "Reception"},

tests/api_client/test_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,26 @@ def test_td_ipv_returns_years_9_to_11(self, api_client):
8686
def test_unknown_programme_returns_empty_list(self, api_client):
8787
result = api_client.get_year_groups_for_programme("unknown")
8888
assert result == []
89+
90+
91+
class TestGetProgrammes:
92+
def test_returns_all_when_no_programme_types(self, app):
93+
client = MavisApiClient(app=app, session={"jwt": "x", "cis2_info": {}})
94+
result = client.get_programmes()
95+
values = [p["value"] for p in result]
96+
assert values == ["flu", "hpv", "menacwy", "td_ipv"]
97+
98+
def test_filters_by_programme_types(self, app):
99+
client = MavisApiClient(
100+
app=app,
101+
session={"jwt": "x", "cis2_info": {"programme_types": ["flu", "hpv"]}},
102+
)
103+
result = client.get_programmes()
104+
values = [p["value"] for p in result]
105+
assert values == ["flu", "hpv"]
106+
107+
def test_returns_all_when_cis2_info_missing(self, app):
108+
client = MavisApiClient(app=app, session={"jwt": "x"})
109+
result = client.get_programmes()
110+
values = [p["value"] for p in result]
111+
assert values == ["flu", "hpv", "menacwy", "td_ipv"]

0 commit comments

Comments
 (0)