diff --git a/app/blueprints/assessments/helpers.py b/app/blueprints/assessments/helpers.py index 5578e316..f56682dc 100644 --- a/app/blueprints/assessments/helpers.py +++ b/app/blueprints/assessments/helpers.py @@ -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"], @@ -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): diff --git a/app/blueprints/assessments/routes.py b/app/blueprints/assessments/routes.py index 8c9dca57..8e1780b5 100644 --- a/app/blueprints/assessments/routes.py +++ b/app/blueprints/assessments/routes.py @@ -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, @@ -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, @@ -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 ) @@ -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 @@ -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, ) diff --git a/app/blueprints/tagging/routes.py b/app/blueprints/tagging/routes.py index c29ce90e..3fae359c 100644 --- a/app/blueprints/tagging/routes.py +++ b/app/blueprints/tagging/routes.py @@ -72,13 +72,16 @@ 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 ) @@ -86,7 +89,7 @@ def load_change_tags(application_id): "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, diff --git a/tests/test_tags.py b/tests/test_tags.py index 20dcff25..53ca2fc1 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -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,