diff --git a/src/categoryTools.js b/src/categoryTools.js
index 7ef88d3854..9fe38c80b2 100644
--- a/src/categoryTools.js
+++ b/src/categoryTools.js
@@ -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,
diff --git a/src/groups.js b/src/groups.js
index d47e93624d..df6d6fa500 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -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));
diff --git a/src/websockets.js b/src/websockets.js
index 94d95facca..7557e592c0 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -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);