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

add _make_user_email_from_urn() to graphql helpers #580

Merged
merged 4 commits into from
Jul 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def parse_owner(entity: dict[str, Any]) -> OwnerRef:
)
owner_details = OwnerRef(
display_name=display_name or "",
email=properties.get("email", ""),
email=properties.get(
"email",
_make_user_email_from_urn(owners[0].get("urn")),
),
urn=owners[0].get("urn", ""),
)
else:
Expand Down Expand Up @@ -293,3 +296,19 @@ def parse_relations(

relations_return = {relationship_type: related_entities}
return relations_return


def _make_user_email_from_urn(urn) -> str:
"""
Creates a user email using a user entity urn. This should only be called
when an urn exists for a user that has not signed into datahub via sso,
so has not been created as an entity and has no associated email address.

We will look to revist our approach to ownership user creation, see
github issue https://github.com/ministryofjustice/find-moj-data/issues/578,
but for now this will fix the issue of owners being flagged in datahub but not
showing in find-moj-data
"""
username = urn.replace("urn:li:corpuser:", "")
email = f"{username}@justice.gov.uk"
return email
24 changes: 24 additions & 0 deletions lib/datahub-client/tests/client/datahub/test_graphql_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from datetime import datetime, timezone

import pytest

from data_platform_catalogue.client.graphql_helpers import (
_make_user_email_from_urn,
parse_columns,
parse_created_and_modified,
parse_glossary_terms,
Expand Down Expand Up @@ -375,3 +377,25 @@ def test_parse_glossary_terms():
)

assert result == [term]


@pytest.mark.parametrize(
"urn, expected_email",
[
(
"urn:li:corpuser:jon.smith",
"[email protected]",
),
(
"urn:li:corpuser:jon.smith54",
"[email protected]",
),
(
"urn:li:corpuser:jon.smith.sullivan",
"[email protected]",
),
],
)
def test_make_user_email_from_urn(urn, expected_email):
email = _make_user_email_from_urn(urn)
assert email == expected_email
Loading