Skip to content

Commit

Permalink
FIX API DELETE /api/teams/:teamId/groups?groupId=external-group-id
Browse files Browse the repository at this point in the history
Grafana introduced a breaking change in 10.2.0 :
grafana/grafana#76325
This fix handles it.
  • Loading branch information
Gilles Hamel authored and amotl committed Mar 7, 2024
1 parent c1dc3f7 commit 248792d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion grafana_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
self.user = User(self.client)
self.users = Users(self.client)
self.rbac = Rbac(self.client)
self.teams = Teams(self.client)
self.teams = Teams(self.client, self)
self.annotations = Annotations(self.client)
self.snapshots = Snapshots(self.client)
self.notifications = Notifications(self.client)
Expand Down
12 changes: 10 additions & 2 deletions grafana_client/elements/team.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import typing as t
import warnings

from verlib2 import Version

from ..model import PersonalPreferences
from .base import Base

VERSION_10_2_0 = Version("10.2.0")


class Teams(Base):
def __init__(self, client):
def __init__(self, client, api):
super(Teams, self).__init__(client)
self.client = client
self.api = api

def search_teams(self, query=None, page=None, perpage=None):
"""
Expand Down Expand Up @@ -215,6 +220,9 @@ def remove_team_external_group(self, team_id, group_id):
:param group_id:
:return:
"""
team_group_path = "/teams/%s/groups?groupId=%s" % (team_id, group_id)
if Version(self.api.version) < VERSION_10_2_0:
team_group_path = "/teams/%s/groups/%s" % (team_id, group_id)
else:
team_group_path = "/teams/%s/groups?groupId=%s" % (team_id, group_id)
r = self.client.DELETE(team_group_path)
return r
21 changes: 20 additions & 1 deletion test/elements/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,29 @@ def test_add_team_external_group(self, m):
self.assertEqual(r["message"], "Group added to Team")

@requests_mock.Mocker()
def test_remove_team_external_group(self, m):
def test_remove_team_external_group_grafana_1020(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.0"},
)

m.delete(
"http://localhost/api/teams/42/groups?groupId=a_external_group",
json={"message": "Team group removed"},
)
r = self.grafana.teams.remove_team_external_group("42", "a_external_group")
self.assertEqual(r["message"], "Team group removed")

@requests_mock.Mocker()
def test_remove_team_external_group(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.1.0"},
)

m.delete(
"http://localhost/api/teams/42/groups/a_external_group",
json={"message": "Team group removed"},
)
r = self.grafana.teams.remove_team_external_group("42", "a_external_group")
self.assertEqual(r["message"], "Team group removed")

0 comments on commit 248792d

Please sign in to comment.