Commit 89d4db8e by Leonard Gram

teams: team listing shows only your teams (editors).

parent 1f949e58
...@@ -86,10 +86,16 @@ func SearchTeams(c *m.ReqContext) Response { ...@@ -86,10 +86,16 @@ func SearchTeams(c *m.ReqContext) Response {
page = 1 page = 1
} }
var userIdFilter int64
if c.QueryBool("showMine") {
userIdFilter = c.SignedInUser.UserId
}
query := m.SearchTeamsQuery{ query := m.SearchTeamsQuery{
OrgId: c.OrgId, OrgId: c.OrgId,
Query: c.Query("query"), Query: c.Query("query"),
Name: c.Query("name"), Name: c.Query("name"),
UserIdFilter: userIdFilter,
Page: page, Page: page,
Limit: perPage, Limit: perPage,
} }
......
...@@ -66,6 +66,7 @@ type SearchTeamsQuery struct { ...@@ -66,6 +66,7 @@ type SearchTeamsQuery struct {
Limit int Limit int
Page int Page int
OrgId int64 OrgId int64
UserIdFilter int64
Result SearchTeamQueryResult Result SearchTeamQueryResult
} }
......
...@@ -149,6 +149,10 @@ func SearchTeams(query *m.SearchTeamsQuery) error { ...@@ -149,6 +149,10 @@ func SearchTeams(query *m.SearchTeamsQuery) error {
params := make([]interface{}, 0) params := make([]interface{}, 0)
sql.WriteString(getTeamSelectSqlBase()) sql.WriteString(getTeamSelectSqlBase())
if query.UserIdFilter > 0 {
sql.WriteString(`INNER JOIN team_member on team.id = team_member.team_id AND team_member.user_id = ?`)
params = append(params, query.UserIdFilter)
}
sql.WriteString(` WHERE team.org_id = ?`) sql.WriteString(` WHERE team.org_id = ?`)
params = append(params, query.OrgId) params = append(params, query.OrgId)
......
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 { StoreState, Team, TeamGroup, TeamMember } from 'app/types'; import { OrgRole, 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',
...@@ -85,7 +86,8 @@ export const setSearchQuery = (searchQuery: string): SetSearchQueryAction => ({ ...@@ -85,7 +86,8 @@ export const setSearchQuery = (searchQuery: string): SetSearchQueryAction => ({
export function loadTeams(): ThunkResult<void> { export function loadTeams(): ThunkResult<void> {
return async dispatch => { return async dispatch => {
const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1 }); const showMine = contextSrv.user.orgRole === OrgRole.Editor;
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