From b4698f3fdca38c4113689b73b7d547d3272a305f Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sat, 19 Jan 2019 14:22:30 +0100 Subject: [PATCH] fix case sensitive irc channel uniqueness check --- src/teams/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/teams/models.py b/src/teams/models.py index f9341ace..77458fe9 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -147,15 +147,15 @@ class Team(CampRelatedModel): if self.private_irc_channel_name == settings.IRCBOT_PUBLIC_CHANNEL or self.private_irc_channel_name == settings.IRCBOT_VOLUNTEER_CHANNEL: raise ValidationError('The private IRC channel name is reserved') - # make sure public_irc_channel_name is unique + # make sure public_irc_channel_name is not in use as public or private irc channel for another team, case insensitive if self.public_irc_channel_name: - if Team.objects.filter(private_irc_channel_name__iexact=self.public_irc_channel_name).exclude(pk=self.pk).exists(): - raise ValidationError('The public IRC channel name is already in use!') + if Team.objects.filter(private_irc_channel_name__iexact=self.public_irc_channel_name).exclude(pk=self.pk).exists() or Team.objects.filter(public_irc_channel_name__iexact=self.public_irc_channel_name).exclude(pk=self.pk).exists(): + raise ValidationError('The public IRC channel name is already in use on another team!') - # make sure private_irc_channel_name is unique + # make sure private_irc_channel_name is not in use as public or private irc channel for another team, case insensitive if self.private_irc_channel_name: - if Team.objects.filter(public_irc_channel_name__iexact=self.private_irc_channel_name).exclude(pk=self.pk).exists(): - raise ValidationError('The private IRC channel name is already in use!') + if Team.objects.filter(private_irc_channel_name__iexact=self.private_irc_channel_name).exclude(pk=self.pk).exists() or Team.objects.filter(public_irc_channel_name__iexact=self.private_irc_channel_name).exclude(pk=self.pk).exists(): + raise ValidationError('The private IRC channel name is already in use on another team!') @property def memberships(self):