admin cleanup
removed unnecessary admin checks in src/admin/user then realized they are just one liners so moved them to src/socket.io.admin.js moved categories update to categories folderv1.18.x
parent
ac88b5fc25
commit
10f56faf9d
@ -1,112 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async'),
|
||||
utils = require('../../public/src/utils'),
|
||||
user = require('../user'),
|
||||
groups = require('../groups');
|
||||
|
||||
(function(UserAdmin) {
|
||||
|
||||
UserAdmin.createUser = function(uid, userData, callback) {
|
||||
user.isAdministrator(uid, function(err, isAdmin) {
|
||||
if(err || !isAdmin) {
|
||||
return callback(err || new Error('You are not an administrator'));
|
||||
}
|
||||
|
||||
user.create(userData, callback);
|
||||
});
|
||||
};
|
||||
|
||||
UserAdmin.makeAdmin = function(uid, theirid, socket) {
|
||||
user.isAdministrator(uid, function(err, isAdmin) {
|
||||
if (isAdmin) {
|
||||
groups.join('administrators', theirid, function(err) {
|
||||
if (!err) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'User Modified',
|
||||
message: 'This user is now an administrator!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Warning',
|
||||
message: 'You need to be an administrator to make someone else an administrator!',
|
||||
type: 'warning',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
UserAdmin.removeAdmin = function(uid, theirid, socket) {
|
||||
user.isAdministrator(uid, function(err, isAdmin) {
|
||||
if (isAdmin) {
|
||||
groups.leave('administrators', theirid, function(err) {
|
||||
if (!err) {
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'User Modified',
|
||||
message: 'This user is no longer an administrator!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
UserAdmin.banUser = function(uid, theirid, socket, callback) {
|
||||
user.isAdministrator(uid, function(err, amIAdmin) {
|
||||
user.isAdministrator(theirid, function(err, areTheyAdmin) {
|
||||
if (amIAdmin && !areTheyAdmin) {
|
||||
user.ban(theirid, function(err, result) {
|
||||
callback(true);
|
||||
socket.emit('event:alert', {
|
||||
alert_id: 'ban_user',
|
||||
title: 'User Banned',
|
||||
message: 'This user is banned!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
UserAdmin.unbanUser = function(uid, theirid, socket) {
|
||||
user.isAdministrator(uid, function(err, amIAdmin) {
|
||||
if (amIAdmin) {
|
||||
user.unban(theirid, function(err, result) {
|
||||
socket.emit('event:alert', {
|
||||
alert_id: 'ban_user',
|
||||
title: 'User Unbanned',
|
||||
message: 'This user is unbanned!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
UserAdmin.deleteUser = function(uid, theirid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
function(isAdmin, next) {
|
||||
if(!isAdmin) {
|
||||
return next(new Error('You are not an administrator'));
|
||||
}
|
||||
user.delete(uid, theirid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
}(exports));
|
Loading…
Reference in New Issue