mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
teams: moved logic for searchteams to backend
This commit is contained in:
parent
782b5b6a3a
commit
b60e71c28b
@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
|||||||
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) {
|
|||||||
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) {
|
|||||||
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) {
|
|||||||
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)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
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 => ({
|
|||||||
|
|
||||||
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));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user