1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

Cannot set username that is similar to an alias we don't own

This commit is contained in:
Yohann D'ANELLO
2020-02-17 11:21:05 +01:00
parent 6a4e0de444
commit 3ce5f31411
2 changed files with 34 additions and 3 deletions

View File

@ -85,7 +85,7 @@ class Note(PolymorphicModel):
"""
Verify alias (simulate save)
"""
aliases = Alias.objects.filter(name=str(self))
aliases = Alias.objects.filter(normalized_name=Alias.normalize(str(self)))
if aliases.exists():
# Alias exists, so check if it is linked to this note
if aliases.first().note != self:
@ -233,3 +233,8 @@ class Alias(models.Model):
'already exists.'))
except Alias.DoesNotExist:
pass
def delete(self, using=None, keep_parents=False):
if self.name == str(self.note):
raise ValidationError(_("You can't delete your main alias."))
return super().delete(using, keep_parents)