Use team uid for team group actions (#103415)
* use team uid for team group actions * add constructor for tests; rename vars for clarity * github told me to do this
This commit is contained in:
@@ -25,13 +25,13 @@ type Service interface {
|
||||
}
|
||||
|
||||
func UIDToIDHandler(teamService Service) func(ctx context.Context, orgID int64, resourceID string) (string, error) {
|
||||
return func(ctx context.Context, orgID int64, resourceID string) (string, error) {
|
||||
// if teamID is empty or is an integer, we assume it's a team id and we don't need to resolve it
|
||||
_, err := strconv.ParseInt(resourceID, 10, 64)
|
||||
if resourceID == "" || err == nil {
|
||||
return resourceID, nil
|
||||
return func(ctx context.Context, orgID int64, teamIDorUID string) (string, error) {
|
||||
// if teamIDorUID is empty or is an integer, we assume it's a team ID, and we don't need to resolve it
|
||||
_, err := strconv.ParseInt(teamIDorUID, 10, 64)
|
||||
if teamIDorUID == "" || err == nil {
|
||||
return teamIDorUID, nil
|
||||
}
|
||||
team, err := teamService.GetTeamByID(ctx, &GetTeamByIDQuery{UID: resourceID, OrgID: orgID})
|
||||
team, err := teamService.GetTeamByID(ctx, &GetTeamByIDQuery{UID: teamIDorUID, OrgID: orgID})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -44,9 +44,9 @@ func MiddlewareTeamUIDResolver(teamService Service, paramName string) web.Handle
|
||||
handler := UIDToIDHandler(teamService)
|
||||
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
// Get team id from request, fetch team and replace teamId with team id
|
||||
teamID := web.Params(c.Req)[paramName]
|
||||
id, err := handler(c.Req.Context(), c.OrgID, teamID)
|
||||
// Get team id from request, fetch team and replace team UID with team ID
|
||||
teamIDorUID := web.Params(c.Req)[paramName]
|
||||
id, err := handler(c.Req.Context(), c.OrgID, teamIDorUID)
|
||||
if err == nil {
|
||||
gotParams := web.Params(c.Req)
|
||||
gotParams[paramName] = id
|
||||
|
||||
@@ -20,6 +20,12 @@ func NewFakeService() *FakeService {
|
||||
return &FakeService{}
|
||||
}
|
||||
|
||||
func NewFakeServiceWithTeamDTO(teamDTO *team.TeamDTO) *FakeService {
|
||||
return &FakeService{
|
||||
ExpectedTeamDTO: teamDTO,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FakeService) CreateTeam(ctx context.Context, cmd *team.CreateTeamCommand) (team.Team, error) {
|
||||
return s.ExpectedTeam, s.ExpectedError
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export function updateTeam(name: string, email: string): ThunkResult<void> {
|
||||
export function loadTeamGroups(): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const team = getStore().team.team;
|
||||
const response = await getBackendSrv().get(`/api/teams/${team.id}/groups`);
|
||||
const response = await getBackendSrv().get(`/api/teams/${team.uid}/groups`);
|
||||
dispatch(teamGroupsLoaded(response));
|
||||
};
|
||||
}
|
||||
@@ -126,7 +126,7 @@ export function loadTeamGroups(): ThunkResult<void> {
|
||||
export function addTeamGroup(groupId: string): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const team = getStore().team.team;
|
||||
await getBackendSrv().post(`/api/teams/${team.id}/groups`, { groupId: groupId });
|
||||
await getBackendSrv().post(`/api/teams/${team.uid}/groups`, { groupId: groupId });
|
||||
dispatch(loadTeamGroups());
|
||||
};
|
||||
}
|
||||
@@ -135,7 +135,7 @@ export function removeTeamGroup(groupId: string): ThunkResult<void> {
|
||||
return async (dispatch, getStore) => {
|
||||
const team = getStore().team.team;
|
||||
// need to use query parameter due to escaped characters in the request
|
||||
await getBackendSrv().delete(`/api/teams/${team.id}/groups?groupId=${encodeURIComponent(groupId)}`);
|
||||
await getBackendSrv().delete(`/api/teams/${team.uid}/groups?groupId=${encodeURIComponent(groupId)}`);
|
||||
dispatch(loadTeamGroups());
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user