From 3ab39d23a197c20de06ec169675cd4ebbca13201 Mon Sep 17 00:00:00 2001 From: Mat Moore Date: Mon, 12 Aug 2024 14:06:04 +0100 Subject: [PATCH] feat: add fallback for missing access info --- locale/en/LC_MESSAGES/django.po | 22 +++-- templates/partial/contact_info.html | 6 +- .../test_details_contact_contents.py | 92 +++++++++++++++++-- 3 files changed, 102 insertions(+), 18 deletions(-) diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index e26359239..4e4781742 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Find MoJ data\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-08 16:54+0100\n" +"POT-Creation-Date: 2024-08-12 13:45+0100\n" "Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -193,7 +193,8 @@ msgstr "Last updated:" msgid "Domain:" msgstr "Domain:" -#: templates/details_base.html:73 templates/partial/search_result.html:41 +#: templates/details_base.html:73 templates/partial/contact_info.html:36 +#: templates/partial/search_result.html:41 msgid "Not provided" msgstr "Not provided." @@ -366,22 +367,25 @@ msgid "Access requirements" msgstr "Request access" # Request access link -#: templates/partial/contact_info.html:8 +#: templates/partial/contact_info.html:7 msgid "Click link for access information (opens in new tab)" msgstr "Click link for access information (opens in new tab)" -# Default text for contact info -#: templates/partial/contact_info.html:13 -msgid "Processing the data might require permission from IAO or Data owner." -msgstr "Processing the data might require permission from the Data owner." +#: templates/partial/contact_info.html:12 +msgid "Please use contact channels to request access." +msgstr "Please use contact channels to request access." + +#: templates/partial/contact_info.html:14 +msgid "Please contact the data owner for access information." +msgstr "Please contact the data owner for access information." # Heading -#: templates/partial/contact_info.html:20 +#: templates/partial/contact_info.html:22 msgid "Contact channels for questions" msgstr "Contact channels for questions" # Heading -#: templates/partial/contact_info.html:32 +#: templates/partial/contact_info.html:34 msgid "IAO or Data Owner" msgstr "Data owner" diff --git a/templates/partial/contact_info.html b/templates/partial/contact_info.html index c35acb37c..87df406f9 100644 --- a/templates/partial/contact_info.html +++ b/templates/partial/contact_info.html @@ -8,8 +8,12 @@

{% translate "Access require {% else %}

{{ access_requirements }}

{% endif %} + {% elif slack_channel.dc_slack_channel_url %} +

{% translate "Please use contact channels to request access." %}

+ {% elif data_owner_email %} +

{% translate "Please contact the data owner for access information." %}

{% else %} -

{% translate "Processing the data might require permission from IAO or Data owner." %}

+

{% translate "Not provided" %}

{% endif %} diff --git a/tests/integration/test_details_contact_contents.py b/tests/integration/test_details_contact_contents.py index c75f50953..13f583a7a 100644 --- a/tests/integration/test_details_contact_contents.py +++ b/tests/integration/test_details_contact_contents.py @@ -1,5 +1,10 @@ import pytest -from data_platform_catalogue.entities import AccessInformation, CustomEntityProperties +from data_platform_catalogue.entities import ( + AccessInformation, + CustomEntityProperties, + FurtherInformation, + OwnerRef, +) from tests.conftest import ( generate_database_metadata, @@ -41,15 +46,14 @@ def setup( "To access these data you need to seek permission from the data owner by email", "p", ), - ( - "", - "Processing the data might require permission from the Data owner.", - "p", - ), ], ) def test_access_requirements_content( - self, mock_catalogue, access_reqs, expected_text, expected_tag + self, + mock_catalogue, + access_reqs, + expected_text, + expected_tag, ): """ test that what is displayed in the request action section of contacts is what we expect @@ -61,9 +65,12 @@ def test_access_requirements_content( """ test_database = generate_database_metadata( custom_properties=CustomEntityProperties( - access_information=AccessInformation(dc_access_requirements=access_reqs) + access_information=AccessInformation( + dc_access_requirements=access_reqs + ), ) ) + mock_get_database_details_response(mock_catalogue, test_database) self.start_on_the_details_page() @@ -73,6 +80,75 @@ def test_access_requirements_content( assert request_access_metadata.text == expected_text assert request_access_metadata.tag_name == expected_tag + @pytest.mark.parametrize( + "access_reqs, slack_channel, owner, expected_text", + [ + ( + "Some contact info", + "#contact us", + "meta.data@justice.gov.uk", + "Some contact info", + ), + ( + "", + "#contact_us", + "meta.data@justice.gov.uk", + "Please use contact channels to request access.", + ), + ( + "", + "", + "meta.data@justice.gov.uk", + "Please contact the data owner for access information.", + ), + ( + "", + "", + "", + "Not provided.", + ), + ], + ) + def test_access_requirements_fallbacks( + self, mock_catalogue, access_reqs, slack_channel, owner, expected_text + ): + """ + If no access requirements are given, users should use the contact info, + if provided. If not, then they should contact the data owner. + If none of the information is provided, then the catalogue entry is + non-functional - we should prevent this happening at ingestion time + or before. + """ + test_database = generate_database_metadata( + custom_properties=CustomEntityProperties( + access_information=AccessInformation( + dc_access_requirements=access_reqs + ), + ) + ) + + if owner: + test_database.governance.data_owner = OwnerRef( + display_name=owner, email=owner, urn="urn:bla" + ) + else: + test_database.governance.data_owner.display_name = "" + test_database.governance.data_owner.email = "" + + if slack_channel: + test_database.custom_properties.further_information = FurtherInformation( + dc_slack_channel_name=slack_channel, + dc_slack_channel_url="http://bla.com", + ) + + mock_get_database_details_response(mock_catalogue, test_database) + + self.start_on_the_details_page() + + request_access_metadata = self.details_database_page.request_access() + + assert request_access_metadata.text == expected_text + def start_on_the_details_page(self): self.selenium.get( f"{self.live_server_url}/details/database/urn:li:container:test"