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):