diff --git a/pkg/api/api.go b/pkg/api/api.go index 24183e63782..9d1151a757e 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -168,7 +168,7 @@ func (hs *HTTPServer) registerRoutes() { // team without requirement of user to be org admin apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) { teamsRoute.Get("/:teamId", Wrap(GetTeamByID)) - teamsRoute.Get("/search", Wrap(SearchTeams)) + teamsRoute.Get("/search", Wrap(hs.SearchTeams)) }) // org information available to all users. diff --git a/pkg/api/team.go b/pkg/api/team.go index eb7b1df37be..fd34c0ab720 100644 --- a/pkg/api/team.go +++ b/pkg/api/team.go @@ -81,7 +81,7 @@ func DeleteTeamByID(c *m.ReqContext) Response { } // GET /api/teams/search -func SearchTeams(c *m.ReqContext) Response { +func (hs *HTTPServer) SearchTeams(c *m.ReqContext) Response { perPage := c.QueryInt("perpage") if perPage <= 0 { perPage = 1000 @@ -92,7 +92,7 @@ func SearchTeams(c *m.ReqContext) Response { } var userIdFilter int64 - if c.QueryBool("showMine") { + if hs.Cfg.EditorsCanAdmin && c.OrgRole != m.ROLE_ADMIN { userIdFilter = c.SignedInUser.UserId } diff --git a/pkg/api/team_test.go b/pkg/api/team_test.go index a1984288870..cab59cc5f98 100644 --- a/pkg/api/team_test.go +++ b/pkg/api/team_test.go @@ -3,6 +3,8 @@ package api import ( "testing" + "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/models" @@ -20,6 +22,10 @@ func TestTeamApiEndpoint(t *testing.T) { TotalCount: 2, } + hs := &HTTPServer{ + Cfg: setting.NewCfg(), + } + Convey("When searching with no parameters", func() { loggedInUserScenario("When calling GET on", "/api/teams/search", func(sc *scenarioContext) { var sentLimit int @@ -33,7 +39,7 @@ func TestTeamApiEndpoint(t *testing.T) { return nil }) - sc.handlerFunc = SearchTeams + sc.handlerFunc = hs.SearchTeams sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec() So(sentLimit, ShouldEqual, 1000) @@ -60,7 +66,7 @@ func TestTeamApiEndpoint(t *testing.T) { return nil }) - sc.handlerFunc = SearchTeams + sc.handlerFunc = hs.SearchTeams sc.fakeReqWithParams("GET", sc.url, map[string]string{"perpage": "10", "page": "2"}).exec() So(sentLimit, ShouldEqual, 10) diff --git a/public/app/features/teams/state/actions.ts b/public/app/features/teams/state/actions.ts index bfccddeefc5..e2582839233 100644 --- a/public/app/features/teams/state/actions.ts +++ b/public/app/features/teams/state/actions.ts @@ -1,9 +1,8 @@ import { ThunkAction } from 'redux-thunk'; import { getBackendSrv } from 'app/core/services/backend_srv'; -import { OrgRole, StoreState, Team, TeamGroup, TeamMember } from 'app/types'; +import { StoreState, Team, TeamGroup, TeamMember } from 'app/types'; import { updateNavIndex, UpdateNavIndexAction } from 'app/core/actions'; import { buildNavModel } from './navModel'; -import { contextSrv } from '../../../core/services/context_srv'; export enum ActionTypes { LoadTeams = 'LOAD_TEAMS', @@ -86,8 +85,7 @@ export const setSearchQuery = (searchQuery: string): SetSearchQueryAction => ({ export function loadTeams(): ThunkResult { return async dispatch => { - const showMine = contextSrv.user.orgRole === OrgRole.Editor; - const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1, showMine }); + const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1 }); dispatch(teamsLoaded(response.teams)); }; }