mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 16:47:45 -02:30
UI side of the session limit
includes the 'control' socket, kicking the user out, and adjusting the expireSession function based on the reason
This commit is contained in:
@@ -887,7 +887,7 @@ var tower = angular.module('Tower', [
|
|||||||
// Listen for job changes and issue callbacks to initiate
|
// Listen for job changes and issue callbacks to initiate
|
||||||
// DOM updates
|
// DOM updates
|
||||||
function openSocket() {
|
function openSocket() {
|
||||||
var schedule_socket;
|
var schedule_socket, control_socket;
|
||||||
|
|
||||||
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
|
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
|
||||||
sock.init();
|
sock.init();
|
||||||
@@ -936,6 +936,16 @@ var tower = angular.module('Tower', [
|
|||||||
$log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status);
|
$log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status);
|
||||||
$rootScope.$emit('ScheduleStatusChange', data);
|
$rootScope.$emit('ScheduleStatusChange', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
control_socket = Socket({
|
||||||
|
scope: $rootScope,
|
||||||
|
endpoint: "control"
|
||||||
|
});
|
||||||
|
control_socket.init();
|
||||||
|
control_socket.on("limit_reached", function(data) {
|
||||||
|
$log.debug(data.reason);
|
||||||
|
Timer.expireSession('session_limit');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
openSocket();
|
openSocket();
|
||||||
|
|
||||||
@@ -982,7 +992,7 @@ var tower = angular.module('Tower', [
|
|||||||
} else if ($rootScope.sessionTimer.isExpired()) {
|
} else if ($rootScope.sessionTimer.isExpired()) {
|
||||||
// gets here on timeout
|
// gets here on timeout
|
||||||
if (next.templateUrl !== (urlPrefix + 'login/loginBackDrop.partial.html')) {
|
if (next.templateUrl !== (urlPrefix + 'login/loginBackDrop.partial.html')) {
|
||||||
$rootScope.sessionTimer.expireSession();
|
$rootScope.sessionTimer.expireSession('idle');
|
||||||
if (sock) {
|
if (sock) {
|
||||||
sock.socket.socket.disconnect();
|
sock.socket.socket.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,16 @@ export default
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
expireSession: function () {
|
expireSession: function (reason) {
|
||||||
|
if(reason === 'session_limit'){
|
||||||
|
$rootScope.sessionLimitExpired = true;
|
||||||
|
$rootScope.sessionExpired = false;
|
||||||
|
}
|
||||||
|
else if(reason === 'idle'){
|
||||||
|
$rootScope.sessionExpired = true;
|
||||||
|
$rootScope.sessionLimitExpired = false;
|
||||||
|
}
|
||||||
this.sessionTime = 0;
|
this.sessionTime = 0;
|
||||||
$rootScope.sessionExpired = true;
|
|
||||||
this.clearTimers();
|
this.clearTimers();
|
||||||
$cookieStore.put('sessionExpired', true);
|
$cookieStore.put('sessionExpired', true);
|
||||||
transitionTo('signOut');
|
transitionTo('signOut');
|
||||||
@@ -89,7 +96,7 @@ export default
|
|||||||
// make a timeout that will go off in 30 mins to log them out
|
// make a timeout that will go off in 30 mins to log them out
|
||||||
// unless they extend their time
|
// unless they extend their time
|
||||||
$rootScope.endTimer = setTimeout(function(){
|
$rootScope.endTimer = setTimeout(function(){
|
||||||
that.expireSession();
|
that.expireSession('idle');
|
||||||
}, tm * 1000);
|
}, tm * 1000);
|
||||||
|
|
||||||
// notify the user a minute before the end of their session that
|
// notify the user a minute before the end of their session that
|
||||||
|
|||||||
@@ -6,13 +6,17 @@
|
|||||||
ng-src="/static/assets/{{ customLogo }}" >
|
ng-src="/static/assets/{{ customLogo }}" >
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="LoginModal-alert" ng-show="!sessionExpired">
|
<div class="LoginModal-alert" ng-show="!sessionExpired && !sessionLimitExpired">
|
||||||
Welcome to Ansible Tower! Please sign in.
|
Welcome to Ansible Tower! Please sign in.
|
||||||
</div>
|
</div>
|
||||||
<div class="LoginModal-alert" ng-show="sessionExpired">
|
<div class="LoginModal-alert" ng-show="sessionExpired">
|
||||||
Your session timed out due to inactivity. Please
|
Your session timed out due to inactivity. Please
|
||||||
sign in.
|
sign in.
|
||||||
</div>
|
</div>
|
||||||
|
<div class="LoginModal-alert" ng-show="sessionLimitExpired">
|
||||||
|
Maximum per-user sessions reached. Please
|
||||||
|
sign in.
|
||||||
|
</div>
|
||||||
<form id="login-form"
|
<form id="login-form"
|
||||||
name="loginForm"
|
name="loginForm"
|
||||||
class="form-horizontal"
|
class="form-horizontal"
|
||||||
|
|||||||
@@ -11,16 +11,21 @@
|
|||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
export default
|
export default
|
||||||
['$rootScope',
|
[ '$rootScope',
|
||||||
function ($rootScope) {
|
function ($rootScope) {
|
||||||
return {
|
return {
|
||||||
response: function(config) {
|
response: function(config) {
|
||||||
if(config.headers('auth-token-timeout') !== null){
|
if(config.headers('auth-token-timeout') !== null){
|
||||||
// $rootScope.sessionTimer = Number(config.headers('auth-token-timeout'));
|
|
||||||
$AnsibleConfig.session_timeout = Number(config.headers('auth-token-timeout'));
|
$AnsibleConfig.session_timeout = Number(config.headers('auth-token-timeout'));
|
||||||
// $rootScope.sessionTimer = Timer.init();
|
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
|
},
|
||||||
|
responseError: function(rejection){
|
||||||
|
if(rejection.data.detail && rejection.data.detail === "Maximum per-user sessions reached"){
|
||||||
|
$rootScope.sessionTimer.expireSession('session_limit');
|
||||||
|
return rejection;
|
||||||
|
}
|
||||||
|
return rejection;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ angular.module('SocketIO', ['Utilities'])
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// encountered expired token, redirect to login page
|
// encountered expired token, redirect to login page
|
||||||
$rootScope.sessionTimer.expireSession();
|
$rootScope.sessionTimer.expireSession('idle');
|
||||||
$location.url('/login');
|
$location.url('/login');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ angular.module('Utilities', ['RestServices', 'Utilities', 'sanitizeFilter'])
|
|||||||
} else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') ||
|
} else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') ||
|
||||||
(status === 401 && data.detail && data.detail === 'Invalid token')) {
|
(status === 401 && data.detail && data.detail === 'Invalid token')) {
|
||||||
if ($rootScope.sessionTimer) {
|
if ($rootScope.sessionTimer) {
|
||||||
$rootScope.sessionTimer.expireSession();
|
$rootScope.sessionTimer.expireSession('idle');
|
||||||
}
|
}
|
||||||
$location.url('/login');
|
$location.url('/login');
|
||||||
} else if (data.non_field_errors) {
|
} else if (data.non_field_errors) {
|
||||||
|
|||||||
Reference in New Issue
Block a user