From 51a904dc0755b308d159d21052df48715539c5b7 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 4 Jun 2023 08:05:48 +0200 Subject: [PATCH] Only return anonymous_url in anonymous context Otherwise the frontend will treat map as anonymous even with and owner and display a wrong message creation. Also, this edit URL does not make sense (and will not work) when there is an owner. --- umap/tests/test_map_views.py | 1 - umap/views.py | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/umap/tests/test_map_views.py b/umap/tests/test_map_views.py index 2b7489ec..426e42a4 100644 --- a/umap/tests/test_map_views.py +++ b/umap/tests/test_map_views.py @@ -42,7 +42,6 @@ def test_create(client, user, post_data): "share_status": 1, "owner": {"id": user.pk, "name": "Joe", "url": "/en/user/Joe/"}, "editors": [], - "anonymous_edit_url": created_map.get_anonymous_edit_url(), } diff --git a/umap/views.py b/umap/views.py index 2465a498..a7cd6d4f 100644 --- a/umap/views.py +++ b/umap/views.py @@ -545,10 +545,11 @@ class MapCreate(FormLessEditMixin, PermissionsMixin, CreateView): if self.request.user.is_authenticated: form.instance.owner = self.request.user self.object = form.save() - anonymous_url = self.object.get_anonymous_edit_url() permissions = self.get_permissions() # User does not have the cookie yet. - permissions["anonymous_edit_url"] = anonymous_url + if not self.object.owner: + anonymous_url = self.object.get_anonymous_edit_url() + permissions["anonymous_edit_url"] = anonymous_url response = simple_json_response( id=self.object.pk, url=self.object.get_absolute_url(),