Commit b60e71c2 by Hugo Häggmark Committed by Leonard Gram

teams: moved logic for searchteams to backend

parent 782b5b6a
...@@ -168,7 +168,7 @@ func (hs *HTTPServer) registerRoutes() { ...@@ -168,7 +168,7 @@ func (hs *HTTPServer) registerRoutes() {
// team without requirement of user to be org admin // team without requirement of user to be org admin
apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) { apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
teamsRoute.Get("/:teamId", Wrap(GetTeamByID)) teamsRoute.Get("/:teamId", Wrap(GetTeamByID))
teamsRoute.Get("/search", Wrap(SearchTeams)) teamsRoute.Get("/search", Wrap(hs.SearchTeams))
}) })
// org information available to all users. // org information available to all users.
......
...@@ -81,7 +81,7 @@ func DeleteTeamByID(c *m.ReqContext) Response { ...@@ -81,7 +81,7 @@ func DeleteTeamByID(c *m.ReqContext) Response {
} }
// GET /api/teams/search // GET /api/teams/search
func SearchTeams(c *m.ReqContext) Response { func (hs *HTTPServer) SearchTeams(c *m.ReqContext) Response {
perPage := c.QueryInt("perpage") perPage := c.QueryInt("perpage")
if perPage <= 0 { if perPage <= 0 {
perPage = 1000 perPage = 1000
...@@ -92,7 +92,7 @@ func SearchTeams(c *m.ReqContext) Response { ...@@ -92,7 +92,7 @@ func SearchTeams(c *m.ReqContext) Response {
} }
var userIdFilter int64 var userIdFilter int64
if c.QueryBool("showMine") { if hs.Cfg.EditorsCanAdmin && c.OrgRole != m.ROLE_ADMIN {
userIdFilter = c.SignedInUser.UserId userIdFilter = c.SignedInUser.UserId
} }
......
...@@ -3,6 +3,8 @@ package api ...@@ -3,6 +3,8 @@ package api
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
...@@ -20,6 +22,10 @@ func TestTeamApiEndpoint(t *testing.T) { ...@@ -20,6 +22,10 @@ func TestTeamApiEndpoint(t *testing.T) {
TotalCount: 2, TotalCount: 2,
} }
hs := &HTTPServer{
Cfg: setting.NewCfg(),
}
Convey("When searching with no parameters", func() { Convey("When searching with no parameters", func() {
loggedInUserScenario("When calling GET on", "/api/teams/search", func(sc *scenarioContext) { loggedInUserScenario("When calling GET on", "/api/teams/search", func(sc *scenarioContext) {
var sentLimit int var sentLimit int
...@@ -33,7 +39,7 @@ func TestTeamApiEndpoint(t *testing.T) { ...@@ -33,7 +39,7 @@ func TestTeamApiEndpoint(t *testing.T) {
return nil return nil
}) })
sc.handlerFunc = SearchTeams sc.handlerFunc = hs.SearchTeams
sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec() sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec()
So(sentLimit, ShouldEqual, 1000) So(sentLimit, ShouldEqual, 1000)
...@@ -60,7 +66,7 @@ func TestTeamApiEndpoint(t *testing.T) { ...@@ -60,7 +66,7 @@ func TestTeamApiEndpoint(t *testing.T) {
return nil return nil
}) })
sc.handlerFunc = SearchTeams sc.handlerFunc = hs.SearchTeams
sc.fakeReqWithParams("GET", sc.url, map[string]string{"perpage": "10", "page": "2"}).exec() sc.fakeReqWithParams("GET", sc.url, map[string]string{"perpage": "10", "page": "2"}).exec()
So(sentLimit, ShouldEqual, 10) So(sentLimit, ShouldEqual, 10)
......
import { ThunkAction } from 'redux-thunk'; import { ThunkAction } from 'redux-thunk';
import { getBackendSrv } from 'app/core/services/backend_srv'; 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 { updateNavIndex, UpdateNavIndexAction } from 'app/core/actions';
import { buildNavModel } from './navModel'; import { buildNavModel } from './navModel';
import { contextSrv } from '../../../core/services/context_srv';
export enum ActionTypes { export enum ActionTypes {
LoadTeams = 'LOAD_TEAMS', LoadTeams = 'LOAD_TEAMS',
...@@ -86,8 +85,7 @@ export const setSearchQuery = (searchQuery: string): SetSearchQueryAction => ({ ...@@ -86,8 +85,7 @@ export const setSearchQuery = (searchQuery: string): SetSearchQueryAction => ({
export function loadTeams(): ThunkResult<void> { export function loadTeams(): ThunkResult<void> {
return async dispatch => { return async dispatch => {
const showMine = contextSrv.user.orgRole === OrgRole.Editor; const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1 });
const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1, showMine });
dispatch(teamsLoaded(response.teams)); dispatch(teamsLoaded(response.teams));
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment