diff --git a/src/datadoc/config.py b/src/datadoc/config.py index d30ccec2..824c87ba 100644 --- a/src/datadoc/config.py +++ b/src/datadoc/config.py @@ -133,3 +133,8 @@ def get_unit_code() -> int | None: def get_organisational_unit_code() -> int | None: """The code for the organisational units code list in Klass.""" return int(_get_config_item("DATADOC_ORGANISATIONAL_UNIT_CODE") or 83) + + +def get_dapla_manual_naming_standard_url() -> str | None: + """Get the URL to naming standard in the DAPLA manual.""" + return _get_config_item("DAPLA_MANUAL_NAMING_STANDARD_URL") diff --git a/src/datadoc/frontend/callbacks/dataset.py b/src/datadoc/frontend/callbacks/dataset.py index d00ece42..d38da967 100644 --- a/src/datadoc/frontend/callbacks/dataset.py +++ b/src/datadoc/frontend/callbacks/dataset.py @@ -80,13 +80,7 @@ def open_dataset_handling( if n_clicks and n_clicks > 0: dapla_dataset_path_info = DaplaDatasetPathInfo(file_path) if not dapla_dataset_path_info.path_complies_with_naming_standard(): - return ( - True, - False, - True, - "", - state.current_metadata_language.value, - ) + return (True, False, True, "", state.current_metadata_language.value) return True, False, False, "", state.current_metadata_language.value # no message return False, False, False, "", state.current_metadata_language.value diff --git a/src/datadoc/frontend/components/alerts.py b/src/datadoc/frontend/components/alerts.py index 09e82341..cbd2de2a 100644 --- a/src/datadoc/frontend/components/alerts.py +++ b/src/datadoc/frontend/components/alerts.py @@ -2,6 +2,7 @@ from __future__ import annotations +from datadoc.config import get_dapla_manual_naming_standard_url from datadoc.frontend.components.builders import AlertTypes from datadoc.frontend.components.builders import build_ssb_alert @@ -43,6 +44,7 @@ naming_convention_warning = build_ssb_alert( AlertTypes.WARNING, "opened-dataset_warning", - "Filen følger ikke navnestandard", + "Filen følger ikke navnestandard. Vennlist se", "opened-dataset-warning-explanation", + link=get_dapla_manual_naming_standard_url(), ) diff --git a/src/datadoc/frontend/components/builders.py b/src/datadoc/frontend/components/builders.py index eb4ff4a2..2e1f96b0 100644 --- a/src/datadoc/frontend/components/builders.py +++ b/src/datadoc/frontend/components/builders.py @@ -78,6 +78,7 @@ def build_ssb_alert( # noqa: PLR0913 not immediately obvious how to improve thi message: str | None = None, *, start_open: bool = False, + link: str | None = None, ) -> dbc.Alert: """Make a Dash Alert according to SSBs Design System.""" alert = AlertType.get_type(alert_type) @@ -96,6 +97,7 @@ def build_ssb_alert( # noqa: PLR0913 not immediately obvious how to improve thi id=content_identifier, children=message, ), + html.A(link, href=link, target="_blank"), ], style={"width": "70%"}, ) diff --git a/tests/frontend/callbacks/test_dataset_callbacks.py b/tests/frontend/callbacks/test_dataset_callbacks.py index 5fa81274..02f12d49 100644 --- a/tests/frontend/callbacks/test_dataset_callbacks.py +++ b/tests/frontend/callbacks/test_dataset_callbacks.py @@ -45,6 +45,11 @@ def file_path(): return "valid/path/to/file.json" +@pytest.fixture() +def file_path_without_dates(): + return "valid/path/to/person_data_v1.parquet" + + @pytest.mark.parametrize( ("metadata_identifier", "provided_value", "expected_model_value"), [ @@ -278,13 +283,13 @@ def test_open_dataset_handling_normal( ): state.current_metadata_language = SupportedLanguages.ENGLISH - opened, show_error, error_msg, language = open_dataset_handling( + opened, show_error, naming_standard, error_msg, language = open_dataset_handling( n_clicks_1, file_path, ) - assert opened assert not show_error + assert naming_standard assert error_msg == "" assert language == "en" @@ -298,12 +303,13 @@ def test_open_dataset_handling_file_not_found( state.current_metadata_language = SupportedLanguages.ENGLISH open_file_mock.side_effect = FileNotFoundError() - opened, show_error, error_msg, language = open_dataset_handling( + opened, show_error, naming_standard, error_msg, language = open_dataset_handling( n_clicks_1, file_path, ) assert not opened assert show_error + assert not naming_standard assert error_msg.startswith(f"Filen '{file_path}' finnes ikke.") assert language == "en" @@ -317,12 +323,13 @@ def test_open_dataset_handling_general_exception( state.current_metadata_language = SupportedLanguages.ENGLISH open_file_mock.side_effect = ValueError() - opened, show_error, error_msg, language = open_dataset_handling( + opened, show_error, naming_standard, error_msg, language = open_dataset_handling( n_clicks_1, file_path, ) assert not opened assert show_error + assert not naming_standard assert error_msg.startswith("ValueError") assert language == "en" @@ -333,10 +340,31 @@ def test_open_dataset_handling_no_click( file_path: str, ): state.current_metadata_language = SupportedLanguages.ENGLISH - opened, show_error, error_msg, language = open_dataset_handling(0, file_path) - + opened, show_error, naming_standard, error_msg, language = open_dataset_handling( + 0, + file_path, + ) assert not opened assert not show_error + assert not naming_standard + assert error_msg == "" + assert language == "en" + + +@patch(f"{DATASET_CALLBACKS_MODULE}.open_file") +def test_open_dataset_handling_naming_standard( + open_file_mock: Mock, # noqa: ARG001 + n_clicks_1: int, + file_path_without_dates: str, +): + state.current_metadata_language = SupportedLanguages.ENGLISH + opened, show_error, naming_standard, error_msg, language = open_dataset_handling( + n_clicks_1, + file_path_without_dates, + ) + assert opened is True + assert not show_error + assert naming_standard assert error_msg == "" assert language == "en"