mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
fixed active users socket calls in ACP
This commit is contained in:
@@ -2,11 +2,23 @@ define(function() {
|
||||
var Admin = {};
|
||||
|
||||
Admin.init = function() {
|
||||
ajaxify.register_events(['api:get_all_rooms']);
|
||||
ajaxify.register_events(['api:meta.rooms.getAll']);
|
||||
|
||||
app.enterRoom('admin');
|
||||
socket.emit('api:meta.rooms.getAll', function(data) {
|
||||
socket.emit('api:meta.rooms.getAll', Admin.updateRoomUsage);
|
||||
socket.on('event:meta.rooms.update', Admin.updateRoomUsage);
|
||||
|
||||
$('#logout-link').on('click', function() {
|
||||
$.post(RELATIVE_PATH + '/logout', {
|
||||
_csrf: $('#csrf_token').val()
|
||||
}, function() {
|
||||
window.location.href = RELATIVE_PATH + '/';
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
Admin.updateRoomUsage = function(data) {
|
||||
console.log('room usage updating', data);
|
||||
var active_users = document.getElementById('active_users'),
|
||||
total = 0;
|
||||
active_users.innerHTML = '';
|
||||
@@ -20,15 +32,6 @@ define(function() {
|
||||
}
|
||||
|
||||
document.getElementById('connections').innerHTML = total;
|
||||
});
|
||||
|
||||
$('#logout-link').on('click', function() {
|
||||
$.post(RELATIVE_PATH + '/logout', {
|
||||
_csrf: $('#csrf_token').val()
|
||||
}, function() {
|
||||
window.location.href = RELATIVE_PATH + '/';
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
return Admin;
|
||||
|
||||
@@ -10,9 +10,21 @@ var groups = require('../groups'),
|
||||
},
|
||||
|
||||
async = require('async'),
|
||||
winston = require('winston'),
|
||||
|
||||
SocketAdmin = {};
|
||||
|
||||
SocketAdmin.before = function(sessionData, next) {
|
||||
// Verify administrative privileges
|
||||
user.isAdministrator(sessionData.uid, function(err, isAdmin) {
|
||||
if (isAdmin) {
|
||||
next();
|
||||
} else {
|
||||
winston.warn('[socket.io] Call to admin method blocked (accessed by uid ' + sessionData.uid + ')');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Topics */
|
||||
|
||||
SocketAdmin.topics = {};
|
||||
|
||||
@@ -130,6 +130,7 @@ Sockets.init = function() {
|
||||
} else {
|
||||
// Deconstruct the message
|
||||
var parts = payload.name.slice(4).split('.'),
|
||||
namespace = parts.slice(0, 1),
|
||||
methodToCall = parts.reduce(function(prev, cur) {
|
||||
if (prev !== null && prev[cur]) {
|
||||
return prev[cur];
|
||||
@@ -157,8 +158,15 @@ Sockets.init = function() {
|
||||
}
|
||||
socketArgs.push(sessionData);
|
||||
|
||||
// winston.info('[socket.io] Executing: ' + payload.name);
|
||||
// Call the requested method
|
||||
if (Namespaces[namespace].before) {
|
||||
Namespaces[namespace].before(sessionData, function() {
|
||||
methodToCall.apply(Namespaces, socketArgs);
|
||||
});
|
||||
} else {
|
||||
methodToCall.apply(Namespaces, socketArgs);
|
||||
}
|
||||
// winston.info('[socket.io] Executing: ' + payload.name);
|
||||
} else {
|
||||
winston.warn('[socket.io] Unrecognized message: ' + payload.name);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ SocketMeta.rooms.enter = function(data, sessionData) {
|
||||
module.parent.exports.updateRoomBrowsingText(data.enter);
|
||||
|
||||
if (data.enter != 'admin') {
|
||||
sessionData.server.sockets.in('admin').emit('api:get_all_rooms', sessionData.server.sockets.manager.rooms);
|
||||
sessionData.server.sockets.in('admin').emit('event:meta.rooms.update', sessionData.server.sockets.manager.rooms);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user