From b51210ee3500448073476bc90e8582091d9e31ba Mon Sep 17 00:00:00 2001 From: Moshe Eichler <78307768+MosheEichler@users.noreply.github.com> Date: Wed, 7 Feb 2024 09:31:11 +0200 Subject: [PATCH] Improve create clickable URL (#31584) * Add the ability to create a clickable url with different text than the link * RN * revert * added a modeling rule (#22875) * added a modeling rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * added a parsing rule * Update README.md (#23810) Edit the file to remove duplication of command names in the right pane. * Modeling rules fixes (#24259) * save * save no exit_code * save not fail on test-modeling-rules * remove ciscoasa changes * Update Docker Image To demisto/chromium (#24291) * Updated Metadata Of Pack ExpanseV2 * Added release notes to pack ExpanseV2 * Packs/ExpanseV2/Scripts/ExpanseGenerateIssueMapWidgetScript/ExpanseGenerateIssueMapWidgetScript.yml Docker image update * Deprecated GitHub TestData (#31573) * CR fixes * UT fixes * revert f-string * conflicts * pack version * conflicts * doc * conflicts * Bump pack from version Base to 1.34.0. * conflicts * RN * remove parameterize * Bump pack from version Base to 1.33.26. * pre-commit fixes --------- Co-authored-by: guytamir10 <106061479+guytamir10@users.noreply.github.com> Co-authored-by: ShirleyDenkberg <62508050+ShirleyDenkberg@users.noreply.github.com> Co-authored-by: Darya Koval <72339940+daryakoval@users.noreply.github.com> Co-authored-by: content-bot <55035720+content-bot@users.noreply.github.com> Co-authored-by: eepstain <116078117+eepstain@users.noreply.github.com> Co-authored-by: Content Bot --- Packs/Base/.pack-ignore | 1 + Packs/Base/ReleaseNotes/1_33_26.md | 6 ++ .../CommonServerPython/CommonServerPython.py | 14 +++- .../CommonServerPython_test.py | 75 +++++++++++++++++++ Packs/Base/pack_metadata.json | 4 +- 5 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 Packs/Base/ReleaseNotes/1_33_26.md diff --git a/Packs/Base/.pack-ignore b/Packs/Base/.pack-ignore index 43512e3a3209..0af5e65fab1e 100644 --- a/Packs/Base/.pack-ignore +++ b/Packs/Base/.pack-ignore @@ -81,6 +81,7 @@ JavaScript CPE CPEs debug-entry +clickable [tests_require_network] CommonServerPython diff --git a/Packs/Base/ReleaseNotes/1_33_26.md b/Packs/Base/ReleaseNotes/1_33_26.md new file mode 100644 index 000000000000..07137716ee1e --- /dev/null +++ b/Packs/Base/ReleaseNotes/1_33_26.md @@ -0,0 +1,6 @@ + +#### Scripts + +##### CommonServerPython + +Added the ability to create a clickable URL with different text than the link. diff --git a/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py b/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py index ef4bfec9fc6d..572cf2b89150 100644 --- a/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py +++ b/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py @@ -2018,22 +2018,28 @@ def url_to_clickable_markdown(data, url_keys): return data -def create_clickable_url(url): +def create_clickable_url(url, text=None): """ Make the given url clickable when in markdown format by concatenating itself, with the proper brackets :type url: ``Union[List[str], str]`` :param url: the url of interest or a list of urls - :return: markdown format for clickable url - :rtype: ``str`` + :type text: ``Union[List[str], str, None]`` + :param text: the text of the url or a list of texts of urls. + + :return: Markdown format for clickable url + :rtype: ``Union[List[str], str]`` """ if not url: return None elif isinstance(url, list): + if isinstance(text, list): + assert len(url) == len(text), 'The URL list and the text list must be the same length.' + return ['[{}]({})'.format(text, item) for text, item in zip(text, url)] return ['[{}]({})'.format(item, item) for item in url] - return '[{}]({})'.format(url, url) + return '[{}]({})'.format(text or url, url) class JsonTransformer: diff --git a/Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py b/Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py index 56f16815d74d..74de2379560d 100644 --- a/Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py +++ b/Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py @@ -9243,3 +9243,78 @@ def test_detect_file_indicator_type(indicator, expected_result): """ from CommonServerPython import detect_file_indicator_type assert detect_file_indicator_type(indicator) == expected_result + + +def test_create_clickable_url(): + """ + Given: + One URL and one text. + When: + Running create_clickable_url function. + Then: + Assert the function returns the expected result. + A URL with different text than the link. + """ + from CommonServerPython import create_clickable_url + assert create_clickable_url('https://example.com', 'click here') == '[click here](https://example.com)' + + +def test_create_clickable_url_one_url_without_text(): + """ + Given: + One URL. + When: + Running create_clickable_url function. + Then: + Assert the function returns the expected result. + A clickable URL with the same text as the link. + """ + from CommonServerPython import create_clickable_url + assert create_clickable_url('https://example.com', None) == '[https://example.com](https://example.com)' + + +def test_create_clickable_url_list_of_urls_with_list_of_text(): + """ + Given: + A list of URLs and a list of texts. + When: + Running create_clickable_url function. + Then: + Assert the function returns the expected result. + A list of URLs with different texts than the links. + """ + from CommonServerPython import create_clickable_url + expected = ['[click here1](https://example1.com)', '[click here2](https://example2.com)'] + assert create_clickable_url(['https://example1.com', 'https://example2.com'], ['click here1', 'click here2']) == expected + + +def test_create_clickable_url_list_of_urls_without_text(): + """ + Given: + A list of URLs without text. + When: + Running create_clickable_url function. + Then: + Assert the function returns the expected result. + A list URLs without texts as the links. + """ + from CommonServerPython import create_clickable_url + expected = ['[https://example1.com](https://example1.com)', '[https://example2.com](https://example2.com)'] + assert create_clickable_url(['https://example1.com', 'https://example2.com'], None) == expected + + +def test_create_clickable_test_wrong_text_value(): + """ + Given: + A list of links and texts (not in teh same length). + When: + Running create_clickable_url function. + Then: + Assert the function returns the expected error. + """ + from CommonServerPython import create_clickable_url + with pytest.raises(AssertionError) as e: + assert create_clickable_url(['https://example1.com', 'https://example2.com'], ['click here1']) + + assert e.type == AssertionError + assert 'The URL list and the text list must be the same length.' in e.value.args diff --git a/Packs/Base/pack_metadata.json b/Packs/Base/pack_metadata.json index 33a68e44c3d0..9707e70463b4 100644 --- a/Packs/Base/pack_metadata.json +++ b/Packs/Base/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Base", "description": "The base pack for Cortex XSOAR.", "support": "xsoar", - "currentVersion": "1.33.25", + "currentVersion": "1.33.26", "author": "Cortex XSOAR", "serverMinVersion": "6.0.0", "url": "https://www.paloaltonetworks.com/cortex", @@ -25,4 +25,4 @@ "marketplacev2", "xpanse" ] -} +} \ No newline at end of file