diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index 02658e98..900f33b7 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -53,6 +53,7 @@ Object { "dropGroups": [Function], "getGroupsDone": [Function], "getGroupsInit": [Function], + "getMemberGroups": [Function], }, "looker": Object { "getLookerDone": [Function], diff --git a/package.json b/package.json index 65aac3b3..5b2c8d31 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1.1.8", + "version": "1000.27.14", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", diff --git a/src/actions/groups.js b/src/actions/groups.js index 8bdb4f9c..8d3ba7b3 100644 --- a/src/actions/groups.js +++ b/src/actions/groups.js @@ -42,10 +42,21 @@ function getGroupsDone(groupIds, tokenV3) { return getService(tokenV3).getGroupMap(groupIds); } +/** + * Get groups that a member belong to + * @param {*} userId the member's userId + * @param {*} tokenV3 the member's token + * @returns + */ +function getMemberGroups(userId, tokenV3) { + return getService(tokenV3).getMemberGroups(userId); +} + export default createActions({ GROUPS: { DROP_GROUPS: dropGroups, GET_GROUPS_INIT: getGroupsInit, GET_GROUPS_DONE: getGroupsDone, + GET_MEMBER_GROUPS: getMemberGroups, }, }); diff --git a/src/reducers/groups.js b/src/reducers/groups.js index e7ba374e..9135dfa8 100644 --- a/src/reducers/groups.js +++ b/src/reducers/groups.js @@ -84,6 +84,11 @@ function onGetGroupsDone(state, action) { return { ...state, groups, loading }; } + +function onGetMemberGroups(state, action) { + return { ...state, memberGroups: action.payload }; +} + /** * Creates a new Groups reducer with the specified initial state. * @param {Object} initialState Optional. Initial state. @@ -95,9 +100,11 @@ function create(initialState) { [a.dropGroups]: onDropGroups, [a.getGroupsInit]: onGetGroupsInit, [a.getGroupsDone]: onGetGroupsDone, + [a.getMemberGroups]: onGetMemberGroups, }, _.defaults(initialState ? _.clone(initialState) : {}, { groups: {}, loading: {}, + memberGroups: [], })); } diff --git a/src/services/groups.js b/src/services/groups.js index a3b42a80..6d85e4f6 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -354,6 +354,17 @@ class GroupService { getTokenV3() { return this.private.tokenV3; } + + /** + * Gets the corresponding user's groups information + * @param {*} userId the userId + * @returns + */ + async getMemberGroups(userId) { + const url = `/groups/memberGroups/${userId}`; + const res = await this.private.api.get(url); + return handleApiResponse(res); + } } let lastInstance = null;