mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
tweaks to category permission modal
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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.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);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
@@ -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) {
|
||||
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);
|
||||
Groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) {
|
||||
if (!err) {
|
||||
next.apply(this, arguments);
|
||||
} else {
|
||||
next(null, {
|
||||
members: []
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function(err, data) {
|
||||
if (!err) {
|
||||
callback(null, {
|
||||
"+r": data['+r'].members,
|
||||
"+w": data['+w'].members
|
||||
});
|
||||
} else {
|
||||
callback(null, {
|
||||
"+r": [],
|
||||
"+w": []
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user