Skip to content

Commit

Permalink
Fix an error 500 in the merge view when one entity did not exist anym…
Browse files Browse the repository at this point in the history
…ore.
  • Loading branch information
genglert committed Dec 7, 2023
1 parent d0079f2 commit 8f4f70a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
== Version 2.3.17 Work in progress (not released -- this is a draft) ==

TODO: compile *.po (creme_config)
TODO: compile *.po (creme_core, creme_config)

Users side :
------------
# An error 500 in the merge view, when one entity did not exist anymore, has been fixed.
# In the theme "Chantilly", an icon "Restore" was missing.
# Apps :
* Assistants :
Expand Down
9 changes: 8 additions & 1 deletion creme/creme_core/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Creme Creme-Core 2.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-25 15:41+0200\n"
"POT-Creation-Date: 2023-12-07 09:57+0100\n"
"Last-Translator: Hybird <[email protected]>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -3481,6 +3481,13 @@ msgstr ""
"des vieilles fiches seront automatiquement disponibles dans la nouvelle "
"fiche fusionnée."

msgid ""
"One entity you want to merge does not exist anymore (have you already "
"performed the merge?)"
msgstr ""
"Une fiche que vous voulez fusionner n'existe plus (avez-vous déjà effectué la "
"fusion ?)"

msgid "A job is already cleaning the trash."
msgstr "Un job est déjà en train de vider la corbeille."

Expand Down
5 changes: 4 additions & 1 deletion creme/creme_core/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ..gui.icons import get_icon_by_name, get_icon_size_px
from ..management.commands.creme_populate import Command as PopulateCommand
from ..models import (
CremeEntity,
CremePropertyType,
CremeUser,
DeletionCommand,
Expand Down Expand Up @@ -579,7 +580,9 @@ def build_filedata(content, suffix='.txt'):
# def build_merge_url(self, entity1, entity2):
@staticmethod
def build_merge_url(entity1, entity2):
return reverse('creme_core__merge_entities') + f'?id1={entity1.id}&id2={entity2.id}'
id1 = entity1.id if isinstance(entity1, CremeEntity) else entity1
id2 = entity2.id if isinstance(entity2, CremeEntity) else entity2
return reverse('creme_core__merge_entities') + f'?id1={id1}&id2={id2}'

def build_request(self, url='/', user=None):
request = self.request_factory.get(url)
Expand Down
16 changes: 16 additions & 0 deletions creme/creme_core/tests/views/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,22 @@ def test_error03(self):
orga = FakeOrganisation.objects.create(user=user, name='Genshiken')
self.assertGET409(self.build_merge_url(orga, orga))

def test_error04(self):
"One entity does not exist."
user = self.login()
orga = FakeOrganisation.objects.create(user=user, name='Genshiken')

response1 = self.client.get(self.build_merge_url(orga, self.UNUSED_PK))
msg = _(
'One entity you want to merge does not exist anymore '
'(have you already performed the merge?)'
)
self.assertContains(response1, msg, status_code=404, html=True)

# ---
response2 = self.client.get(self.build_merge_url(self.UNUSED_PK, orga))
self.assertContains(response2, msg, status_code=404, html=True)

def test_perm01(self):
user = self.login(is_superuser=False)

Expand Down
9 changes: 6 additions & 3 deletions creme/creme_core/views/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

################################################################################
# Creme is a free/open-source Customer Relationship Management software
# Copyright (C) 2009-2022 Hybird
# Copyright (C) 2009-2023 Hybird
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -605,8 +605,11 @@ def get_entities(self):
try:
entity1 = entities_per_id[entity1_id]
entity2 = entities_per_id[entity2_id]
except IndexError as e:
raise Http404(f'Entity not found: {e}') from e
except KeyError as e:
raise Http404(gettext(
'One entity you want to merge does not exist anymore '
'(have you already performed the merge?)'
)) from e

if entity1.entity_type_id != entity2.entity_type_id:
raise ConflictError('You can not merge entities of different types.')
Expand Down

0 comments on commit 8f4f70a

Please sign in to comment.