-
Notifications
You must be signed in to change notification settings - Fork 279
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
Add openAPI schema for some internal endpoints #5037
base: dev
Are you sure you want to change the base?
Conversation
- /escalation_chain - /escalation_policy - /channel_filter - /user_notification_policy
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.
great job 👍
def _get_slack_channel(self, obj) -> SlackChannelDetails | None: | ||
if obj.slack_channel_id is not None: | ||
slack_team_identity = self.context["request"].auth.organization.slack_team_identity | ||
if slack_team_identity is not None: | ||
slack_channel = slack_team_identity.get_cached_channels(slack_id=obj.slack_channel_id).first() | ||
if slack_channel: | ||
result["slack_channel"] = { | ||
return { | ||
"display_name": slack_channel.name, | ||
"slack_id": obj.slack_channel_id, | ||
"slack_id": slack_channel.slack_id, | ||
"id": slack_channel.public_primary_key, | ||
} | ||
return None |
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.
nit: invert IFs to reduce nesting
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.
user_id = self.request.query_params.get("user") | ||
slack_channel_id = self.request.query_params.get("slack_channel") | ||
channel_filter_id = self.request.query_params.get("channel_filter") |
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.
I think these are no longer used, can we remove them?
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.
They have been already removed
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.
I mean that frontend/mobile app don't seem to use these filters, can we remove them?
engine/common/api_helpers/filters.py
Outdated
@@ -66,6 +67,13 @@ class MultipleChoiceCharFilter(filters.ModelMultipleChoiceFilter): | |||
pass | |||
|
|||
|
|||
@extend_schema_field(serializers.CharField) | |||
class ModelChoiceCharFilter(filters.ModelChoiceFilter): |
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.
maybe call it ModelChoicePublicPrimaryKeyFilter
so it's easier to understand what it's used for? can also add a default to_field_name="public_primary_key"
in there
|
||
@extend_schema_view( | ||
list=extend_schema(responses=ChannelFilterSerializer), | ||
retrieve=extend_schema(responses=ChannelFilterRetrieveResponseSerializer), |
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.
can this be just ChannelFilterSerializer
?
@@ -218,3 +220,15 @@ def update(self, instance, validated_data): | |||
raise BadRequest(detail="Filtering term of default channel filter cannot be changed") | |||
|
|||
return super().update(instance, validated_data) | |||
|
|||
|
|||
class ChannelFilterRetrieveResponseSerializer(ChannelFilterUpdateSerializer): |
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.
maybe ChannelFilterUpdateResponseSerializer
would be a better name here? this way it indicates that it's a response from update/create, not retrieve
"/channel_filters", | ||
"/escalation_chains", | ||
"/escalation_policies", | ||
"/notification_policies", |
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.
might be a good idea to re-generate frontend types and commit them in this PR as well
def _get_slack_channel(self, obj) -> SlackChannelDetails | None: | ||
if obj.slack_channel_id is None: | ||
return None | ||
slack_team_identity = self.context["request"].auth.organization.slack_team_identity | ||
if slack_team_identity is not None: | ||
slack_channel = slack_team_identity.get_cached_channels(slack_id=obj.slack_channel_id).first() | ||
if slack_channel: | ||
return { | ||
"display_name": slack_channel.name, | ||
"slack_id": slack_channel.slack_id, | ||
"id": slack_channel.public_primary_key, | ||
} | ||
return None |
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.
def _get_slack_channel(self, obj) -> SlackChannelDetails | None: | |
if obj.slack_channel_id is None: | |
return None | |
slack_team_identity = self.context["request"].auth.organization.slack_team_identity | |
if slack_team_identity is not None: | |
slack_channel = slack_team_identity.get_cached_channels(slack_id=obj.slack_channel_id).first() | |
if slack_channel: | |
return { | |
"display_name": slack_channel.name, | |
"slack_id": slack_channel.slack_id, | |
"id": slack_channel.public_primary_key, | |
} | |
return None | |
def _get_slack_channel(self, obj) -> SlackChannelDetails | None: | |
if obj.slack_channel_id is None: | |
return None | |
slack_team_identity = self.context["request"].auth.organization.slack_team_identity | |
if slack_team_identity is None: | |
return None | |
slack_channel = slack_team_identity.get_cached_channels(slack_id=obj.slack_channel_id).first() | |
if slack_channel is None: | |
return None | |
return { | |
"display_name": slack_channel.name, | |
"slack_id": slack_channel.slack_id, | |
"id": slack_channel.public_primary_key, | |
} |
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.
check out https://youtu.be/CFRhGnuXG-4?si=WhR8vxKXXN0t7a22 for inspiration 😄
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.
I think we should revert the pnpm generate-types
commit and run that in the packages/grafana-oncall-app
directory of grafana/irm
instead.
cc: @brojd
What this PR does
Adds openAPI schema for following endpoints:
Which issue(s) this PR closes
Related to https://github.com/grafana/oncall-private/issues/2457
Checklist
pr:no public docs
PR label added if not required)release:
). These labels dictate how your PR willshow up in the autogenerated release notes.