Skip to content

Node.js based forum software built for the modern web

tweaks to category permission modal

Julian Lam38da65ee5897
diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js
index a9985cabad..3f9224d626 100644
--- a/public/src/forum/admin/categories.js
+++ b/public/src/forum/admin/categories.js
@@ -187,7 +187,7 @@ define(function() {
resultsEl = modal.find('.search-results'),
searchDelay;
- searchEl.off('keyup').on('keyup', function() {
+ searchEl.off().on('keyup', function() {
var searchEl = this,
resultsFrag = document.createDocumentFragment(),
liEl = document.createElement('li');
@@ -219,7 +219,7 @@ define(function() {
Categories.refreshPrivilegeList(cid);
- resultsEl.on('click', '[data-priv]', function(e) {
+ resultsEl.off().on('click', '[data-priv]', function(e) {
var btnEl = $(this),
uid = btnEl.parents('li[data-uid]').attr('data-uid'),
privilege = this.getAttribute('data-priv');
@@ -232,8 +232,7 @@ define(function() {
});
});
- modal.on('click', '.members li > img', function() {
- console.log('clicked', this);
+ modal.off().on('click', '.members li > img', function() {
searchEl.val(this.getAttribute('title'));
searchEl.keyup();
});
@@ -246,6 +245,7 @@ define(function() {
readMembers = modalEl.find('#category-permissions-read'),
writeMembers = modalEl.find('#category-permissions-write');
socket.emit('api:admin.categories.getPrivilegeSettings', cid, function(err, privilegeList) {
+ console.log('privlist', privilegeList);
var readLength = privilegeList['+r'].length,
writeLength = privilegeList['+w'].length,
readFrag = document.createDocumentFragment(),
diff --git a/src/groups.js b/src/groups.js
index e0abb71b92..058b8fdd08 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -15,7 +15,6 @@
}, function (err, groups) {
// Remove deleted and hidden groups from this list
callback(err, groups.filter(function (group) {
- console.log(group);
if (group.deleted === '1' || group.hidden === '1') {
return false;
} else {
@@ -165,30 +164,25 @@
});
};
- Groups.hide = function(gid) {
- Groups.exists(gid, function(err, exists) {
- if (exists) {
- Groups.update(gid, {
- hidden: '1'
- });
- }
- });
+ Groups.hide = function(gid, callback) {
+ Groups.update(gid, {
+ hidden: '1'
+ }, callback);
};
Groups.update = function(gid, values, callback) {
RDB.exists('gid:' + gid, function (err, exists) {
+ console.log('exists?', gid, exists, values);
if (!err && exists) {
RDB.hmset('gid:' + gid, values, callback);
} else {
- callback(new Error('gid-not-found'));
+ if (callback) callback(new Error('gid-not-found'));
}
});
};
Groups.destroy = function(gid, callback) {
- if (gid !== 1) {
- RDB.hset('gid:' + gid, 'deleted', '1', callback);
- }
+ RDB.hset('gid:' + gid, 'deleted', '1', callback);
};
Groups.join = function(gid, uid, callback) {
@@ -199,8 +193,15 @@
Groups.getGidFromName(groupName, function(err, gid) {
if (err || !gid) {
Groups.create(groupName, '', function(err, groupObj) {
- Groups.hide(groupObj.gid);
- Groups.join(groupObj.gid, uid, callback);
+ console.log('creating group, calling hide', groupObj.gid);
+ async.parallel([
+ function(next) {
+ Groups.hide(groupObj.gid, next);
+ },
+ function(next) {
+ Groups.join(groupObj.gid, uid, next);
+ }
+ ], callback);
});
} else {
Groups.join(gid, uid, callback);
diff --git a/src/routes/debug.js b/src/routes/debug.js
index ba81edd7bc..1cd17ee9d9 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -54,6 +54,14 @@ var DebugRoute = function(app) {
}
});
});
+
+ app.get('/groups/prune', function(req, res) {
+ var Groups = require('../groups');
+
+ Groups.prune(function(err) {
+ res.send('pruned');
+ });
+ });
});
};
diff --git a/src/websockets.js b/src/websockets.js
index df0e007eeb..7b17843100 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -1011,23 +1011,32 @@ module.exports.init = function(io) {
socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) {
async.parallel({
"+r": function(next) {
- Groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, next);
+ Groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, function(err, groupObj) {
+ if (!err) {
+ next.apply(this, arguments);
+ } else {
+ next(null, {
+ members: []
+ });
+ }
+ });
},
"+w": function(next) {
- Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, next);
- }
- }, function(err, data) {
- if (!err) {
- callback(null, {
- "+r": data['+r'].members,
- "+w": data['+w'].members
- });
- } else {
- callback(null, {
- "+r": [],
- "+w": []
+ Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) {
+ if (!err) {
+ next.apply(this, arguments);
+ } else {
+ next(null, {
+ members: []
+ });
+ }
});
}
+ }, function(err, data) {
+ callback(null, {
+ "+r": data['+r'].members,
+ "+w": data['+w'].members
+ });
});
});