tweaks to category permission modal

v1.18.x
Julian Lam 12 years ago
parent e3e1a556cd
commit 38da65ee58

@ -187,7 +187,7 @@ define(function() {
resultsEl = modal.find('.search-results'), resultsEl = modal.find('.search-results'),
searchDelay; searchDelay;
searchEl.off('keyup').on('keyup', function() { searchEl.off().on('keyup', function() {
var searchEl = this, var searchEl = this,
resultsFrag = document.createDocumentFragment(), resultsFrag = document.createDocumentFragment(),
liEl = document.createElement('li'); liEl = document.createElement('li');
@ -219,7 +219,7 @@ define(function() {
Categories.refreshPrivilegeList(cid); Categories.refreshPrivilegeList(cid);
resultsEl.on('click', '[data-priv]', function(e) { resultsEl.off().on('click', '[data-priv]', function(e) {
var btnEl = $(this), var btnEl = $(this),
uid = btnEl.parents('li[data-uid]').attr('data-uid'), uid = btnEl.parents('li[data-uid]').attr('data-uid'),
privilege = this.getAttribute('data-priv'); privilege = this.getAttribute('data-priv');
@ -232,8 +232,7 @@ define(function() {
}); });
}); });
modal.on('click', '.members li > img', function() { modal.off().on('click', '.members li > img', function() {
console.log('clicked', this);
searchEl.val(this.getAttribute('title')); searchEl.val(this.getAttribute('title'));
searchEl.keyup(); searchEl.keyup();
}); });
@ -246,6 +245,7 @@ define(function() {
readMembers = modalEl.find('#category-permissions-read'), readMembers = modalEl.find('#category-permissions-read'),
writeMembers = modalEl.find('#category-permissions-write'); writeMembers = modalEl.find('#category-permissions-write');
socket.emit('api:admin.categories.getPrivilegeSettings', cid, function(err, privilegeList) { socket.emit('api:admin.categories.getPrivilegeSettings', cid, function(err, privilegeList) {
console.log('privlist', privilegeList);
var readLength = privilegeList['+r'].length, var readLength = privilegeList['+r'].length,
writeLength = privilegeList['+w'].length, writeLength = privilegeList['+w'].length,
readFrag = document.createDocumentFragment(), readFrag = document.createDocumentFragment(),

@ -15,7 +15,6 @@
}, function (err, groups) { }, function (err, groups) {
// Remove deleted and hidden groups from this list // Remove deleted and hidden groups from this list
callback(err, groups.filter(function (group) { callback(err, groups.filter(function (group) {
console.log(group);
if (group.deleted === '1' || group.hidden === '1') { if (group.deleted === '1' || group.hidden === '1') {
return false; return false;
} else { } else {
@ -165,30 +164,25 @@
}); });
}; };
Groups.hide = function(gid) { Groups.hide = function(gid, callback) {
Groups.exists(gid, function(err, exists) {
if (exists) {
Groups.update(gid, { Groups.update(gid, {
hidden: '1' hidden: '1'
}); }, callback);
}
});
}; };
Groups.update = function(gid, values, callback) { Groups.update = function(gid, values, callback) {
RDB.exists('gid:' + gid, function (err, exists) { RDB.exists('gid:' + gid, function (err, exists) {
console.log('exists?', gid, exists, values);
if (!err && exists) { if (!err && exists) {
RDB.hmset('gid:' + gid, values, callback); RDB.hmset('gid:' + gid, values, callback);
} else { } else {
callback(new Error('gid-not-found')); if (callback) callback(new Error('gid-not-found'));
} }
}); });
}; };
Groups.destroy = function(gid, callback) { 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) { Groups.join = function(gid, uid, callback) {
@ -199,8 +193,15 @@
Groups.getGidFromName(groupName, function(err, gid) { Groups.getGidFromName(groupName, function(err, gid) {
if (err || !gid) { if (err || !gid) {
Groups.create(groupName, '', function(err, groupObj) { Groups.create(groupName, '', function(err, groupObj) {
Groups.hide(groupObj.gid); console.log('creating group, calling hide', groupObj.gid);
Groups.join(groupObj.gid, uid, callback); async.parallel([
function(next) {
Groups.hide(groupObj.gid, next);
},
function(next) {
Groups.join(groupObj.gid, uid, next);
}
], callback);
}); });
} else { } else {
Groups.join(gid, uid, callback); Groups.join(gid, uid, callback);

@ -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');
});
});
}); });
}; };

@ -1011,23 +1011,32 @@ module.exports.init = function(io) {
socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) { socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) {
async.parallel({ async.parallel({
"+r": function(next) { "+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) { "+w": function(next) {
Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, next); Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) {
if (!err) {
next.apply(this, arguments);
} else {
next(null, {
members: []
});
}
});
} }
}, function(err, data) { }, function(err, data) {
if (!err) {
callback(null, { callback(null, {
"+r": data['+r'].members, "+r": data['+r'].members,
"+w": data['+w'].members "+w": data['+w'].members
}); });
} else {
callback(null, {
"+r": [],
"+w": []
});
}
}); });
}); });

Loading…
Cancel
Save