From 8c203972099e67bc808907d3c84988b307460a26 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 1 May 2024 15:43:10 +0200 Subject: [PATCH 1/2] fix: make sure to display anonymous edit link even if email is not configured --- umap/static/umap/js/umap.js | 20 +++++++++---------- .../integration/test_anonymous_owned_map.py | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 348d849a..f11054bb 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -1023,11 +1023,7 @@ U.Map = L.Map.extend({ this.options.umap_id = data.id this.permissions.setOptions(data.permissions) this.permissions.commit() - if ( - data.permissions && - data.permissions.anonymous_edit_url && - this.options.urls.map_send_edit_link - ) { + if (data.permissions && data.permissions.anonymous_edit_url) { alert.duration = Infinity alert.content = L._( @@ -1035,12 +1031,6 @@ U.Map = L.Map.extend({ ) + `
${data.permissions.anonymous_edit_url}` alert.actions = [ - { - label: L._('Send me the link'), - input: L._('Email'), - callback: this.sendEditLink, - callbackContext: this, - }, { label: L._('Copy link'), callback: () => { @@ -1053,6 +1043,14 @@ U.Map = L.Map.extend({ callbackContext: this, }, ] + if (this.options.urls.map_send_edit_link) { + alert.actions.push({ + label: L._('Send me the link'), + input: L._('Email'), + callback: this.sendEditLink, + callbackContext: this, + }) + } } } else if (!this.permissions.isDirty) { // Do not override local changes to permissions, diff --git a/umap/tests/integration/test_anonymous_owned_map.py b/umap/tests/integration/test_anonymous_owned_map.py index 74f3f0e7..0a92e523 100644 --- a/umap/tests/integration/test_anonymous_owned_map.py +++ b/umap/tests/integration/test_anonymous_owned_map.py @@ -203,3 +203,23 @@ def test_email_sending_error_are_catched(tilelayer, page, live_server): alert.get_by_role("button", name="Send me the link").click() assert patched.called expect(alert.get_by_text("Can't send email to foo@bar.com")).to_be_visible() + + +def test_alert_message_after_create_show_link_even_without_mail( + tilelayer, live_server, page, monkeypatch, settings +): + # Disable email + settings.DEFAULT_FROM_EMAIL = None + page.goto(f"{live_server.url}/en/map/new") + with page.expect_response(re.compile(r".*/map/create/")): + page.get_by_role("button", name="Save").click() + alert = page.locator(".umap-alert") + expect(alert).to_be_visible() + expect( + alert.get_by_text( + "Your map has been created! As you are not logged in, here is your secret " + "link to edit the map, please keep it safe:" + ) + ).to_be_visible() + expect(alert.get_by_role("button", name="Copy")).to_be_visible() + expect(alert.get_by_role("button", name="Send me the link")).to_be_hidden() From 0002b22f5cfe2d0d4e7158ed53493a73a72d8b50 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 1 May 2024 16:57:46 +0200 Subject: [PATCH 2/2] chore: skip failing test for now This test was relying on changing DEFAULT_FROM_EMAIL in the test, but given this setting is used at load from urls.py, it has no effect. --- umap/tests/integration/test_anonymous_owned_map.py | 1 + 1 file changed, 1 insertion(+) diff --git a/umap/tests/integration/test_anonymous_owned_map.py b/umap/tests/integration/test_anonymous_owned_map.py index 0a92e523..5e266b8d 100644 --- a/umap/tests/integration/test_anonymous_owned_map.py +++ b/umap/tests/integration/test_anonymous_owned_map.py @@ -205,6 +205,7 @@ def test_email_sending_error_are_catched(tilelayer, page, live_server): expect(alert.get_by_text("Can't send email to foo@bar.com")).to_be_visible() +@pytest.mark.skip(reason="Changing DEFAULT_FROM_EMAIL at runtime has no effect") def test_alert_message_after_create_show_link_even_without_mail( tilelayer, live_server, page, monkeypatch, settings ):