-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboards): add new endpoint for favourite dashboards (#81438)
1. Add new endpoint for favouriting dashboards (supports `PUT` req) 2. Return `isFavourite` field in `DashboardDetails` endpoint's `GET` request #78023 --------- Co-authored-by: harshithadurai <[email protected]> Co-authored-by: Nar Saynorath <[email protected]>
- Loading branch information
1 parent
b6edfcb
commit cbadcc6
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -418,6 +418,63 @@ def test_dashboard_details_data_returns_permissions_with_teams(self): | |
assert "teamsWithEditAccess" in response.data["permissions"] | ||
assert response.data["permissions"]["teamsWithEditAccess"] == [team1.id, team2.id] | ||
|
||
def test_get_favorited_user_status(self): | ||
self.user_1 = self.create_user(email="[email protected]") | ||
self.user_2 = self.create_user(email="[email protected]") | ||
self.create_member(user=self.user_1, organization=self.organization) | ||
self.create_member(user=self.user_2, organization=self.organization) | ||
|
||
self.dashboard.favorited_by = [self.user_1.id, self.user_2.id] | ||
|
||
self.login_as(user=self.user_1) | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request("get", self.url(self.dashboard.id)) | ||
assert response.status_code == 200 | ||
assert response.data["isFavorited"] is True | ||
|
||
def test_get_not_favorited_user_status(self): | ||
self.user_1 = self.create_user(email="[email protected]") | ||
self.create_member(user=self.user_1, organization=self.organization) | ||
self.dashboard.favorited_by = [self.user_1.id, self.user.id] | ||
|
||
user_3 = self.create_user() | ||
self.create_member(user=user_3, organization=self.organization) | ||
self.login_as(user=user_3) | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request("get", self.url(self.dashboard.id)) | ||
assert response.status_code == 200 | ||
assert response.data["isFavorited"] is False | ||
|
||
def test_get_favorite_status_no_dashboard_edit_access(self): | ||
self.user_1 = self.create_user(email="[email protected]") | ||
self.user_2 = self.create_user(email="[email protected]") | ||
self.create_member(user=self.user_1, organization=self.organization) | ||
self.create_member(user=self.user_2, organization=self.organization) | ||
|
||
self.dashboard.favorited_by = [self.user_1.id, self.user_2.id, self.user.id] | ||
|
||
DashboardPermissions.objects.create(is_editable_by_everyone=False, dashboard=self.dashboard) | ||
self.login_as(user=self.user_2) | ||
dashboard_detail_put_url = reverse( | ||
"sentry-api-0-organization-dashboard-details", | ||
kwargs={ | ||
"organization_id_or_slug": self.organization.slug, | ||
"dashboard_id": self.dashboard.id, | ||
}, | ||
) | ||
with self.feature({"organizations:dashboards-edit-access": True}): | ||
response = self.do_request( | ||
"put", dashboard_detail_put_url, data={"title": "New Dashboard 9"} | ||
) | ||
# assert user cannot edit dashboard | ||
assert response.status_code == 403 | ||
|
||
# assert user can see if they favorited the dashboard | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request("get", self.url(self.dashboard.id)) | ||
assert response.status_code == 200 | ||
assert response.data["isFavorited"] is True | ||
|
||
|
||
class OrganizationDashboardDetailsDeleteTest(OrganizationDashboardDetailsTestCase): | ||
def test_delete(self): | ||
|
@@ -3220,3 +3277,72 @@ def test_visit_dashboard_no_access(self): | |
dashboard = Dashboard.objects.get(id=self.dashboard.id) | ||
assert dashboard.visits == 1 | ||
assert dashboard.last_visited == last_visited | ||
|
||
|
||
class OrganizationDashboardFavoriteTest(OrganizationDashboardDetailsTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
# Create two additional users | ||
self.user_1 = self.create_user(email="[email protected]") | ||
self.user_2 = self.create_user(email="[email protected]") | ||
self.create_member(user=self.user_1, organization=self.organization) | ||
self.create_member(user=self.user_2, organization=self.organization) | ||
|
||
# Both users have favorited the dashboard | ||
self.dashboard.favorited_by = [self.user_1.id, self.user_2.id] | ||
|
||
def url(self, dashboard_id): | ||
return reverse( | ||
"sentry-api-0-organization-dashboard-favorite", | ||
kwargs={ | ||
"organization_id_or_slug": self.organization.slug, | ||
"dashboard_id": dashboard_id, | ||
}, | ||
) | ||
|
||
# PUT tests | ||
def test_favorite_dashboard(self): | ||
assert self.user.id not in self.dashboard.favorited_by | ||
self.login_as(user=self.user) | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request( | ||
"put", self.url(self.dashboard.id), data={"isFavorited": "true"} | ||
) | ||
assert response.status_code == 204 | ||
assert self.user.id in self.dashboard.favorited_by | ||
|
||
def test_unfavorite_dashboard(self): | ||
assert self.user_1.id in self.dashboard.favorited_by | ||
self.login_as(user=self.user_1) | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request( | ||
"put", self.url(self.dashboard.id), data={"isFavorited": False} | ||
) | ||
assert response.status_code == 204 | ||
assert self.user_1.id not in self.dashboard.favorited_by | ||
|
||
def test_favorite_dashboard_no_dashboard_edit_access(self): | ||
DashboardPermissions.objects.create(is_editable_by_everyone=False, dashboard=self.dashboard) | ||
self.login_as(user=self.user_2) | ||
dashboard_detail_url = reverse( | ||
"sentry-api-0-organization-dashboard-details", | ||
kwargs={ | ||
"organization_id_or_slug": self.organization.slug, | ||
"dashboard_id": self.dashboard.id, | ||
}, | ||
) | ||
with self.feature({"organizations:dashboards-edit-access": True}): | ||
response = self.do_request( | ||
"put", dashboard_detail_url, data={"title": "New Dashboard 9"} | ||
) | ||
# assert user cannot edit dashboard | ||
assert response.status_code == 403 | ||
|
||
# assert if user can edit the favorite status of the dashboard | ||
assert self.user_2.id in self.dashboard.favorited_by | ||
with self.feature({"organizations:dashboards-favourite": True}): | ||
response = self.do_request( | ||
"put", self.url(self.dashboard.id), data={"isFavorited": False} | ||
) | ||
assert response.status_code == 204 | ||
assert self.user_2.id not in self.dashboard.favorited_by |