more fixed to privs, and ACP modal

v1.18.x
Julian Lam 11 years ago
parent d54ecea506
commit 87f4566e06

@ -361,50 +361,22 @@ define(['uploader'], function(uploader) {
Categories.refreshPrivilegeList = function (cid) { Categories.refreshPrivilegeList = function (cid) {
var modalEl = $('#category-permissions-modal'), var modalEl = $('#category-permissions-modal'),
readMembers = modalEl.find('#category-permissions-read'), memberList = $('.members');
writeMembers = modalEl.find('#category-permissions-write'),
moderatorsEl = modalEl.find('#category-permissions-mods');
socket.emit('admin.categories.getPrivilegeSettings', cid, function(err, privilegeList) { socket.emit('admin.categories.getPrivilegeSettings', cid, function(err, privilegeList) {
var readLength = privilegeList['+r'].length, var membersLength = privilegeList.length,
writeLength = privilegeList['+w'].length,
modLength = privilegeList.mods.length,
liEl, x, userObj; liEl, x, userObj;
readMembers.html(''); memberList.html('');
if (readLength > 0) { if (membersLength > 0) {
for(x = 0; x < readLength; x++) { for(x = 0; x < membersLength; x++) {
userObj = privilegeList['+r'][x]; userObj = privilegeList[x];
liEl = $('<li/>').attr('data-uid', userObj.uid).html('<img src="' + userObj.picture + '" title="' + userObj.username + '" />'); liEl = $('<li/>').attr('data-uid', userObj.uid).html('<img src="' + userObj.picture + '" title="' + userObj.username + '" />');
readMembers.append(liEl); memberList.append(liEl);
} }
} else { } else {
liEl = $('<li/>').addClass('empty').html('All users can read and see this category'); liEl = $('<li/>').addClass('empty').html('All users can read and post, and reply to topics in this category');
readMembers.append(liEl); memberList.append(liEl);
}
writeMembers.html('');
if (writeLength > 0) {
for(x=0;x<writeLength;x++) {
userObj = privilegeList['+w'][x];
liEl = $('<li />').attr('data-uid', userObj.uid).html('<img src="' + userObj.picture + '" title="' + userObj.username + '" />');
writeMembers.append(liEl);
}
} else {
liEl = $('<li />').addClass('empty').html('All users can write to this category');
writeMembers.append(liEl);
}
moderatorsEl.html('');
if (modLength > 0) {
for(x = 0;x < modLength; x++) {
userObj = privilegeList.mods[x];
liEl = $('<li />').attr('data-uid', userObj.uid).html('<img src="' + userObj.picture + '" title="' + userObj.username + '" />');
moderatorsEl.append(liEl);
}
} else {
liEl = $('<li />').addClass('empty').html('No moderators');
moderatorsEl.append(liEl);
} }
}); });
}; };

@ -61,10 +61,12 @@ var winston = require('winston'),
} }
callback(null, { callback(null, {
read: results.topicPrivs.read, meta: {
editable: results.topicPrivs.editable || results.isOwner || results.hasEnoughRep, read: results.topicPrivs.meta.read,
view_deleted: results.topicPrivs.view_deleted || results.isOwner || results.hasEnoughRep, editable: results.topicPrivs.meta.editable || results.isOwner || results.hasEnoughRep,
move: results.topicPrivs.admin || results.topicPrivs.moderator view_deleted: results.topicPrivs.meta.view_deleted || results.isOwner || results.hasEnoughRep,
move: results.topicPrivs.admin || results.topicPrivs.mods
}
}); });
}); });
}; };

@ -69,50 +69,31 @@ Categories.setPrivilege = function(socket, data, callback) {
}; };
Categories.getPrivilegeSettings = function(socket, cid, callback) { Categories.getPrivilegeSettings = function(socket, cid, callback) {
async.parallel({ var privileges = ['read', 'topics:create', 'topics:reply', 'mods'];
"+r": function(next) {
groups.get('cid:' + cid + ':privileges:+r', { expand: true }, function(err, groupObj) { async.reduce(privileges, [], function(members, privilege, next) {
if (!err) { groups.get('cid:' + cid + ':privileges:' + privilege, { expand: true }, function(err, groupObj) {
next.apply(this, arguments); if (!err) {
} else { members = members.concat(groupObj.members);
next(null, { }
members: []
});
}
});
},
"+w": function(next) {
groups.get('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) {
if (!err) {
next.apply(this, arguments);
} else {
next(null, {
members: []
});
}
});
},
"mods": function(next) {
groups.get('cid:' + cid + ':privileges:mods', { expand: true }, function(err, groupObj) {
if (!err) {
next.apply(this, arguments);
} else {
next(null, {
members: []
});
}
});
}
}, function(err, data) {
if(err) {
return callback(err);
}
callback(null, { next(null, members);
"+r": data['+r'].members,
"+w": data['+w'].members,
"mods": data.mods.members
}); });
}, function(err, members) {
// Remove duplicates
var present = [],
x = members.length,
uid;
while(x--) {
uid = parseInt(members[x].uid, 10);
if (present.indexOf(uid) !== -1) {
members.splice(x, 1);
} else {
present.push(uid);
}
}
callback(err, members);
}); });
}; };

@ -130,7 +130,7 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
postTools.privileges(pid, socket.uid, next); postTools.privileges(pid, socket.uid, next);
}, },
function(privileges, next) { function(privileges, next) {
if (!privileges || !privileges.read) { if (!privileges || !privileges.meta.read) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
posts.getPostFields(pid, ['content', 'deleted'], next); posts.getPostFields(pid, ['content', 'deleted'], next);

@ -133,7 +133,7 @@ var async = require('async'),
async.filter(tids, function(tid, next) { async.filter(tids, function(tid, next) {
threadTools.privileges(tid, uid, function(err, privileges) { threadTools.privileges(tid, uid, function(err, privileges) {
next(!err && privileges.read); next(!err && privileges.meta.read);
}); });
}, function(tids) { }, function(tids) {
Topics.getTopicsByTids(tids, uid, function(err, topicData) { Topics.getTopicsByTids(tids, uid, function(err, topicData) {

@ -50,7 +50,7 @@ module.exports = function(Topics) {
async.filter(newtids, function(tid, next) { async.filter(newtids, function(tid, next) {
threadTools.privileges(tid, uid, function(err, privileges) { threadTools.privileges(tid, uid, function(err, privileges) {
next(!err && privileges.read); next(!err && privileges.meta.read);
}); });
}, function(newtids) { }, function(newtids) {
unreadTids.push.apply(unreadTids, newtids); unreadTids.push.apply(unreadTids, newtids);

Loading…
Cancel
Save