Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
only show active tags in assessment dashboard and the change tags screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 committed Oct 17, 2023
1 parent 2b50c9b commit 12efb02
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
8 changes: 4 additions & 4 deletions app/blueprints/assessments/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def get_tag_map_and_tag_options(fund_round_tags, post_processed_overviews):
)
for purposes in Config.TAGGING_FILTER_CONFIG
]
tag_map = {}
tags_in_application_map = {}
for overview in post_processed_overviews:
tag_map[overview["application_id"]] = (
tags_in_application_map[overview["application_id"]] = (
[
AssociatedTag(
application_id=overview["application_id"],
Expand All @@ -132,13 +132,13 @@ def get_tag_map_and_tag_options(fund_round_tags, post_processed_overviews):
purpose=item["tag"]["tag_type"]["purpose"],
)
for item in overview["tag_associations"]
if item["associated"] is True
if item["associated"] is True and item["tag"]["active"] is True
]
if overview["tag_associations"]
else None
)

return tag_map, tag_option_groups
return tags_in_application_map, tag_option_groups


def generate_csv_of_application(q_and_a: dict, fund: Fund, application_json):
Expand Down
29 changes: 16 additions & 13 deletions app/blueprints/assessments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ def fund_dashboard(fund_short_name: str, round_short_name: str):

# This call is to get the location data such as country, region and local_authority
# from all the existing applications.
applications_metadata = get_application_overviews(
all_applications_metadata = get_application_overviews(
fund_id, round_id, search_params=""
)
locations = LocationData.from_json_blob(applications_metadata)
# note, we are not sending search parameters here as we don't want to filter
# the stats at all. see https://dluhcdigital.atlassian.net/browse/FS-3249
unfiltered_stats = process_assessments_stats(all_applications_metadata)
all_application_locations = LocationData.from_json_blob(
all_applications_metadata
)

search_params = {
**search_params,
Expand All @@ -245,10 +250,6 @@ def fund_dashboard(fund_short_name: str, round_short_name: str):
fund_id, round_id, search_params
)

# note, we are not sending search parameters here as we don't want to filter
# the stats at all. see https://dluhcdigital.atlassian.net/browse/FS-3249
stats = process_assessments_stats(applications_metadata)

teams_flag_stats = get_team_flag_stats(application_overviews)

# this is only used for querying applications, so remove it from the search params,
Expand Down Expand Up @@ -278,7 +279,7 @@ def fund_dashboard(fund_short_name: str, round_short_name: str):
active_fund_round_tags = get_tags_for_fund_round(
fund_id, round_id, {"tag_status": "True"}
)
tag_map, tag_option_groups = get_tag_map_and_tag_options(
tags_in_application_map, tag_option_groups = get_tag_map_and_tag_options(
active_fund_round_tags, post_processed_overviews
)

Expand All @@ -296,7 +297,9 @@ def get_sorted_application_overviews(
"organisation_name": lambda x: x["organisation_name"],
"funding_type": lambda x: x["funding_type"],
"status": lambda x: x["application_status"],
"tags": lambda x: len(tag_map.get(x["application_id"]) or []),
"tags": lambda x: len(
tags_in_application_map.get(x["application_id"]) or []
),
}

# Define the sorting function based on the specified column
Expand Down Expand Up @@ -326,17 +329,17 @@ def get_sorted_application_overviews(
cohort=cohort,
assessment_statuses=assessment_statuses,
show_clear_filters=show_clear_filters,
stats=stats,
stats=unfiltered_stats,
team_flag_stats=teams_flag_stats,
is_active_status=is_active_status,
sort_column=sort_column,
sort_order=sort_order,
tag_option_groups=tag_option_groups,
tags=tag_map,
tags=tags_in_application_map,
tagging_purpose_config=Config.TAGGING_PURPOSE_CONFIG,
countries=locations.countries,
regions=locations.regions,
local_authorities=locations._local_authorities,
countries=all_application_locations.countries,
regions=all_application_locations.regions,
local_authorities=all_application_locations._local_authorities,
)


Expand Down
9 changes: 6 additions & 3 deletions app/blueprints/tagging/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,24 @@ def load_change_tags(application_id):
)
)
state = get_state_for_tasklist_banner(application_id)
available_tags = get_tags_for_fund_round(state.fund_id, state.round_id, "")
all_tags = get_tags_for_fund_round(state.fund_id, state.round_id, "")
associated_tags = get_associated_tags_for_application(application_id)
active_tags = []
if associated_tags:
associated_tag_ids = [tag.tag_id for tag in associated_tags]
for tag in available_tags:
for tag in all_tags:
if tag.id in associated_tag_ids:
tag.associated = True
if tag.active:
active_tags.append(tag)
assessment_status = determine_assessment_status(
state.workflow_status, state.is_qa_complete
)
return render_template(
"change_tags.html",
form=tag_association_form,
state=state,
available_tags=available_tags,
available_tags=active_tags,
tag_config=Config.TAGGING_PURPOSE_CONFIG,
application_id=application_id,
assessment_status=assessment_status,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ def test_change_tags_route(
)


@pytest.mark.application_id("resolved_app")
def test_change_tags_route_does_not_show_deactivated_tags_as_options(
mock_get_tasklist_state_for_banner,
client_with_valid_session,
mock_get_funds,
mock_get_application_metadata,
mock_get_fund,
mock_get_inactive_tags_for_fund_round,
mock_get_associated_tags_for_application,
):

response = client_with_valid_session.get("/assess/application/app_id/tags")
soup = BeautifulSoup(response.data, "html.parser")
assert soup.find("h1").text == "Change tags"
assert (
soup.find(
"p",
class_="govuk-body dluhc-body-empty",
).text.strip()
== "There are no tags available"
)


@pytest.mark.application_id("resolved_app")
def test_change_tags_route_associated_tag_checked(
mock_get_tasklist_state_for_banner,
Expand Down

0 comments on commit 12efb02

Please sign in to comment.