Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new Team with the same name should not propagate IntegrityError #934

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/aap_eda/api/serializers/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Meta:

def validate(self, data):
self.validate_shared_resource()
validators.check_if_team_name_exists(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msmagnanijr When this resource gets managed in the Gateway does it follow the same constraints?

data["name"], data["organization_id"]
)
return data


Expand Down
13 changes: 13 additions & 0 deletions src/aap_eda/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,16 @@ def check_credential_types(
raise serializers.ValidationError(
f"The type of credential can only be one of {names}"
)


def check_if_team_name_exists(name: str, organization_id: int):
if models.Team.objects.filter(
name=name, organization_id=organization_id
).exists():
raise serializers.ValidationError(
{
"name": [
"A team with this name already exists in the organization."
]
}
)
Loading