Skip to content

Commit e28c3f8

Browse files
committed
Use Team.create in create_team service
Utilize Team.create() in create_team service instead of using Team.objects.create(). This will create Team and Namespace as required and call the necesseary validation method in the model. Remove redundant error checks in the service as there is no need for double checking. Update imports in team forms.py. Refs. TS-2426
1 parent 5141df6 commit e28c3f8

File tree

2 files changed

+4
-8
lines changed
  • django/thunderstore

2 files changed

+4
-8
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from django.core.exceptions import ValidationError
21
from django.db import transaction
32

43
from thunderstore.account.models import ServiceAccount
54
from thunderstore.core.exceptions import PermissionValidationError
65
from thunderstore.core.types import UserType
7-
from thunderstore.repository.models import Namespace, Team, TeamMember
6+
from thunderstore.repository.models import Team, TeamMember
87
from thunderstore.repository.models.team import TeamMemberRole
98

109

@@ -21,12 +20,8 @@ def create_team(agent: UserType, team_name: str) -> Team:
2120
raise PermissionValidationError("Must be authenticated to create teams")
2221
if getattr(agent, "service_account", None) is not None:
2322
raise PermissionValidationError("Service accounts cannot create teams")
24-
if Team.objects.filter(name__iexact=team_name).exists():
25-
raise ValidationError("Team with this Name already exists")
26-
if Namespace.objects.filter(name__iexact=team_name).exists():
27-
raise ValidationError("Team with this Namespace already exists")
2823

29-
team = Team.objects.create(name=team_name)
24+
team = Team.create(name=team_name)
3025
team.add_member(user=agent, role=TeamMemberRole.owner)
3126
return team
3227

django/thunderstore/repository/forms/team.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django import forms
44
from django.contrib.auth import get_user_model
55
from django.core.exceptions import ObjectDoesNotExist, ValidationError
6+
from django.db import transaction
67

78
from thunderstore.api.cyberstorm.services.team import (
89
create_team,
@@ -12,7 +13,7 @@
1213
update_team_member,
1314
)
1415
from thunderstore.core.types import UserType
15-
from thunderstore.repository.models import Team, TeamMember, TeamMemberRole, transaction
16+
from thunderstore.repository.models import Team, TeamMember, TeamMemberRole
1617
from thunderstore.repository.validators import PackageReferenceComponentValidator
1718

1819
User = get_user_model()

0 commit comments

Comments
 (0)