Fix the userInfo
Fix user Info window, now clicking on the user name make it appears +
attempt to add a logout
Issue-ID: CLAMP-393
Change-Id: I82686a848f7ccae95c1eab22f1923a8821ba76b1
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js
index 9389ad6..fb595de 100644
--- a/ui-react/src/LoopUI.js
+++ b/ui-react/src/LoopUI.js
@@ -106,6 +106,7 @@
constructor() {
super();
this.getUser = this.getUser.bind(this);
+ this.logout = this.logout.bind(this);
this.updateLoopCache = this.updateLoopCache.bind(this);
this.loadLoop = this.loadLoop.bind(this);
this.closeLoop = this.closeLoop.bind(this);
@@ -120,6 +121,14 @@
this.setState({ userName: user })
});
}
+
+ logout() {
+ UserService.logout().then(user => {
+ this.setState({ userName: user });
+ window.location.reload();
+ });
+
+ }
renderMenuNavBar() {
return (
@@ -205,8 +214,8 @@
this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
this.props.history.push('/');
}
-
- render() {
+
+ render() {
return (
<StyledMainDiv id="main_div">
<Route path="/operationalPolicyModal"
@@ -223,7 +232,8 @@
<Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
<Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
<Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
- <GlobalClampStyle />
+ <Route path="/logout" render={this.logout} />
+ <GlobalClampStyle />
{this.renderNavBar()}
{this.renderLoopViewer()}
</StyledMainDiv>
diff --git a/ui-react/src/api/UserService.js b/ui-react/src/api/UserService.js
index be21e69..37ec73d 100644
--- a/ui-react/src/api/UserService.js
+++ b/ui-react/src/api/UserService.js
@@ -47,6 +47,31 @@
return UserService.notLoggedUserName;
});
}
+
+ static logout() {
+ return fetch('/restservices/clds/v1/user/logout', {
+ method: 'POST',
+ credentials: 'same-origin',
+ })
+ .then(function (response) {
+ console.debug("logout response received, status code:", response.status);
+ if (response.ok) {
+ return response.text();
+ } else {
+ console.error("logout response is nok");
+ return UserService.notLoggedUserName;
+ }
+ })
+ .then(function (data) {
+ console.info ("User disconnected:",data)
+ return data;
+ })
+ .catch(function(error) {
+ console.warn("logout error received, user set to: ",UserService.notLoggedUserName);
+ console.error("logout error:",error);
+ return UserService.notLoggedUserName;
+ });
+ }
static getUserInfo() {
return fetch('/restservices/clds/v1/clds/cldsInfo', {
diff --git a/ui-react/src/components/dialogs/UserInfo.js b/ui-react/src/components/dialogs/UserInfo.js
index b8d68b8..7d81b38 100644
--- a/ui-react/src/components/dialogs/UserInfo.js
+++ b/ui-react/src/components/dialogs/UserInfo.js
@@ -39,7 +39,6 @@
super(props, context);
this.handleClose = this.handleClose.bind(this);
- this.initialValues = this.initialValues.bind(this);
this.renderReadTemplatePermission = this.renderReadTemplatePermission.bind(this);
this.renderReadModelPermission = this.renderReadModelPermission.bind(this);
this.renderReadToscaPermission = this.renderReadToscaPermission.bind(this);
@@ -49,23 +48,15 @@
this.renderUserName = this.renderUserName.bind(this);
this.state = {
show: true,
- userInfo: {permissionReadTemplate: true,
- permissionReadCl: true,
- permissionReadTosca: true,
- permissionUpdateCl: true,
- permissionUpdateTemplate: true,
- permissionUpdateTosca: true,
- userName: 'admin',
- cldsVersion: '1.0.0'
- }
+ userInfo: {}
};
-
}
- initialValues() {
+ componentWillMount() {
UserService.getUserInfo().then(userInfo => {
this.setState({ userInfo: userInfo })
});
}
+
handleClose() {
this.props.history.push('/');
}
@@ -127,7 +118,7 @@
}
render() {
return (
- <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} onEntered={this.initialValues}>
+ <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
<Modal.Header closeButton>
<Modal.Title>User Info</Modal.Title>
</Modal.Header>
diff --git a/ui-react/src/index.js b/ui-react/src/index.js
index cbbdc65..dd83096 100644
--- a/ui-react/src/index.js
+++ b/ui-react/src/index.js
@@ -23,13 +23,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import OnapClamp from './OnapClamp';
-import { Route, BrowserRouter } from 'react-router-dom'
+import { Route, MemoryRouter } from 'react-router-dom'
const routing = (
- <BrowserRouter forceRefresh={false}>
+ <MemoryRouter forceRefresh={false}>
<Route path="/" component={OnapClamp}/>
- </BrowserRouter>
+ </MemoryRouter>
);
export var mainClamp = ReactDOM.render(