Initial support for user status flags (NotAvail, NotVisible, ...)

This commit is contained in:
Bryan Ashby 2022-05-08 22:15:57 -06:00
parent 24491000ad
commit 6502f3b55e
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
5 changed files with 62 additions and 14 deletions

View File

@ -21,21 +21,24 @@ exports.getConnectionByNodeId = getConnectionByNodeId;
const clientConnections = [];
exports.clientConnections = clientConnections;
function getActiveConnections(authUsersOnly = false) {
function getActiveConnections(options = { authUsersOnly: true, visibleOnly: true }) {
return clientConnections.filter(conn => {
return ((authUsersOnly && conn.user.isAuthenticated()) || !authUsersOnly);
if (options.authUsersOnly && !conn.user.isAuthenticated()) {
return false;
}
if (options.visibleOnly && !conn.user.isVisible()) {
return false;
}
return true;
//return ((options.authUsersOnly && conn.user.isAuthenticated()) || !options.authUsersOnly);
});
}
function getActiveConnectionList(authUsersOnly) {
if(!_.isBoolean(authUsersOnly)) {
authUsersOnly = true;
}
function getActiveConnectionList(options = { authUsersOnly: true, visibleOnly: true }) {
const now = moment();
return _.map(getActiveConnections(authUsersOnly), ac => {
return _.map(getActiveConnections(options), ac => {
let action;
try {
// attempting to fetch a bad menu stack item can blow up/assert
@ -51,6 +54,8 @@ function getActiveConnectionList(authUsersOnly) {
action : action,
serverName : ac.session.serverName,
isSecure : ac.session.isSecure,
isVisible : ac.user.isVisible(),
isAvailable : ac.user.isAvailable(),
};
//
@ -66,6 +71,7 @@ function getActiveConnectionList(authUsersOnly) {
const diff = now.diff(moment(ac.user.properties[UserProps.LastLoginTs]), 'minutes');
entry.timeOn = moment.duration(diff, 'minutes');
}
return entry;
});
}

View File

@ -204,7 +204,7 @@ exports.getModule = class NodeMessageModule extends MenuModule {
location : 'N/A',
affils : 'N/A',
timeOn : 'N/A',
}].concat(getActiveConnectionList(true)
}].concat(getActiveConnectionList()
.map(node => Object.assign(node, { text : -1 == node.node ? '-ALL-' : node.node.toString() } ))
).filter(node => node.node !== this.client.node); // remove our client's node
this.nodeList.sort( (a, b) => a.node - b.node ); // sort by node

View File

@ -23,8 +23,6 @@ const moment = require('moment');
const sanatizeFilename = require('sanitize-filename');
const ssh2 = require('ssh2');
exports.isRootUserId = function(id) { return 1 === id; };
module.exports = class User {
constructor() {
this.userId = 0;
@ -32,6 +30,7 @@ module.exports = class User {
this.properties = {}; // name:value
this.groups = []; // group membership(s)
this.authFactor = User.AuthFactors.None;
this.statusFlags = User.StatusFlags.None;
}
// static property accessors
@ -73,6 +72,14 @@ module.exports = class User {
};
}
static get StatusFlags() {
return {
None : 0x00000000,
NotAvailable : 0x00000001, // Not currently available for chat, message, page, etc.
NotVisible : 0x00000002, // Invisible -- does not show online, last callers, etc.
}
}
isAuthenticated() {
return true === this.authenticated;
}
@ -121,6 +128,22 @@ module.exports = class User {
return sanatizeFilename(name) || `user${this.userId.toString()}`;
}
isAvailable() {
return (this.statusFlags & User.StatusFlags.NotAvailable) == 0;
}
isVisible() {
return (this.statusFlags & User.StatusFlags.NotVisible) == 0;
}
setVisibility(visible) {
if (visible) {
this.statusFlags &= ~User.StatusFlags.NotVisible;
} else {
this.statusFlags |= User.StatusFlags.NotVisible;
}
}
getLegacySecurityLevel() {
if(this.isRoot() || this.isGroupMember('sysops')) {
return 100;

View File

@ -96,6 +96,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
enter() {
this.client.stopIdleMonitor();
this._applyOpVisibility();
super.enter();
}
@ -104,12 +105,30 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
return stream.name === 'wfc-ringbuffer';
});
this._restoreOpVisibility();
this._stopRefreshing();
this.client.startIdleMonitor();
super.leave();
}
_applyOpVisibility() {
const vis = this.config.opVisibility || 'current';
this.restoreUserIsVisible = this.client.user.isVisible();
switch (vis) {
case 'hidden' : this.client.user.setVisibility(false); break;
case 'visible' : this.client.user.setVisibility(true); break;
default : break;
}
}
_restoreOpVisibility() {
this.client.user.setVisibility(this.restoreUserIsVisible);
}
_startRefreshing() {
this.mainRefreshTimer = setInterval( () => {
this._refreshAll();
@ -214,7 +233,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
return cb(null);
}
const nodeStatusItems = getActiveConnectionList(false)
const nodeStatusItems = getActiveConnectionList({authUsersOnly: false, visibleOnly: false})
.slice(0, nodeStatusView.dimens.height)
.map(ac => {
// Handle pre-authenticated

View File

@ -43,7 +43,7 @@ exports.getModule = class WhosOnlineModule extends MenuModule {
return cb(Errors.MissingMci(`Missing online list MCI ${MciViewIds.onlineList}`));
}
const onlineList = getActiveConnectionList(true).slice(0, onlineListView.height).map(
const onlineList = getActiveConnectionList().slice(0, onlineListView.height).map(
oe => Object.assign(oe, { text : oe.userName, timeOn : _.upperFirst(oe.timeOn.humanize()) })
);