Skip to content

Commit

Permalink
Bug 1862934: Trigger the inactivity logout method when component Mast…
Browse files Browse the repository at this point in the history
…head is mounted
  • Loading branch information
jhadvig committed Aug 4, 2020
1 parent ee8c5d6 commit a0344c5
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions frontend/public/components/masthead-toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,44 @@ class MastheadToolbarContents_ extends React.Component {
this._onHelpDropdownToggle = this._onHelpDropdownToggle.bind(this);
this._onAboutModal = this._onAboutModal.bind(this);
this._closeAboutModal = this._closeAboutModal.bind(this);
this._onInactivityTimeout = this._onInactivityTimeout.bind(this);
this.userInctivityTimeout = null;
this._resetInactivityTimeout = this._resetInactivityTimeout.bind(this);
this.userInactivityTimeout = null;
}

componentDidMount() {
if (window.SERVER_FLAGS.statuspageID) {
this._getStatuspageData(window.SERVER_FLAGS.statuspageID);
}
// Ignore inactivity-timeout if set to less then 300 seconds
if (window.SERVER_FLAGS.inactivityTimeout >= 300) {
window.addEventListener('click', _.throttle(this._onInactivityTimeout, 500));
window.addEventListener('keydown', _.throttle(this._onInactivityTimeout, 500));
const inactivityTimeoutEnabled = window.SERVER_FLAGS.inactivityTimeout >= 300;
if (inactivityTimeoutEnabled) {
window.addEventListener('click', _.throttle(this._resetInactivityTimeout, 500));
window.addEventListener('keydown', _.throttle(this._resetInactivityTimeout, 500));
this._resetInactivityTimeout();
}
this._updateUser();
}

componentDidUpdate(prevProps) {
const { flags, user } = this.props;
if (
this.props.flags[FLAGS.OPENSHIFT] !== prevProps.flags[FLAGS.OPENSHIFT] ||
!_.isEqual(this.props.user, prevProps.user)
flags[FLAGS.OPENSHIFT] !== prevProps.flags[FLAGS.OPENSHIFT] ||
!_.isEqual(user, prevProps.user)
) {
this._updateUser();
}
}

componentWillUnmount() {
window.removeEventListener('click', this._onInactivityTimeout);
window.removeEventListener('keydown', this._onInactivityTimeout);
clearTimeout(this.userInctivityTimeout);
window.removeEventListener('click', this._resetInactivityTimeout);
window.removeEventListener('keydown', this._resetInactivityTimeout);
clearTimeout(this.userInactivityTimeout);
}

_onInactivityTimeout() {
_resetInactivityTimeout() {
const { flags, user } = this.props;

if (flagPending(flags[FLAGS.OPENSHIFT]) || !user) {
return;
}

clearTimeout(this.userInctivityTimeout);
this.userInctivityTimeout = setTimeout(() => {
clearTimeout(this.userInactivityTimeout);
this.userInactivityTimeout = setTimeout(() => {
if (flags[FLAGS.OPENSHIFT]) {
authSvc.logoutOpenShift(user?.metadata?.name === 'kube:admin');
} else {
Expand Down

0 comments on commit a0344c5

Please sign in to comment.