diff --git a/feedback/models.py b/feedback/models.py index 5998bacc..49d7d3e9 100644 --- a/feedback/models.py +++ b/feedback/models.py @@ -1,3 +1,5 @@ +from urllib.parse import ParseResult, quote, urlparse, urlunparse + from django.conf import settings from django.core.validators import MinLengthValidator from django.db import models @@ -55,3 +57,19 @@ class IssueChoices(models.TextChoices): entity_name = models.CharField(max_length=250) entity_url = models.CharField(max_length=250) data_custodian_email = models.CharField(max_length=250) + + @property + def encoded_entity_url(self): + parsed_url: ParseResult = urlparse(self.entity_url) + encoded_path: str = quote(parsed_url.path) + encoded_entity_url: str = urlunparse( + ( + parsed_url.scheme, + parsed_url.netloc, + encoded_path, + parsed_url.params, + parsed_url.query, + parsed_url.fragment, + ) + ) + return encoded_entity_url diff --git a/feedback/service.py b/feedback/service.py index 859963c1..49c34fc2 100644 --- a/feedback/service.py +++ b/feedback/service.py @@ -28,12 +28,14 @@ def send( personalisation = { "assetOwner": ( - issue.data_custodian_email if issue.data_custodian_email else "Data Catalog Team" + issue.data_custodian_email + if issue.data_custodian_email + else "Data Catalog Team" ), "userEmail": issue.created_by.email if issue.created_by else "", "assetName": issue.entity_name, "userMessage": issue.additional_info, - "assetUrl": issue.entity_url, + "assetUrl": issue.encoded_entity_url, } reference = str(issue.id) diff --git a/tests/feedback/test_notify_service.py b/tests/feedback/test_notify_service.py index b342fd20..5f2db783 100644 --- a/tests/feedback/test_notify_service.py +++ b/tests/feedback/test_notify_service.py @@ -24,7 +24,9 @@ def test_send_all_notifications(mock_notifications_client, reporter): @pytest.mark.django_db -def test_send_notifications_no_data_custodian_email(mock_notifications_client, reporter): +def test_send_notifications_no_data_custodian_email( + mock_notifications_client, reporter +): data = { "reason": "Other", "additional_info": "This is some additional information.", @@ -76,3 +78,20 @@ def test_send_all_notifications_no_reporter_no_data_custodian_email( send(issue=issue, client=mock_notifications_client, send_email_to_reporter=False) assert mock_notifications_client.send_email_notification.call_count == 1 + + +@pytest.mark.django_db +def test_entity_url_encoding(reporter): + data = { + "reason": "Other", + "additional_info": "This is some additional information.", + "entity_name": "my_entity", + "entity_url": "http://localhost:8000/details/table/urn:li:dataset:(urn:li:dataPlatform:dbt,cadet.awsdatacatalog.derived_oasys_dim.dim_ref_question,PROD)", # noqa: E501 + "created_by": reporter, + } + + encoded_entity_url = "http://localhost:8000/details/table/urn%3Ali%3Adataset%3A%28urn%3Ali%3AdataPlatform%3Adbt%2Ccadet.awsdatacatalog.derived_oasys_dim.dim_ref_question%2CPROD%29" # noqa: E501 + + issue = Issue.objects.create(**data) + assert issue + assert issue.encoded_entity_url == encoded_entity_url