Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions django/thunderstore/api/cyberstorm/services/team.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.core.exceptions import ValidationError
from django.db import transaction

from thunderstore.account.models import ServiceAccount
from thunderstore.core.exceptions import PermissionValidationError
from thunderstore.core.types import UserType
from thunderstore.repository.models import Team, TeamMember
from thunderstore.repository.models.namespace import Namespace
from thunderstore.repository.models.team import TeamMemberRole


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

team = Team.create(name=team_name)
team.add_member(user=agent, role=TeamMemberRole.owner)
Expand Down
Loading