privilege fix for single category check

v1.18.x
barisusakli 11 years ago
parent e7700a3fde
commit e420ee5fb6

@ -26,6 +26,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
events.removeListeners(); events.removeListeners();
socket.removeListener('event:new_post', onNewPost); socket.removeListener('event:new_post', onNewPost);
socket.removeListener('event:new_notification', onNewNotification);
} }
}); });
@ -65,6 +66,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
navigator.init('.posts > .post-row', postCount, Topic.navigatorCallback, Topic.toTop, Topic.toBottom); navigator.init('.posts > .post-row', postCount, Topic.navigatorCallback, Topic.toTop, Topic.toBottom);
socket.on('event:new_post', onNewPost); socket.on('event:new_post', onNewPost);
socket.on('event:new_notification', onNewNotification);
$(window).on('scroll', updateTopicTitle); $(window).on('scroll', updateTopicTitle);
@ -145,11 +147,17 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
var postcount = $('.user_postcount_' + data.posts[i].uid); var postcount = $('.user_postcount_' + data.posts[i].uid);
postcount.html(parseInt(postcount.html(), 10) + 1); postcount.html(parseInt(postcount.html(), 10) + 1);
} }
socket.emit('topics.markAsRead', tid); socket.emit('topics.markAsRead', tid);
createNewPosts(data); createNewPosts(data);
} }
function onNewNotification(data) {
var tid = ajaxify.variables.get('topic_id');
if (data && data.tid && parseInt(data.tid, 10) === tid) {
socket.emit('topics.markTopicNotificationsRead', tid);
}
}
function addBlockQuoteHandler() { function addBlockQuoteHandler() {
$('#post-container').on('click', 'blockquote .toggle', function() { $('#post-container').on('click', 'blockquote .toggle', function() {
var blockQuote = $(this).parent('blockquote'); var blockQuote = $(this).parent('blockquote');

@ -24,53 +24,47 @@ var async = require('async'),
}; };
Notifications.get = function(nid, callback) { Notifications.get = function(nid, callback) {
db.exists('notifications:' + nid, function(err, exists) { db.getObject('notifications:' + nid, function(err, notification) {
if (err) { if (err) {
winston.error('[notifications.get] Could not retrieve nid ' + nid + ': ' + err.message);
return callback(err); return callback(err);
} }
if (!exists) { if (!notification) {
winston.info('[notifications.get] Could not retrieve nid ' + nid);
return callback(null, null); return callback(null, null);
} }
db.getObject('notifications:' + nid, function(err, notification) { // Backwards compatibility for old notification schema
if (err) { // Remove this block when NodeBB v0.6.0 is released.
return callback(err); if (notification.hasOwnProperty('text')) {
} notification.bodyShort = notification.text;
notification.bodyLong = '';
// Backwards compatibility for old notification schema notification.text = S(notification.text).escapeHTML().s;
// Remove this block when NodeBB v0.6.0 is released. }
if (notification.hasOwnProperty('text')) {
notification.bodyShort = notification.text;
notification.bodyLong = '';
notification.text = S(notification.text).escapeHTML().s;
}
notification.bodyShort = S(notification.bodyShort).escapeHTML().s; notification.bodyShort = S(notification.bodyShort).escapeHTML().s;
notification.bodyLong = S(notification.bodyLong).escapeHTML().s; notification.bodyLong = S(notification.bodyLong).escapeHTML().s;
if (notification.from && !notification.image) { if (notification.from && !notification.image) {
User.getUserField(notification.from, 'picture', function(err, picture) { User.getUserField(notification.from, 'picture', function(err, picture) {
if (err) { if (err) {
return callback(err); return callback(err);
}
notification.image = picture;
callback(null, notification);
});
return;
} else if (notification.image) {
switch(notification.image) {
case 'brand:logo':
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
break;
} }
notification.image = picture;
return callback(null, notification); callback(null, notification);
});
return;
} else if (notification.image) {
switch(notification.image) {
case 'brand:logo':
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
break;
} }
callback(null, notification); return callback(null, notification);
}); }
callback(null, notification);
}); });
}; };
@ -207,18 +201,13 @@ var async = require('async'),
} }
Notifications.pushGroup = function(nid, groupName, callback) { Notifications.pushGroup = function(nid, groupName, callback) {
if (!callback) { callback = callback || function() {};
callback = function() {};
}
groups.get(groupName, {}, function(err, groupObj) { groups.get(groupName, {}, function(err, groupObj) {
if (!err && groupObj) { if (err || !groupObj || !Array.isArray(groupObj.members) || !groupObj.members.length) {
if (groupObj.memberCount > 0) { return callback(err);
Notifications.push(nid, groupObj.members, callback);
}
} else {
callback(err);
} }
Notifications.push(nid, groupObj.members, callback);
}); });
}; };
@ -229,7 +218,7 @@ var async = require('async'),
return callback(); return callback();
} }
Notifications.get(nid, function(err, notificationData) { db.getObjectFields('notifications:' + nid, ['uniqueId', 'datetime'], function(err, notificationData) {
if (err || !notificationData) { if (err || !notificationData) {
return callback(err); return callback(err);
} }

@ -16,10 +16,10 @@ module.exports = function(privileges) {
privileges.categories.get = function(cid, uid, callback) { privileges.categories.get = function(cid, uid, callback) {
async.parallel({ async.parallel({
'topics:create': function(next) { 'topics:create': function(next) {
helpers.allowedTo('topics:create', uid, cid, next); helpers.allowedTo('topics:create', uid, [cid], next);
}, },
read: function(next) { read: function(next) {
helpers.allowedTo('read', uid, cid, next); helpers.allowedTo('read', uid, [cid], next);
}, },
isAdministrator: function(next) { isAdministrator: function(next) {
user.isAdministrator(uid, next); user.isAdministrator(uid, next);
@ -35,10 +35,10 @@ module.exports = function(privileges) {
var editable = results.isAdministrator || results.isModerator; var editable = results.isAdministrator || results.isModerator;
callback(null, { callback(null, {
'topics:create': results['topics:create'], 'topics:create': results['topics:create'][0],
editable: editable, editable: editable,
view_deleted: editable, view_deleted: editable,
read: results.read read: results.read[0]
}); });
}); });
}; };
@ -55,7 +55,9 @@ module.exports = function(privileges) {
helpers.some([ helpers.some([
function(next) { function(next) {
helpers.allowedTo(privilege, uid, cid, next); helpers.allowedTo(privilege, uid, [cid], function(err, results) {
next(err, Array.isArray(results) && results.length ? results[0] : false);
});
}, },
function(next) { function(next) {
user.isModerator(uid, cid, next); user.isModerator(uid, cid, next);

@ -21,11 +21,6 @@ helpers.some = function(tasks, callback) {
}; };
helpers.allowedTo = function(privilege, uid, cids, callback) { helpers.allowedTo = function(privilege, uid, cids, callback) {
if (!Array.isArray(cids)) {
cids = [cids];
}
if (parseInt(uid, 10) === 0) { if (parseInt(uid, 10) === 0) {
return isGuestAllowedTo(privilege, cids, callback); return isGuestAllowedTo(privilege, cids, callback);
} }
@ -61,9 +56,6 @@ helpers.allowedTo = function(privilege, uid, cids, callback) {
result.push((!results.userPrivilegeExists[i] && !results.groupPrivilegeExists[i]) || results.hasUserPrivilege[i] || results.hasGroupPrivilege[i]); result.push((!results.userPrivilegeExists[i] && !results.groupPrivilegeExists[i]) || results.hasUserPrivilege[i] || results.hasGroupPrivilege[i]);
} }
if (result.length === 1) {
result = result[0];
}
callback(null, result); callback(null, result);
}); });
@ -100,10 +92,6 @@ function isGuestAllowedTo(privilege, cids, callback) {
result.push(!results.userPrivilegeExists[i] && groupPriv); result.push(!results.userPrivilegeExists[i] && groupPriv);
} }
if (result.length === 1) {
result = result[0];
}
callback(null, result); callback(null, result);
}); });
} }

@ -23,10 +23,10 @@ module.exports = function(privileges) {
async.parallel({ async.parallel({
'topics:reply': function(next) { 'topics:reply': function(next) {
helpers.allowedTo('topics:reply', uid, cid, next); helpers.allowedTo('topics:reply', uid, [cid], next);
}, },
read: function(next) { read: function(next) {
helpers.allowedTo('read', uid, cid, next); helpers.allowedTo('read', uid, [cid], next);
}, },
isOwner: function(next) { isOwner: function(next) {
topics.isOwner(tid, uid, next); topics.isOwner(tid, uid, next);
@ -53,8 +53,8 @@ module.exports = function(privileges) {
var deletable = isAdminOrMod || results.isOwner; var deletable = isAdminOrMod || results.isOwner;
callback(null, { callback(null, {
'topics:reply': results['topics:reply'], 'topics:reply': results['topics:reply'][0],
read: results.read, read: results.read[0],
view_thread_tools: editable || deletable, view_thread_tools: editable || deletable,
editable: editable, editable: editable,
deletable: deletable, deletable: deletable,

@ -73,12 +73,10 @@ SocketTopics.markAsRead = function(socket, tid) {
topics.markAsRead(tid, socket.uid, function(err) { topics.markAsRead(tid, socket.uid, function(err) {
topics.pushUnreadCount(socket.uid); topics.pushUnreadCount(socket.uid);
topics.markTopicNotificationsRead(tid, socket.uid);
}); });
}; };
SocketTopics.markTidsRead = function(socket, tids, callback) { SocketTopics.markTidsRead = function(socket, tids, callback) {
if (!Array.isArray(tids)) { if (!Array.isArray(tids)) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
@ -98,6 +96,13 @@ SocketTopics.markTidsRead = function(socket, tids, callback) {
}); });
}; };
SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) {
if(!tid || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
topics.markTopicNotificationsRead(tid, socket.uid);
};
SocketTopics.markAllRead = function(socket, data, callback) { SocketTopics.markAllRead = function(socket, data, callback) {
topics.getUnreadTids(socket.uid, 0, -1, function(err, tids) { topics.getUnreadTids(socket.uid, 0, -1, function(err, tids) {
if (err) { if (err) {

@ -200,9 +200,6 @@ module.exports = function(Topics) {
}, },
function(data, next) { function(data, next) {
postData = data; postData = data;
next();
},
function(next) {
Topics.markAsUnreadForAll(tid, next); Topics.markAsUnreadForAll(tid, next);
}, },
function(next) { function(next) {
@ -218,9 +215,6 @@ module.exports = function(Topics) {
function(topicData, next) { function(topicData, next) {
topicData.title = validator.escape(topicData.title); topicData.title = validator.escape(topicData.title);
postData.topic = topicData; postData.topic = topicData;
next();
},
function(next) {
posts.getPidIndex(postData.pid, next); posts.getPidIndex(postData.pid, next);
}, },
function(index, next) { function(index, next) {

Loading…
Cancel
Save