Add user_id to BE requests 49/57949/1
authorMalek <malek.zoabi@amdocs.com>
Sun, 29 Jul 2018 13:29:35 +0000 (16:29 +0300)
committerMalek <malek.zoabi@amdocs.com>
Sun, 29 Jul 2018 13:30:18 +0000 (16:30 +0300)
Issue-ID: SDC-1567
Change-Id: I9cac454b762414e28953dd2045b0a8daa31d67b6
Signed-off-by: Malek <malek.zoabi@amdocs.com>
workflow-designer-ui/src/main/frontend/src/App.js
workflow-designer-ui/src/main/frontend/src/appConstants.js
workflow-designer-ui/src/main/frontend/src/services/restAPIUtil.js
workflow-designer-ui/src/main/frontend/tools/proxy-server.js

index 7b46fe4..4b42f6f 100644 (file)
@@ -21,7 +21,8 @@ import { Route } from 'react-router-dom';
 import { PluginPubSub } from 'shared/pubsub/plugin-pubsub';
 import 'resources/scss/style.scss';
 import 'bpmn-js-properties-panel/styles/properties.less';
-import { routes } from './routes';
+import { routes } from 'wfapp/routes';
+import { USER_ID } from 'wfapp/appConstants';
 
 const RouteWithSubRoutes = route => (
     <Route
@@ -32,10 +33,19 @@ const RouteWithSubRoutes = route => (
 );
 
 class App extends Component {
+    constructor(props) {
+        super(props);
+
+        this.searchParams = new URLSearchParams(location.search);
+
+        if (this.searchParams.get('userId')) {
+            localStorage.setItem(USER_ID, this.searchParams.get('userId'));
+        }
+    }
+
     componentDidMount() {
-        const searchParams = new URLSearchParams(location.search);
-        const eventsClientId = searchParams.get('eventsClientId');
-        const parentUrl = searchParams.get('parentUrl');
+        const eventsClientId = this.searchParams.get('eventsClientId');
+        const parentUrl = this.searchParams.get('parentUrl');
 
         if (eventsClientId && parentUrl) {
             const client = new PluginPubSub(eventsClientId, parentUrl);
index b1497a9..710c4d8 100644 (file)
@@ -16,6 +16,7 @@
 
 import { createAction } from 'redux-actions';
 export const LANG = 'en';
+export const USER_ID = 'USER_ID';
 export const VERSION_LEVEL_LIST = [
     {
         id: '2',
index c0d72c0..d5c0f9b 100644 (file)
@@ -18,6 +18,7 @@ import md5 from 'md5';
 import axios from 'axios';
 
 import store from 'wfapp/store';
+import { USER_ID } from 'wfapp/appConstants';
 
 import {
     sendRequestAction,
@@ -44,7 +45,6 @@ const AUTHORIZATION_HEADER = 'X-AUTH-TOKEN';
 const STORAGE_AUTH_KEY = 'sdc-auth-token';
 const REQUEST_ID_HEADER = 'X-ECOMP-RequestID';
 const CONTENT_MD5_HEADER = 'Content-MD5';
-const USER_ID = 'USER_ID';
 
 function applySecurity(options, data) {
     let headers = options.headers || (options.headers = {});
@@ -70,7 +70,10 @@ function applySecurity(options, data) {
             md5(JSON.stringify(data)).toLowerCase()
         );
     }
-    headers[USER_ID] = 'cs0008';
+
+    if (localStorage.getItem(USER_ID)) {
+        headers[USER_ID] = localStorage.getItem(USER_ID);
+    }
 }
 
 function handleSuccess(responseHeaders, requestHeaders) {
index 3193fb1..397b0ba 100644 (file)
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-'use strict';
+'use strict'
 
-const proxy = require('http-proxy-middleware');
-const devConfig = require('./getDevConfig');
+const proxy = require('http-proxy-middleware')
+const devConfig = require('./getDevConfig')
 
 module.exports = function(server) {
     let proxyConfigDefaults = {
         changeOrigin: true,
         secure: false,
-        onProxyRes: (proxyRes, req, res) => {
-            let setCookie = proxyRes.headers['set-cookie'];
-            if (setCookie) {
-                setCookie[0] = setCookie[0].replace('USER_ID', 'cs0008');
-            }
+        onProxyReq: (proxyReq, req, res) => {
+            proxyReq.setHeader('USER_ID', devConfig.proxyConfig.cookies.USER_ID)
         },
-    };
+    }
 
-    let middlewares = [];
+    let middlewares = []
 
     middlewares.push(
         proxy(
@@ -39,6 +36,6 @@ module.exports = function(server) {
                 target: devConfig.proxyTarget,
             }),
         ),
-    );
-    server.use(middlewares);
-};
+    )
+    server.use(middlewares)
+}