Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Urlencode entity url for notifications #1173

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions feedback/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions feedback/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion tests/feedback/test_notify_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Loading