-
Notifications
You must be signed in to change notification settings - Fork 309
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
Changes from all commits
9fc1f29
fcfc6f9
878d037
061d325
ace757f
81c15dd
d2514b9
becb7c0
06ed04d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
) | ||
from apps.api.throttlers import DemoAlertThrottler | ||
from apps.auth_token.auth import PluginAuthentication | ||
from apps.user_management.models.team import Team | ||
from common.api_helpers.exceptions import BadRequest | ||
from common.api_helpers.filters import ByTeamModelFieldFilterMixin, TeamModelMultipleChoiceFilter | ||
from common.api_helpers.mixins import ( | ||
|
@@ -104,42 +103,6 @@ class AlertReceiveChannelView( | |
"stop_maintenance": [RBACPermission.Permissions.INTEGRATIONS_WRITE], | ||
} | ||
|
||
def create(self, request, *args, **kwargs): | ||
organization = request.auth.organization | ||
user = request.user | ||
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} | ||
Comment on lines
-110
to
-120
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] is not None: | ||
if request.data["integration"] in AlertReceiveChannel.WEB_INTEGRATION_CHOICES: | ||
# Don't allow multiple Direct Paging integrations | ||
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 | ||
Comment on lines
-125
to
-138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is now performed in the appropriate serializer. |
||
return super().create(request, *args, **kwargs) | ||
|
||
return Response(data="invalid integration", status=status.HTTP_400_BAD_REQUEST) | ||
|
||
def perform_update(self, serializer): | ||
prev_state = serializer.instance.insight_logs_serialized | ||
serializer.save() | ||
|
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.
Simplified this bit, added a test