Merge pull request #1050 from ae-utbm/merge_same_users

Check that a user cannot be merged into itself
This commit is contained in:
Kenneth Soares 2025-03-28 15:01:26 +01:00 committed by GitHub
commit 15d541b596
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 15 deletions

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-25 16:38+0100\n" "POT-Creation-Date: 2025-03-28 13:51+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -935,10 +935,6 @@ msgstr "rôle"
msgid "description" msgid "description"
msgstr "description" msgstr "description"
#: club/models.py
msgid "past member"
msgstr "ancien membre"
#: club/models.py #: club/models.py
msgid "Email address" msgid "Email address"
msgstr "Adresse email" msgstr "Adresse email"
@ -2837,6 +2833,7 @@ msgid "Users"
msgstr "Utilisateurs" msgstr "Utilisateurs"
#: core/templates/core/search.jinja core/views/user.py #: core/templates/core/search.jinja core/views/user.py
#: counter/templates/counter/product_list.jinja
msgid "Clubs" msgid "Clubs"
msgstr "Clubs" msgstr "Clubs"
@ -3182,7 +3179,7 @@ msgid "Bans"
msgstr "Bans" msgstr "Bans"
#: core/templates/core/user_tools.jinja counter/forms.py #: core/templates/core/user_tools.jinja counter/forms.py
#: counter/views/mixins.py #: counter/templates/counter/product_list.jinja counter/views/mixins.py
msgid "Counters" msgid "Counters"
msgstr "Comptoirs" msgstr "Comptoirs"
@ -3338,8 +3335,8 @@ msgstr "Nom d'utilisateur, email, ou numéro de compte AE"
#: core/views/forms.py #: core/views/forms.py
msgid "" msgid ""
"Profile: you need to be visible on the picture, in order to be recognized " "Profile: you need to be visible on the picture, in order to be recognized (e."
"(e.g. by the barmen)" "g. by the barmen)"
msgstr "" msgstr ""
"Photo de profil: vous devez être visible sur la photo afin d'être reconnu " "Photo de profil: vous devez être visible sur la photo afin d'être reconnu "
"(par exemple par les barmen)" "(par exemple par les barmen)"
@ -3949,8 +3946,8 @@ msgstr ""
#: counter/templates/counter/mails/account_dump.jinja #: counter/templates/counter/mails/account_dump.jinja
msgid "If you think this was a mistake, please mail us at ae@utbm.fr." msgid "If you think this was a mistake, please mail us at ae@utbm.fr."
msgstr "" msgstr ""
"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à " "Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à ae@utbm."
"ae@utbm.fr." "fr."
#: counter/templates/counter/mails/account_dump.jinja #: counter/templates/counter/mails/account_dump.jinja
msgid "" msgid ""
@ -5120,6 +5117,10 @@ msgstr "Utilisateur qui sera conservé"
msgid "User that will be deleted" msgid "User that will be deleted"
msgstr "Utilisateur qui sera supprimé" msgstr "Utilisateur qui sera supprimé"
#: rootplace/forms.py
msgid "You cannot merge two identical users."
msgstr "Vous ne pouvez pas fusionner deux utilisateurs identiques."
#: rootplace/forms.py #: rootplace/forms.py
msgid "User to be selected" msgid "User to be selected"
msgstr "Utilisateur à sélectionner" msgstr "Utilisateur à sélectionner"
@ -5219,15 +5220,15 @@ msgstr "SAS"
msgid "Albums" msgid "Albums"
msgstr "Albums" msgstr "Albums"
#: sas/templates/sas/album.jinja
msgid "Download album"
msgstr "Télécharger l'album"
#: sas/templates/sas/album.jinja sas/templates/sas/macros.jinja #: sas/templates/sas/album.jinja sas/templates/sas/macros.jinja
#: sas/templates/sas/user_pictures.jinja #: sas/templates/sas/user_pictures.jinja
msgid "To be moderated" msgid "To be moderated"
msgstr "A modérer" msgstr "A modérer"
#: sas/templates/sas/album.jinja
msgid "Download album"
msgstr "Télécharger l'album"
#: sas/templates/sas/album.jinja #: sas/templates/sas/album.jinja
msgid "Upload" msgid "Upload"
msgstr "Envoyer" msgstr "Envoyer"
@ -6042,3 +6043,6 @@ msgstr "Vous ne pouvez plus écrire de commentaires, la date est passée."
#, python-format #, python-format
msgid "Maximum characters: %(max_length)s" msgid "Maximum characters: %(max_length)s"
msgstr "Nombre de caractères max: %(max_length)s" msgstr "Nombre de caractères max: %(max_length)s"
#~ msgid "past member"
#~ msgstr "ancien membre"

View File

@ -7,7 +7,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-25 16:10+0100\n" "POT-Creation-Date: 2025-03-28 13:52+0100\n"
"PO-Revision-Date: 2024-09-17 11:54+0200\n" "PO-Revision-Date: 2024-09-17 11:54+0200\n"
"Last-Translator: Sli <antoine@bartuccio.fr>\n" "Last-Translator: Sli <antoine@bartuccio.fr>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -34,6 +34,7 @@ msgid "Delete"
msgstr "Supprimer" msgstr "Supprimer"
#: com/static/bundled/com/components/moderation-alert-index.ts #: com/static/bundled/com/components/moderation-alert-index.ts
#, javascript-format
msgid "" msgid ""
"This event will take place every week for %s weeks. If you publish or delete " "This event will take place every week for %s weeks. If you publish or delete "
"this event, it will also be published (or deleted) for the following weeks." "this event, it will also be published (or deleted) for the following weeks."

View File

@ -1,4 +1,5 @@
from django import forms from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from core.models import User, UserBan from core.models import User, UserBan
@ -22,6 +23,16 @@ class MergeForm(forms.Form):
queryset=User.objects.all(), queryset=User.objects.all(),
) )
def clean(self):
cleaned_data = super().clean()
user1 = cleaned_data.get("user1")
user2 = cleaned_data.get("user2")
if user1.id == user2.id:
raise ValidationError(_("You cannot merge two identical users."))
return cleaned_data
class SelectUserForm(forms.Form): class SelectUserForm(forms.Form):
user = forms.ModelChoiceField( user = forms.ModelChoiceField(

View File

@ -22,6 +22,7 @@ from django.utils.timezone import localtime, now
from club.models import Club from club.models import Club
from core.models import Group, User from core.models import Group, User
from counter.models import Counter, Customer, Product, Refilling, Selling from counter.models import Counter, Customer, Product, Refilling, Selling
from rootplace.forms import MergeForm
from subscription.models import Subscription from subscription.models import Subscription
@ -79,6 +80,15 @@ class TestMergeUser(TestCase):
sas_admin.id, sas_admin.id,
} }
def test_identical_accounts(self):
form = MergeForm(data={"user1": self.to_keep.id, "user2": self.to_keep.id})
assert not form.is_valid()
assert "__all__" in form.errors
assert (
"Vous ne pouvez pas fusionner deux utilisateurs identiques."
in form.errors["__all__"]
)
def test_both_subscribers_and_with_account(self): def test_both_subscribers_and_with_account(self):
Customer(user=self.to_keep, account_id="11000l", amount=0).save() Customer(user=self.to_keep, account_id="11000l", amount=0).save()
Customer(user=self.to_delete, account_id="12000m", amount=0).save() Customer(user=self.to_delete, account_id="12000m", amount=0).save()