Skip to content
Draft
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
5 changes: 5 additions & 0 deletions src/sentry/core/endpoints/organization_member_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def validate_teams(self, teams: list[Team]) -> list[Team]:
return valid_teams

def validate_teamRoles(self, teamRoles: list[dict[str, Any]]) -> list[tuple[Team, str]]:
for item in teamRoles:
if not isinstance(item, dict) or "role" not in item or "teamSlug" not in item:
raise serializers.ValidationError(
"Each team-role entry must be an object with 'teamSlug' and 'role' keys"
)
roles = {item["role"] for item in teamRoles}
valid_roles = [r.id for r in team_roles.get_all()] + [None]
if roles.difference(valid_roles):
Expand Down
21 changes: 21 additions & 0 deletions tests/sentry/core/endpoints/test_organization_member_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,27 @@ def test_invalid_team_role(self) -> None:
assert not serializer.is_valid()
assert serializer.errors == {"teamRoles": ["Invalid team-role"]}

def test_team_role_missing_keys(self) -> None:
context = {"organization": self.organization, "allowed_roles": [roles.get("member")]}
for bad_item in (
{"teamSlug": self.team.slug},
{"role": "contributor"},
{},
"not-a-dict",
):
data = {
"email": "user@example.com",
"orgRole": "member",
"teamRoles": [bad_item],
}
serializer = OrganizationMemberRequestSerializer(context=context, data=data)
assert not serializer.is_valid()
assert serializer.errors == {
"teamRoles": [
"Each team-role entry must be an object with 'teamSlug' and 'role' keys"
]
}

@with_feature("organizations:invite-billing")
def test_valid_invite_billing_member(self) -> None:
context = {"organization": self.organization, "allowed_roles": [roles.get("member")]}
Expand Down
Loading