blob: 98bce1ce564540ce183351176898e928b9ccfb91 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
18import Configuration from 'sdc-app/config/Configuration.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020019import { actionTypes } from './UsersConstants.js';
talig8e9c0652017-12-20 14:30:43 +020020
21function getUserId() {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020022 let catalogApiHeaders = Configuration.get('CatalogApiHeaders');
23 let User = catalogApiHeaders && catalogApiHeaders.userId;
24 let userId = User && User.value ? User.value : '';
25 return userId;
talig8e9c0652017-12-20 14:30:43 +020026}
27
28function baseUrl() {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020029 const restCatalogPrefix = Configuration.get('restCatalogPrefix');
30 return `${restCatalogPrefix}`;
talig8e9c0652017-12-20 14:30:43 +020031}
32
talig8e9c0652017-12-20 14:30:43 +020033function fetchUsersList() {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020034 const url = '/v1/user/users';
35 return RestAPIUtil.fetch(`${baseUrl()}${url}`);
talig8e9c0652017-12-20 14:30:43 +020036}
37
talig8e9c0652017-12-20 14:30:43 +020038const UsersActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020039 fetchUsersList(dispatch) {
40 fetchUsersList().then(response => {
41 dispatch({
42 type: actionTypes.USERS_LIST_LOADED,
43 usersList: response
44 });
talig8e9c0652017-12-20 14:30:43 +020045
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020046 let userId = getUserId();
47 let userInfo = response.find(user => user.userId === userId);
48 dispatch({
49 type: actionTypes.GOT_USER_INFO,
50 userInfo
51 });
52 });
53 }
talig8e9c0652017-12-20 14:30:43 +020054};
55
56export default UsersActionHelper;