-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(dashboards): POC for sharing dashboards #82455
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
Draft
harshithadurai
wants to merge
2
commits into
master
Choose a base branch
from
harshi/shared-widget-endpoint-poc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from drf_spectacular.utils import OpenApiParameter, extend_schema | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
from sentry.api.api_owners import ApiOwner | ||
from sentry.api.base import Endpoint, region_silo_endpoint | ||
from sentry.apidocs.constants import RESPONSE_NOT_FOUND | ||
from sentry.apidocs.parameters import GlobalParams | ||
|
||
|
||
@region_silo_endpoint | ||
class SharedDashboardDetailsEndpoint(Endpoint): | ||
owner = ApiOwner.PERFORMANCE | ||
# publish_status = { | ||
# "GET": ApiPublishStatus.UNKNOWN, | ||
# } | ||
permission_classes = () | ||
|
||
@extend_schema( | ||
operation_id="Retrieve an Organization's Custom Dashboard", | ||
parameters=[ | ||
GlobalParams.ORG_ID_OR_SLUG, | ||
OpenApiParameter(name="share_id", type=str), | ||
], | ||
responses={ | ||
404: RESPONSE_NOT_FOUND, | ||
}, | ||
) | ||
def get( | ||
self, | ||
request: Request, | ||
organization_id_or_slug: int | str | None = None, | ||
share_id: str | None = None, | ||
) -> Response: | ||
""" | ||
Retrieve a shared dashboard | ||
""" | ||
# print("shared dashboard endpoint") | ||
|
||
# dashboard = Dashboard.objects.first() | ||
data = [] | ||
# data = serialize( | ||
# dashboard, request.user, serializer=SharedDashboardDetailsModelSerializer() | ||
# ) | ||
return self.respond(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from drf_spectacular.utils import OpenApiParameter, extend_schema | ||
from rest_framework.permissions import AllowAny | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
from sentry.api.api_owners import ApiOwner | ||
from sentry.api.base import Endpoint, region_silo_endpoint | ||
from sentry.api.endpoints.organization_events_stats import OrganizationEventsStatsEndpoint | ||
from sentry.apidocs.constants import RESPONSE_NOT_FOUND | ||
from sentry.apidocs.parameters import GlobalParams | ||
from sentry.models.organization import Organization | ||
|
||
|
||
@region_silo_endpoint | ||
class SharedWidgetDetailsEndpoint(Endpoint): | ||
owner = ApiOwner.PERFORMANCE | ||
authentication_classes = [] | ||
permission_classes = (AllowAny,) | ||
|
||
@extend_schema( | ||
operation_id="Retrieve an Organization's Custom Dashboard", | ||
parameters=[ | ||
GlobalParams.ORG_ID_OR_SLUG, | ||
OpenApiParameter(name="share_id", type=str), | ||
], | ||
responses={ | ||
404: RESPONSE_NOT_FOUND, | ||
}, | ||
) | ||
def get( | ||
self, | ||
request: Request, | ||
organization_id_or_slug: int | str | None = None, | ||
share_id: str | None = None, | ||
widget_id: str | None = None, | ||
) -> Response: | ||
""" | ||
Retrieve events data for a singular widget with widget_id | ||
""" | ||
try: | ||
# Fetch the organization | ||
organization = Organization.objects.get( | ||
id=1, | ||
) | ||
|
||
class MockAccess: | ||
def __init__(self, organization): | ||
self.organization = organization | ||
self.scopes = ["org:read"] | ||
|
||
def has_permission(self, permission): | ||
return True | ||
|
||
def has_project_access(self, project): | ||
return True | ||
|
||
def has_team_access(self, team): | ||
return True | ||
|
||
def has_scope(self, scope): | ||
return True | ||
|
||
request.access = MockAccess(organization) | ||
|
||
request.GET = request.GET.copy() | ||
request.GET.setlist("field", ["issue", "title", "count_unique(user)"]) | ||
request.GET.update( | ||
{ | ||
"name": "", | ||
"onDemandType": "dynamic_query", | ||
"per_page": "20", | ||
"project": "1", | ||
"query": "", | ||
"referrer": "api.dashboards.tablewidget", | ||
"sort": "-count_unique(user)", | ||
"statsPeriod": "14d", | ||
"useOnDemandMetrics": "false", | ||
"yAxis": "count_unique(user)", | ||
} | ||
) | ||
|
||
# Create an instance of OrganizationEventsStatsEndpoint | ||
events_stats_endpoint = OrganizationEventsStatsEndpoint() | ||
|
||
# Call the get method | ||
stats_response = events_stats_endpoint.get( | ||
request=request, | ||
organization=organization, | ||
) | ||
return stats_response | ||
|
||
except Organization.DoesNotExist: | ||
return Response({"detail": "Organization not found"}, status=404) | ||
except Exception as e: | ||
return Response({"error": str(e)}, status=400) | ||
|
||
return self.respond({"sample:": "test"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/sentry/api/endpoints/test_shared_dashboard_details.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
from django.urls import reverse | ||
|
||
from sentry.models.dashboard import Dashboard | ||
from sentry.testutils.cases import APITestCase | ||
|
||
|
||
class SharedDashboardDetailsGetTest(APITestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.dashboard_2 = Dashboard.objects.create( | ||
title="Dashboard 2", created_by_id=self.user.id, organization=self.organization | ||
) | ||
|
||
def url(self): | ||
return reverse( | ||
"sentry-api-0-shared-dashboard-details", | ||
kwargs={ | ||
"organization_id_or_slug": self.organization.slug, | ||
# hardcoded for now | ||
"share_id": 2, | ||
}, | ||
) | ||
|
||
def do_request(self, method, url, data=None): | ||
func = getattr(self.client, method) | ||
return func(url, data=data) | ||
|
||
def test_get(self): | ||
# the endpoint should return a limited version of dashboard details (dashboard_2 for now) | ||
|
||
self.client.logout() # ?? | ||
response = self.do_request("get", self.url()) | ||
|
||
# print(response.data, "7878") | ||
assert response.status_code == 208, response.content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from django.urls import reverse | ||
|
||
from sentry.models.dashboard import Dashboard | ||
from sentry.models.dashboard_widget import ( | ||
DashboardWidget, | ||
DashboardWidgetDisplayTypes, | ||
DashboardWidgetTypes, | ||
) | ||
from sentry.testutils.cases import APITestCase | ||
|
||
|
||
class SharedWidgetDetailsGetTest(APITestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.dashboard_2 = Dashboard.objects.create( | ||
title="Dashboard 2", created_by_id=self.user.id, organization=self.organization | ||
) | ||
DashboardWidget.objects.create( | ||
dashboard=self.dashboard_2, | ||
order=0, | ||
title="Widget 1", | ||
display_type=DashboardWidgetDisplayTypes.LINE_CHART, | ||
widget_type=DashboardWidgetTypes.DISCOVER, | ||
interval="1d", | ||
) | ||
|
||
def url(self): | ||
return reverse( | ||
"sentry-api-0-shared-widget-details", | ||
kwargs={ | ||
"organization_id_or_slug": self.organization.slug, | ||
# hardcoded for now | ||
"share_id": 2, | ||
"widget_id": 1, | ||
}, | ||
) | ||
|
||
def do_request(self, method, url, data=None): | ||
func = getattr(self.client, method) | ||
return func(url, data=data) | ||
|
||
def test_get(self): | ||
# the endpoint should return the events data for the widget (dashboard_2 for now) | ||
|
||
# self.client.logout() # ?? | ||
response = self.do_request("get", self.url()) | ||
|
||
# print(response.data, "7878") | ||
assert response.status_code == 208, response.content |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Copilot Autofix
AI 7 months ago
To fix the problem, we should log the detailed exception message on the server and return a generic error message to the user. This approach ensures that sensitive information is not exposed to the user while still allowing developers to access the necessary details for debugging.