mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	privilege fix for single category check
This commit is contained in:
		| @@ -26,6 +26,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT | ||||
| 			events.removeListeners(); | ||||
|  | ||||
| 			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); | ||||
|  | ||||
| 		socket.on('event:new_post', onNewPost); | ||||
| 		socket.on('event:new_notification', onNewNotification); | ||||
|  | ||||
| 		$(window).on('scroll', updateTopicTitle); | ||||
|  | ||||
| @@ -145,11 +147,17 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT | ||||
| 			var postcount = $('.user_postcount_' + data.posts[i].uid); | ||||
| 			postcount.html(parseInt(postcount.html(), 10) + 1); | ||||
| 		} | ||||
|  | ||||
| 		socket.emit('topics.markAsRead', tid); | ||||
| 		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() { | ||||
| 		$('#post-container').on('click', 'blockquote .toggle', function() { | ||||
| 			var blockQuote = $(this).parent('blockquote'); | ||||
|   | ||||
| @@ -24,53 +24,47 @@ var async = require('async'), | ||||
| 	}; | ||||
|  | ||||
| 	Notifications.get = function(nid, callback) { | ||||
| 		db.exists('notifications:' + nid, function(err, exists) { | ||||
| 		db.getObject('notifications:' + nid, function(err, notification) { | ||||
| 			if (err) { | ||||
| 				winston.error('[notifications.get] Could not retrieve nid ' + nid + ': ' + err.message); | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			if (!exists) { | ||||
| 			if (!notification) { | ||||
| 				winston.info('[notifications.get] Could not retrieve nid ' + nid); | ||||
| 				return callback(null, null); | ||||
| 			} | ||||
|  | ||||
| 			db.getObject('notifications:' + nid, function(err, notification) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| 			// Backwards compatibility for old notification schema | ||||
| 			// 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; | ||||
| 			} | ||||
|  | ||||
| 				// Backwards compatibility for old notification schema | ||||
| 				// 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.bodyLong = S(notification.bodyLong).escapeHTML().s; | ||||
|  | ||||
| 				notification.bodyShort = S(notification.bodyShort).escapeHTML().s; | ||||
| 				notification.bodyLong = S(notification.bodyLong).escapeHTML().s; | ||||
|  | ||||
| 				if (notification.from && !notification.image) { | ||||
| 					User.getUserField(notification.from, 'picture', function(err, picture) { | ||||
| 						if (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; | ||||
| 			if (notification.from && !notification.image) { | ||||
| 				User.getUserField(notification.from, 'picture', function(err, picture) { | ||||
| 					if (err) { | ||||
| 						return callback(err); | ||||
| 					} | ||||
|  | ||||
| 					return callback(null, notification); | ||||
| 					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; | ||||
| 				} | ||||
|  | ||||
| 				callback(null, notification); | ||||
| 			}); | ||||
| 				return callback(null, notification); | ||||
| 			} | ||||
|  | ||||
| 			callback(null, notification); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| @@ -207,18 +201,13 @@ var async = require('async'), | ||||
| 	} | ||||
|  | ||||
| 	Notifications.pushGroup = function(nid, groupName, callback) { | ||||
| 		if (!callback) { | ||||
| 			callback = function() {}; | ||||
| 		} | ||||
|  | ||||
| 		callback = callback || function() {}; | ||||
| 		groups.get(groupName, {}, function(err, groupObj) { | ||||
| 			if (!err && groupObj) { | ||||
| 				if (groupObj.memberCount > 0) { | ||||
| 					Notifications.push(nid, groupObj.members, callback); | ||||
| 				} | ||||
| 			} else { | ||||
| 				callback(err); | ||||
| 			if (err || !groupObj || !Array.isArray(groupObj.members) || !groupObj.members.length) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			Notifications.push(nid, groupObj.members, callback); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| @@ -229,7 +218,7 @@ var async = require('async'), | ||||
| 			return callback(); | ||||
| 		} | ||||
|  | ||||
| 		Notifications.get(nid, function(err, notificationData) { | ||||
| 		db.getObjectFields('notifications:' + nid, ['uniqueId', 'datetime'], function(err, notificationData) { | ||||
| 			if (err || !notificationData)  { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|   | ||||
| @@ -16,10 +16,10 @@ module.exports = function(privileges) { | ||||
| 	privileges.categories.get = function(cid, uid, callback) { | ||||
| 		async.parallel({ | ||||
| 			'topics:create': function(next) { | ||||
| 				helpers.allowedTo('topics:create', uid, cid, next); | ||||
| 				helpers.allowedTo('topics:create', uid, [cid], next); | ||||
| 			}, | ||||
| 			read: function(next) { | ||||
| 				helpers.allowedTo('read', uid, cid, next); | ||||
| 				helpers.allowedTo('read', uid, [cid], next); | ||||
| 			}, | ||||
| 			isAdministrator: function(next) { | ||||
| 				user.isAdministrator(uid, next); | ||||
| @@ -35,10 +35,10 @@ module.exports = function(privileges) { | ||||
| 			var editable = results.isAdministrator || results.isModerator; | ||||
|  | ||||
| 			callback(null, { | ||||
| 				'topics:create': results['topics:create'], | ||||
| 				'topics:create': results['topics:create'][0], | ||||
| 				editable: editable, | ||||
| 				view_deleted: editable, | ||||
| 				read: results.read | ||||
| 				read: results.read[0] | ||||
| 			}); | ||||
| 		}); | ||||
| 	}; | ||||
| @@ -55,7 +55,9 @@ module.exports = function(privileges) { | ||||
|  | ||||
| 			helpers.some([ | ||||
| 				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) { | ||||
| 					user.isModerator(uid, cid, next); | ||||
|   | ||||
| @@ -21,11 +21,6 @@ helpers.some = function(tasks, callback) { | ||||
| }; | ||||
|  | ||||
| helpers.allowedTo = function(privilege, uid, cids, callback) { | ||||
|  | ||||
| 	if (!Array.isArray(cids)) { | ||||
| 		cids = [cids]; | ||||
| 	} | ||||
|  | ||||
| 	if (parseInt(uid, 10) === 0) { | ||||
| 		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]); | ||||
| 		} | ||||
|  | ||||
| 		if (result.length === 1) { | ||||
| 			result = result[0]; | ||||
| 		} | ||||
|  | ||||
| 		callback(null, result); | ||||
| 	}); | ||||
| @@ -100,10 +92,6 @@ function isGuestAllowedTo(privilege, cids, callback) { | ||||
| 			result.push(!results.userPrivilegeExists[i] && groupPriv); | ||||
| 		} | ||||
|  | ||||
| 		if (result.length === 1) { | ||||
| 			result = result[0]; | ||||
| 		} | ||||
|  | ||||
| 		callback(null, result); | ||||
| 	}); | ||||
| } | ||||
|   | ||||
| @@ -23,10 +23,10 @@ module.exports = function(privileges) { | ||||
|  | ||||
| 			async.parallel({ | ||||
| 				'topics:reply': function(next) { | ||||
| 					helpers.allowedTo('topics:reply', uid, cid, next); | ||||
| 					helpers.allowedTo('topics:reply', uid, [cid], next); | ||||
| 				}, | ||||
| 				read: function(next) { | ||||
| 					helpers.allowedTo('read', uid, cid, next); | ||||
| 					helpers.allowedTo('read', uid, [cid], next); | ||||
| 				}, | ||||
| 				isOwner: function(next) { | ||||
| 					topics.isOwner(tid, uid, next); | ||||
| @@ -53,8 +53,8 @@ module.exports = function(privileges) { | ||||
| 				var deletable = isAdminOrMod || results.isOwner; | ||||
|  | ||||
| 				callback(null, { | ||||
| 					'topics:reply': results['topics:reply'], | ||||
| 					read: results.read, | ||||
| 					'topics:reply': results['topics:reply'][0], | ||||
| 					read: results.read[0], | ||||
| 					view_thread_tools: editable || deletable, | ||||
| 					editable: editable, | ||||
| 					deletable: deletable, | ||||
|   | ||||
| @@ -73,12 +73,10 @@ SocketTopics.markAsRead = function(socket, tid) { | ||||
|  | ||||
| 	topics.markAsRead(tid, socket.uid, function(err) { | ||||
| 		topics.pushUnreadCount(socket.uid); | ||||
| 		topics.markTopicNotificationsRead(tid, socket.uid); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| SocketTopics.markTidsRead = function(socket, tids, callback) { | ||||
|  | ||||
| 	if (!Array.isArray(tids)) { | ||||
| 		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) { | ||||
| 	topics.getUnreadTids(socket.uid, 0, -1, function(err, tids) { | ||||
| 		if (err) { | ||||
|   | ||||
| @@ -200,9 +200,6 @@ module.exports = function(Topics) { | ||||
| 			}, | ||||
| 			function(data, next) { | ||||
| 				postData = data; | ||||
| 				next(); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				Topics.markAsUnreadForAll(tid, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| @@ -218,9 +215,6 @@ module.exports = function(Topics) { | ||||
| 			function(topicData, next) { | ||||
| 				topicData.title = validator.escape(topicData.title); | ||||
| 				postData.topic = topicData; | ||||
| 				next(); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				posts.getPidIndex(postData.pid, next); | ||||
| 			}, | ||||
| 			function(index, next) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user