-
Notifications
You must be signed in to change notification settings - Fork 299
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
Improve APIs for creating/updating direct paging integrations #2603
Conversation
@staticmethod | ||
def validate_integration(integration): | ||
if integration is None or integration not in AlertReceiveChannel.WEB_INTEGRATION_CHOICES: | ||
raise BadRequest(detail="invalid integration") | ||
return integration | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
team_lookup = {} | ||
if "team" in request.data: | ||
team_public_pk = request.data.get("team", None) | ||
if team_public_pk is not None: | ||
try: | ||
team = user.available_teams.get(public_primary_key=team_public_pk) | ||
team_lookup = {"team": team} | ||
except Team.DoesNotExist: | ||
return Response(data="invalid team", status=status.HTTP_400_BAD_REQUEST) | ||
else: | ||
team_lookup = {"team__isnull": True} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this team check completely, as it seems to be excessive – only admins can create integrations, and every team is available for admins.
if request.data["integration"] == AlertReceiveChannel.INTEGRATION_DIRECT_PAGING: | ||
try: | ||
AlertReceiveChannel.objects.get( | ||
organization=organization, | ||
integration=AlertReceiveChannel.INTEGRATION_DIRECT_PAGING, | ||
deleted_at=None, | ||
**team_lookup, | ||
) | ||
return Response( | ||
data="Direct paging integration already exists for this team", | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
except AlertReceiveChannel.DoesNotExist: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is now performed in the appropriate serializer.
try: | ||
instance = AlertReceiveChannel.create( | ||
**validated_data, | ||
author=self.context["request"].user, | ||
organization=organization, | ||
) | ||
except AlertReceiveChannel.DuplicateDirectPaging: | ||
raise DuplicateDirectPagingBadRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure that direct paging integrations are unique per team in public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What this PR does
Checklist
pr:no public docs
PR label added if not required)CHANGELOG.md
updated (orpr:no changelog
PR label added if not required)