Skip to content

Commit 7cc1068

Browse files
authored
Merge pull request #1192 from thunderstore-io/team-creation-validation-checks
Add validation checks to create_team service
2 parents c2e25db + fa51e85 commit 7cc1068

File tree

1 file changed

+6
-0
lines changed
  • django/thunderstore/api/cyberstorm/services

1 file changed

+6
-0
lines changed

django/thunderstore/api/cyberstorm/services/team.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from django.core.exceptions import ValidationError
12
from django.db import transaction
23

34
from thunderstore.account.models import ServiceAccount
45
from thunderstore.core.exceptions import PermissionValidationError
56
from thunderstore.core.types import UserType
67
from thunderstore.repository.models import Team, TeamMember
8+
from thunderstore.repository.models.namespace import Namespace
79
from thunderstore.repository.models.team import TeamMemberRole
810

911

@@ -20,6 +22,10 @@ def create_team(agent: UserType, team_name: str) -> Team:
2022
raise PermissionValidationError("Must be authenticated to create teams")
2123
if getattr(agent, "service_account", None) is not None:
2224
raise PermissionValidationError("Service accounts cannot create teams")
25+
if Team.objects.filter(name__iexact=team_name).exists():
26+
raise ValidationError("Team with this name already exists")
27+
if Namespace.objects.filter(name__iexact=team_name).exists():
28+
raise ValidationError("Namespace with this name already exists")
2329

2430
team = Team.create(name=team_name)
2531
team.add_member(user=agent, role=TeamMemberRole.owner)

0 commit comments

Comments
 (0)