admin.js socket fixes

v1.18.x
Baris Soner Usakli 11 years ago
parent 13ae2e9401
commit a802dc4b68

@ -87,22 +87,25 @@ define(['uploader'], function(uploader) {
};
socket.emit('admin.categories.create', category, function(err, data) {
if (!err) {
app.alert({
alert_id: 'category_created',
title: 'Created',
message: 'Category successfully created!',
type: 'success',
timeout: 2000
});
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
categories: [data]
});
$('#entry-container').append(html);
$('#new-category-modal').modal('hide');
if(err) {
return app.alertError(err.message);
}
app.alert({
alert_id: 'category_created',
title: 'Created',
message: 'Category successfully created!',
type: 'success',
timeout: 2000
});
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
categories: [data]
});
$('#entry-container').append(html);
$('#new-category-modal').modal('hide');
});
}
@ -227,6 +230,10 @@ define(['uploader'], function(uploader) {
username: searchEl.value,
cid: cid
}, function(err, results) {
if(err) {
return app.alertError(err.message);
}
var numResults = results.length,
resultObj;
for(var x=0;x<numResults;x++) {
@ -276,6 +283,9 @@ define(['uploader'], function(uploader) {
// User Groups and privileges
socket.emit('admin.categories.groupsList', cid, function(err, results) {
if(err) {
return app.alertError(err.message);
}
var groupsFrag = document.createDocumentFragment(),
numResults = results.length,
trEl = document.createElement('tr'),

@ -64,7 +64,12 @@ define(function() {
bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) {
if (confirm) {
socket.emit('admin.groups.delete', gid, function(err, data) {
if (data === 'OK') ajaxify.go('admin/groups');
console.log(err, data);
if(err) {
return app.alertError(err.message);
}
ajaxify.go('admin/groups');
});
}
});

@ -64,7 +64,11 @@ define(function() {
}, false);
// Installed Themes
socket.emit('admin.themes.getInstalled', function(themes) {
socket.emit('admin.themes.getInstalled', function(err, themes) {
if(err) {
return app.alertError(err.message);
}
var instListEl = document.getElementById('installed_themes'),
themeFrag = document.createDocumentFragment(),
liEl = document.createElement('li');

@ -54,10 +54,13 @@ define(function() {
socket.emit('admin.topics.getMore', {
limit: 10,
after: lastTid
}, function(topics) {
}, function(err, topics) {
if(err) {
return app.alertError(err.message);
}
var btnEl = document.getElementById('topics_loadmore');
topics = JSON.parse(topics);
if (topics.length > 0) {
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
topics: topics

@ -126,16 +126,19 @@ define(function() {
}
function handleUserCreate() {
var errorEl = $('#create-modal-error');
$('#createUser').on('click', function() {
$('#create-modal').modal('show');
$('#create-modal form')[0].reset();
errorEl.addClass('hide');
});
$('#create-modal-go').on('click', function() {
var username = $('#create-user-name').val(),
email = $('#create-user-email').val(),
password = $('#create-user-password').val(),
passwordAgain = $('#create-user-password-again').val(),
errorEl = $('#create-modal-error');
passwordAgain = $('#create-user-password-again').val();
if(password !== passwordAgain) {
return errorEl.html('<strong>Error</strong><p>Passwords must match!</p>').removeClass('hide');
@ -147,13 +150,15 @@ define(function() {
password: password
};
socket.emit('admin.user.createUser', user, function(err, data) {
socket.emit('admin.user.createUser', user, function(err) {
if(err) {
return errorEl.html('<strong>Error</strong><p>' + err + '</p>').removeClass('hide');
return errorEl.html('<strong>Error</strong><p>' + err.message + '</p>').removeClass('hide');
}
$('#create-modal').modal('hide');
$('#create-modal').on('hidden.bs.modal', function() {
ajaxify.go('admin/users');
});
app.alertSuccess('User created!');
ajaxify.go('admin/users');
});
});
@ -191,7 +196,7 @@ define(function() {
socket.emit('admin.user.search', username, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}console.log(data)
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
users: data

@ -6,11 +6,16 @@ var utils = require('../../public/src/utils'),
UserAdmin.createUser = function(uid, userData, callback) {
user.isAdministrator(uid, function(err, isAdmin) {
if(err) {
return callback(err);
}
if (isAdmin) {
user.create(userData.username, userData.password, userData.email, function(err) {
if(err) {
return callback(err.message);
return callback(err);
}
callback(null);
});
} else {

@ -122,7 +122,7 @@ var fs = require('fs'),
'theme:templates': '',
'theme:src': ''
};
console.log(themeData);
switch(data.type) {
case 'local':
async.waterfall([

@ -35,9 +35,11 @@ SocketAdmin.before = function(socket, next) {
SocketAdmin.topics = {};
SocketAdmin.topics.getMore = function(socket, data, callback) {
topics.getAllTopics(data.limit, data.after, function(err, topics) {
callback(JSON.stringify(topics));
});
if(!data) {
return callback(new Error('invalid data'));
}
topics.getAllTopics(data.limit, data.after, callback);
};
/* User */
@ -53,15 +55,18 @@ SocketAdmin.user.removeAdmin = function(socket, theirid) {
};
SocketAdmin.user.createUser = function(socket, user, callback) {
if(!user) {
return callback(new Error('invalid data'));
}
admin.user.createUser(socket.uid, user, callback);
};
SocketAdmin.user.banUser = function(socket, theirid) {
admin.user.banUser(socket.uid, theirid, socket, function(isBanned) {
if(isBanned) {
if(socket.userSockets[theirid]) {
for(var i=0; i<socket.userSockets[theirid].length; ++i) {
socket.userSockets[theirid][i].emit('event:banned');
if(index.userSockets[theirid]) {
for(var i=0; i<index.userSockets[theirid].length; ++i) {
index.userSockets[theirid][i].emit('event:banned');
}
}
module.parent.exports.logoutUser(theirid);
@ -97,46 +102,56 @@ SocketAdmin.user.search = function(socket, username, callback) {
SocketAdmin.categories = {};
SocketAdmin.categories.create = function(socket, data, callback) {
categories.create(data, function(err, data) {
callback(err, data);
});
if(!data) {
return callback(new Error('invalid data'));
}
categories.create(data, callback);
};
SocketAdmin.categories.update = function(socket, data) {
if(!data) {
return callback(new Error('invalid data'));
}
admin.categories.update(data, socket);
};
SocketAdmin.categories.search = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
var username = data.username,
cid = data.cid;
user.search(username, function(data) {
async.map(data, function(userObj, next) {
CategoryTools.privileges(cid, userObj.uid, function(err, privileges) {
if (!err) {
userObj.privileges = privileges;
} else {
winston.error('[socket admin.categories.search] Could not retrieve permissions');
if(err) {
return next(err);
}
userObj.privileges = privileges;
next(null, userObj);
});
}, function(err, data) {
if (!callback) {
socket.emit('admin.categories.search', data);
} else {
callback(null, data);
}
});
}, callback);
});
};
SocketAdmin.categories.setPrivilege = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
var cid = data.cid,
uid = data.uid,
privilege = data.privilege,
set = data.set,
cb = function(err) {
if(err) {
return callback(err);
}
CategoryTools.privileges(cid, uid, callback);
};
@ -172,6 +187,10 @@ SocketAdmin.categories.getPrivilegeSettings = function(socket, cid, callback) {
});
}
}, function(err, data) {
if(err) {
return callback(err);
}
callback(null, {
"+r": data['+r'].members,
"+w": data['+w'].members
@ -180,6 +199,10 @@ SocketAdmin.categories.getPrivilegeSettings = function(socket, cid, callback) {
};
SocketAdmin.categories.setGroupPrivilege = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
if (data.set) {
groups.joinByGroupName('cid:' + data.cid + ':privileges:' + data.privilege, data.gid, callback);
} else {
@ -189,19 +212,20 @@ SocketAdmin.categories.setGroupPrivilege = function(socket, data, callback) {
SocketAdmin.categories.groupsList = function(socket, cid, callback) {
groups.list({expand:false}, function(err, data){
if(err) {
return callback(err);
}
async.map(data, function(groupObj, next) {
CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) {
if (!err) {
groupObj.privileges = privileges;
} else {
winston.error('[socket admin.categories.groupsList] Could not retrieve permissions');
if(err) {
return next(err);
}
groupObj.privileges = privileges;
next(null, groupObj);
});
}, function(err, data) {
callback(null, data);
});
}, callback);
});
};
@ -211,12 +235,15 @@ SocketAdmin.themes = {};
SocketAdmin.plugins = {};
SocketAdmin.themes.getInstalled = function(socket, data, callback) {
meta.themes.get(function(err, themeArr) {
callback(themeArr);
});
meta.themes.get(callback);
};
SocketAdmin.themes.set = meta.themes.set;
SocketAdmin.themes.set = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
meta.themes.set(data, callback);
}
SocketAdmin.plugins.toggle = function(socket, plugin_id) {
plugins.toggleActive(plugin_id, function(status) {
@ -233,6 +260,10 @@ SocketAdmin.config.get = function(socket, data, callback) {
};
SocketAdmin.config.set = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
meta.configs.set(data.key, data.value, function(err) {
if(err) {
return callback(err);
@ -258,34 +289,48 @@ SocketAdmin.config.remove = function(socket, key) {
SocketAdmin.groups = {};
SocketAdmin.groups.create = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
groups.create(data.name, data.description, function(err, groupObj) {
callback(err ? err.message : null, groupObj || undefined);
callback(err, groupObj || undefined);
});
};
SocketAdmin.groups.delete = function(socket, gid, callback) {
groups.destroy(gid, function(err) {
callback(err ? err.message : null, err ? null : 'OK');
});
groups.destroy(gid, callback);
};
SocketAdmin.groups.get = function(socket, gid, callback) {
groups.get(gid, {
expand: true
}, function(err, groupObj) {
callback(err ? err.message : null, groupObj || undefined);
callback(err, groupObj || undefined);
});
};
SocketAdmin.groups.join = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
groups.join(data.gid, data.uid, callback);
};
SocketAdmin.groups.leave = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
groups.leave(data.gid, data.uid, callback);
};
SocketAdmin.groups.update = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
groups.update(data.gid, data.values, function(err) {
callback(err ? err.message : null);
});

Loading…
Cancel
Save