Merge pull request #1784 from umap-project/fix-alert-anonymous

fix: make sure to display anonymous edit link even if email is not configured
This commit is contained in:
Yohan Boniface 2024-05-01 17:07:57 +02:00 committed by GitHub
commit cd10a6259f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 11 deletions

View file

@ -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({
) + `<br>${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,

View file

@ -203,3 +203,24 @@ 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()
@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
):
# 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()