Unverified Commit b0610c76 authored by Martin Kraft's avatar Martin Kraft Committed by GitHub
Browse files

MM-12488: Adds new query params options when getting LDAP groups. (#788)

* Bump release v5.6.0

* MM-12488: Adds extra options to get LDAP groups.

* MM-12488: Updates flow type definition and tests.

* MM-12488: Adds tests for new params.

* MM-12488: Revert accidental change.
parent 98856a37
......@@ -13,6 +13,7 @@ import {batchActions} from 'redux-batched-actions';
import type {ActionFunc} from 'types/actions';
import type {Job} from 'types/jobs';
import type {GroupSearchOpts} from 'types/groups';
export function getLogs(page: number = 0, perPage: number = General.LOGS_PAGE_SIZE_DEFAULT): ActionFunc {
return bindClientFunc({
......@@ -206,7 +207,7 @@ export function syncLdap(): ActionFunc {
});
}
export function getLdapGroups(page: number = 0, perPage: number = General.PAGE_SIZE_MAXIMUM): ActionFunc {
export function getLdapGroups(page: number = 0, perPage: number = General.PAGE_SIZE_MAXIMUM, opts: GroupSearchOpts = {q: ''}): ActionFunc {
return bindClientFunc({
clientFunc: Client4.getLdapGroups,
onRequest: AdminTypes.GET_LDAP_GROUPS_REQUEST,
......@@ -215,6 +216,7 @@ export function getLdapGroups(page: number = 0, perPage: number = General.PAGE_S
params: [
page,
perPage,
opts,
],
});
}
......
......@@ -13,6 +13,7 @@ import TestHelper from 'test/test_helper';
import configureStore from 'test/test_store';
const OK_RESPONSE = {status: 'OK'};
const NO_GROUPS_RESPONSE = {count: 0, groups: []};
describe('Actions.Admin', () => {
let store;
......@@ -964,7 +965,7 @@ describe('Actions.Admin', () => {
get('/ldap/groups?page=0&per_page=100').
reply(200, ldapGroups);
await Actions.getLdapGroups(0, 100)(store.dispatch, store.getState);
await Actions.getLdapGroups(0, 100, null)(store.dispatch, store.getState);
const state = store.getState();
const request = state.requests.admin.getLdapGroups;
......@@ -978,6 +979,84 @@ describe('Actions.Admin', () => {
assert.ok(groups[ldapGroups.groups[1].primary_key]);
});
it('getLdapGroups is_linked', async () => {
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=&is_linked=true').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: '', is_linked: true})(store.dispatch, store.getState);
let state = store.getState();
let request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=&is_linked=false').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: '', is_linked: false})(store.dispatch, store.getState);
state = store.getState();
request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
});
it('getLdapGroups is_configured', async () => {
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=&is_configured=true').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: '', is_configured: true})(store.dispatch, store.getState);
let state = store.getState();
let request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=&is_configured=false').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: '', is_configured: false})(store.dispatch, store.getState);
state = store.getState();
request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
});
it('getLdapGroups with name query', async () => {
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=est').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: 'est'})(store.dispatch, store.getState);
let state = store.getState();
let request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
nock(Client4.getBaseRoute()).
get('/ldap/groups?page=0&per_page=100&q=esta').
reply(200, NO_GROUPS_RESPONSE);
await Actions.getLdapGroups(0, 100, {q: 'esta'})(store.dispatch, store.getState);
state = store.getState();
request = state.requests.admin.getLdapGroups;
if (request.status === RequestStatus.FAILURE) {
throw new Error('getLdapGroups request failed err=' + request.error);
}
});
it('linkLdapGroup', async () => {
const ldapGroups = {
count: 2,
......@@ -991,7 +1070,7 @@ describe('Actions.Admin', () => {
get('/ldap/groups?page=0&per_page=100').
reply(200, ldapGroups);
await Actions.getLdapGroups(0, 100)(store.dispatch, store.getState);
await Actions.getLdapGroups(0, 100, null)(store.dispatch, store.getState);
const key = 'test1';
......@@ -1021,7 +1100,7 @@ describe('Actions.Admin', () => {
get('/ldap/groups?page=0&per_page=100').
reply(200, ldapGroups);
await Actions.getLdapGroups(0, 100)(store.dispatch, store.getState);
await Actions.getLdapGroups(0, 100, null)(store.dispatch, store.getState);
const key = 'test2';
......
......@@ -2250,9 +2250,10 @@ export default class Client4 {
);
};
getLdapGroups = async (page = 0, perPage = PER_PAGE_DEFAULT) => {
getLdapGroups = async (page = 0, perPage = PER_PAGE_DEFAULT, opts = {}) => {
const query = {page, per_page: perPage, ...opts};
return this.doFetch(
`${this.getBaseRoute()}/ldap/groups${buildQueryString({page, per_page: perPage})}`,
`${this.getBaseRoute()}/ldap/groups${buildQueryString(query)}`,
{method: 'get'}
);
};
......
......@@ -55,4 +55,10 @@ export type GroupsState = {|
syncables: {[string]: GroupSyncables},
members: Object,
groups: { [string]: Group },
|};
export type GroupSearchOpts = {|
q: string,
is_linked?: boolean,
is_configured?: boolean,
|};
\ No newline at end of file
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