mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 18:26:37 +02:00
admin panel integration for category whitelisting
This commit is contained in:
@@ -33,6 +33,8 @@ CategoryTools.privileges = function(cid, uid, callback) {
|
||||
}
|
||||
}, function(err, privileges) {
|
||||
callback(err, !privileges ? null : {
|
||||
"+r": privileges['+r'],
|
||||
"+w": privileges['+w'],
|
||||
read: privileges['+r'] || privileges.moderator || privileges.admin,
|
||||
write: privileges['+w'] || privileges.moderator || privileges.admin,
|
||||
editable: privileges.moderator || privileges.admin,
|
||||
|
||||
@@ -63,6 +63,16 @@
|
||||
});
|
||||
};
|
||||
|
||||
Groups.getByGroupName = function(groupName, options, callback) {
|
||||
Groups.getGidFromName(groupName, function(err, gid) {
|
||||
if (err || !gid) {
|
||||
callback(new Error('gid-not-found'));
|
||||
} else {
|
||||
Groups.get(gid, options, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Groups.isDeleted = function(gid, callback) {
|
||||
RDB.hget('gid:' + gid, 'deleted', function(err, deleted) {
|
||||
callback(err, deleted === '1');
|
||||
@@ -156,8 +166,28 @@
|
||||
RDB.sadd('gid:' + gid + ':members', uid, callback);
|
||||
};
|
||||
|
||||
Groups.joinByGroupName = function(groupName, uid, callback) {
|
||||
Groups.getGidFromName(groupName, function(err, gid) {
|
||||
if (err || !gid) {
|
||||
callback(new Error('gid-not-found'));
|
||||
} else {
|
||||
Groups.join(gid, uid, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Groups.leave = function(gid, uid, callback) {
|
||||
RDB.srem('gid:' + gid + ':members', uid, callback);
|
||||
};
|
||||
|
||||
Groups.leaveByGroupName = function(groupName, uid, callback) {
|
||||
Groups.getGidFromName(groupName, function(err, gid) {
|
||||
if (err || !gid) {
|
||||
callback(new Error('gid-not-found'));
|
||||
} else {
|
||||
Groups.leave(gid, uid, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}(module.exports));
|
||||
|
||||
@@ -21,6 +21,7 @@ var cookie = require('cookie'),
|
||||
utils = require('../public/src/utils'),
|
||||
topics = require('./topics'),
|
||||
categories = require('./categories'),
|
||||
CategoryTools = require('./categoryTools'),
|
||||
notifications = require('./notifications'),
|
||||
threadTools = require('./threadTools'),
|
||||
postTools = require('./postTools'),
|
||||
@@ -971,6 +972,53 @@ module.exports.init = function(io) {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:admin.categories.search', function(username, cid, callback) {
|
||||
if (uid && uid > 0) {
|
||||
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 api:admin.categories.search] Could not retrieve permissions');
|
||||
}
|
||||
|
||||
next(null, userObj);
|
||||
});
|
||||
}, function(err, data) {
|
||||
if (!callback) socket.emit('api:admin.categories.search', data);
|
||||
else callback(null, data);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if (!callback) socket.emit('api:admin.user.search', null);
|
||||
else callback();
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:admin.categories.setPrivilege', function(cid, uid, privilege, set, callback) {
|
||||
var cb = function(err) {
|
||||
CategoryTools.privileges(cid, uid, callback);
|
||||
};
|
||||
|
||||
if (set) {
|
||||
Groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb);
|
||||
} else {
|
||||
Groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) {
|
||||
async.parallel({
|
||||
"+r": function(next) {
|
||||
Groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, next);
|
||||
},
|
||||
"+w": function(next) {
|
||||
Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, next);
|
||||
}
|
||||
}, callback);
|
||||
});
|
||||
|
||||
socket.on('api:admin.themes.getInstalled', function(callback) {
|
||||
meta.themes.get(function(err, themeArr) {
|
||||
callback(themeArr);
|
||||
|
||||
Reference in New Issue
Block a user