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.
This commit is contained in:
Yohan Boniface 2023-06-04 08:05:48 +02:00
parent 90f7680d8d
commit 51a904dc07
2 changed files with 3 additions and 3 deletions

View file

@ -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(),
}

View file

@ -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(),