mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-29 18:16:17 +01:00 
			
		
		
		
	showing guest handles in frontend UI #2569
This commit is contained in:
		| @@ -378,6 +378,7 @@ define('composer', [ | ||||
| 	function post(post_uuid) { | ||||
| 		var postData = composer.posts[post_uuid], | ||||
| 			postContainer = $('#cmp-uuid-' + post_uuid), | ||||
| 			handleEl = postContainer.find('.handle'), | ||||
| 			titleEl = postContainer.find('.title'), | ||||
| 			bodyEl = postContainer.find('textarea'), | ||||
| 			thumbEl = postContainer.find('input#topic-thumb-url'); | ||||
| @@ -406,6 +407,7 @@ define('composer', [ | ||||
|  | ||||
| 		if (parseInt(postData.cid, 10) > 0) { | ||||
| 			composerData = { | ||||
| 				handle: handleEl ? handleEl.val() : undefined, | ||||
| 				title: titleEl.val(), | ||||
| 				content: bodyEl.val(), | ||||
| 				topic_thumb: thumbEl.val() || '', | ||||
| @@ -424,6 +426,7 @@ define('composer', [ | ||||
| 		} else if (parseInt(postData.tid, 10) > 0) { | ||||
| 			composerData = { | ||||
| 				tid: postData.tid, | ||||
| 				handle: handleEl ? handleEl.val() : undefined, | ||||
| 				content: bodyEl.val(), | ||||
| 				toPid: postData.toPid | ||||
| 			}; | ||||
| @@ -433,6 +436,7 @@ define('composer', [ | ||||
| 		} else if (parseInt(postData.pid, 10) > 0) { | ||||
| 			composerData = { | ||||
| 				pid: postData.pid, | ||||
| 				handle: handleEl ? handleEl.val() : undefined, | ||||
| 				content: bodyEl.val(), | ||||
| 				title: titleEl.val(), | ||||
| 				topic_thumb: thumbEl.val() || '', | ||||
|   | ||||
| @@ -18,21 +18,22 @@ var winston = require('winston'), | ||||
|  | ||||
| (function(PostTools) { | ||||
|  | ||||
| 	PostTools.edit = function(uid, pid, title, content, options, callback) { | ||||
| 		options = options || {}; | ||||
| 	PostTools.edit = function(data, callback) { | ||||
| 		var options = data.options || {}, | ||||
| 			title = data.title.trim(); | ||||
|  | ||||
| 		async.waterfall([ | ||||
| 			function (next) { | ||||
| 				privileges.posts.canEdit(pid, uid, next); | ||||
| 				privileges.posts.canEdit(data.pid, data.uid, next); | ||||
| 			}, | ||||
| 			function(canEdit, next) { | ||||
| 				if (!canEdit) { | ||||
| 					return next(new Error('[[error:no-privileges]]')); | ||||
| 				} | ||||
| 				posts.getPostData(pid, next); | ||||
| 				posts.getPostData(data.pid, next); | ||||
| 			}, | ||||
| 			function(postData, next) { | ||||
| 				postData.content = content; | ||||
| 				postData.content = data.content; | ||||
| 				plugins.fireHook('filter:post.save', postData, next); | ||||
| 			} | ||||
| 		], function(err, postData) { | ||||
| @@ -42,15 +43,15 @@ var winston = require('winston'), | ||||
|  | ||||
| 			async.parallel({ | ||||
| 				post: function(next) { | ||||
| 					posts.setPostFields(pid, { | ||||
| 					posts.setPostFields(data.pid, { | ||||
| 						edited: Date.now(), | ||||
| 						editor: uid, | ||||
| 						editor: data.uid, | ||||
| 						content: postData.content | ||||
| 					}, next); | ||||
| 				}, | ||||
| 				topic: function(next) { | ||||
| 					var tid = postData.tid; | ||||
| 					posts.isMain(pid, function(err, isMainPost) { | ||||
| 					posts.isMain(data.pid, function(err, isMainPost) { | ||||
| 						if (err) { | ||||
| 							return next(err); | ||||
| 						} | ||||
| @@ -64,11 +65,9 @@ var winston = require('winston'), | ||||
| 							}); | ||||
| 						} | ||||
|  | ||||
| 						title = title.trim(); | ||||
|  | ||||
| 						var topicData = { | ||||
| 							tid: tid, | ||||
| 							mainPid: pid, | ||||
| 							mainPid: data.pid, | ||||
| 							title: title, | ||||
| 							slug: tid + '/' + utils.slugify(title) | ||||
| 						}; | ||||
| @@ -96,7 +95,7 @@ var winston = require('winston'), | ||||
| 					}); | ||||
| 				}, | ||||
| 				postData: function(next) { | ||||
| 					PostTools.parsePost(postData, uid, next); | ||||
| 					PostTools.parsePost(postData, data.uid, next); | ||||
| 				} | ||||
| 			}, function(err, results) { | ||||
| 				if (err) { | ||||
|   | ||||
| @@ -14,10 +14,10 @@ module.exports = function(Posts) { | ||||
| 	Posts.create = function(data, callback) { | ||||
| 		var uid = data.uid, | ||||
| 			tid = data.tid, | ||||
| 			handle = data.uid ? null : data.handle,	// Only guests have handles! | ||||
| 			content = data.content, | ||||
| 			timestamp = data.timestamp || Date.now(); | ||||
|  | ||||
|  | ||||
| 		if (!uid && parseInt(uid, 10) !== 0) { | ||||
| 			return callback(new Error('[[error:invalid-uid]]')); | ||||
| 		} | ||||
| @@ -51,6 +51,10 @@ module.exports = function(Posts) { | ||||
| 					postData.ip = data.ip; | ||||
| 				} | ||||
|  | ||||
| 				if (handle) { | ||||
| 					postData.handle = handle; | ||||
| 				} | ||||
|  | ||||
| 				plugins.fireHook('filter:post.save', postData, next); | ||||
| 			}, | ||||
| 			function(postData, next) { | ||||
|   | ||||
| @@ -257,7 +257,17 @@ SocketPosts.edit = function(socket, data, callback) { | ||||
| 		return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]')); | ||||
| 	} | ||||
|  | ||||
| 	postTools.edit(socket.uid, data.pid, data.title, data.content, {topic_thumb: data.topic_thumb, tags: data.tags}, function(err, results) { | ||||
| 	// uid, pid, title, content, options | ||||
| 	postTools.edit({ | ||||
| 		uid: socket.uid, | ||||
| 		pid: data.pid, | ||||
| 		title: data.title, | ||||
| 		content: data.content, | ||||
| 		options: { | ||||
| 			topic_thumb: data.topic_thumb, | ||||
| 			tags: data.tags | ||||
| 		} | ||||
| 	}, function(err, results) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
|   | ||||
| @@ -27,6 +27,7 @@ SocketTopics.post = function(socket, data, callback) { | ||||
|  | ||||
| 	topics.post({ | ||||
| 		uid: socket.uid, | ||||
| 		handle: data.handle, | ||||
| 		title: data.title, | ||||
| 		content: data.content, | ||||
| 		cid: data.category_id, | ||||
|   | ||||
| @@ -93,6 +93,7 @@ module.exports = function(Topics) { | ||||
|  | ||||
| 	Topics.post = function(data, callback) { | ||||
| 		var uid = data.uid, | ||||
| 			handle = data.handle, | ||||
| 			title = data.title, | ||||
| 			content = data.content, | ||||
| 			cid = data.cid; | ||||
| @@ -134,7 +135,7 @@ module.exports = function(Topics) { | ||||
| 				Topics.create({uid: uid, title: title, cid: cid, thumb: data.thumb, tags: data.tags}, next); | ||||
| 			}, | ||||
| 			function(tid, next) { | ||||
| 				Topics.reply({uid:uid, tid:tid, content:content, req: data.req}, next); | ||||
| 				Topics.reply({uid:uid, tid:tid, handle: handle, content:content, req: data.req}, next); | ||||
| 			}, | ||||
| 			function(postData, next) { | ||||
| 				async.parallel({ | ||||
| @@ -184,6 +185,7 @@ module.exports = function(Topics) { | ||||
| 		var tid = data.tid, | ||||
| 			uid = data.uid, | ||||
| 			toPid = data.toPid, | ||||
| 			handle = data.handle, | ||||
| 			content = data.content, | ||||
| 			postData; | ||||
|  | ||||
| @@ -226,7 +228,7 @@ module.exports = function(Topics) { | ||||
| 				checkContentLength(content, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				posts.create({uid: uid, tid: tid, content: content, toPid: toPid, ip: data.req ? data.req.ip : null}, next); | ||||
| 				posts.create({uid: uid, tid: tid, handle: handle, content: content, toPid: toPid, ip: data.req ? data.req.ip : null}, next); | ||||
| 			}, | ||||
| 			function(data, next) { | ||||
| 				postData = data; | ||||
|   | ||||
| @@ -4,6 +4,7 @@ | ||||
|  | ||||
| var async = require('async'), | ||||
| 	winston = require('winston'), | ||||
| 	_ = require('underscore'), | ||||
|  | ||||
| 	db = require('../database'), | ||||
| 	user = require('../user'), | ||||
| @@ -110,25 +111,32 @@ module.exports = function(Topics) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			for (var i = 0; i < postData.length; ++i) { | ||||
| 				if (postData[i]) { | ||||
| 					postData[i].index = results.indices[i]; | ||||
| 					postData[i].deleted = parseInt(postData[i].deleted, 10) === 1; | ||||
| 					postData[i].user = results.userData[postData[i].uid]; | ||||
| 					postData[i].editor = postData[i].editor ? results.editors[postData[i].editor] : null; | ||||
| 					postData[i].favourited = results.favourites[i]; | ||||
| 					postData[i].upvoted = results.voteData.upvotes[i]; | ||||
| 					postData[i].downvoted = results.voteData.downvotes[i]; | ||||
| 					postData[i].votes = postData[i].votes || 0; | ||||
| 					postData[i].display_moderator_tools = results.privileges[i].editable; | ||||
| 					postData[i].display_move_tools = results.privileges[i].move && postData[i].index !== 0; | ||||
| 					postData[i].selfPost = parseInt(uid, 10) === parseInt(postData[i].uid, 10); | ||||
| 			postData = postData.map(function(postObj, i) { | ||||
| 				if (postObj) { | ||||
| 					postObj.index = results.indices[i]; | ||||
| 					postObj.deleted = parseInt(postObj.deleted, 10) === 1; | ||||
| 					postObj.user = _.clone(results.userData[postObj.uid]); | ||||
| 					postObj.editor = postObj.editor ? results.editors[postObj.editor] : null; | ||||
| 					postObj.favourited = results.favourites[i]; | ||||
| 					postObj.upvoted = results.voteData.upvotes[i]; | ||||
| 					postObj.downvoted = results.voteData.downvotes[i]; | ||||
| 					postObj.votes = postObj.votes || 0; | ||||
| 					postObj.display_moderator_tools = results.privileges[i].editable; | ||||
| 					postObj.display_move_tools = results.privileges[i].move && postObj.index !== 0; | ||||
| 					postObj.selfPost = parseInt(uid, 10) === parseInt(postObj.uid, 10); | ||||
|  | ||||
| 					if(postData[i].deleted && !results.privileges[i].view_deleted) { | ||||
| 						postData[i].content = '[[topic:post_is_deleted]]'; | ||||
| 					if(postObj.deleted && !results.privileges[i].view_deleted) { | ||||
| 						postObj.content = '[[topic:post_is_deleted]]'; | ||||
| 					} | ||||
|  | ||||
| 					// Username override for guests, if enabled | ||||
| 					if (parseInt(postObj.uid, 10) === 0 && postObj.handle) { | ||||
| 						postObj.user.username = postObj.handle; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 				return postObj; | ||||
| 			}).filter(Boolean); | ||||
|  | ||||
| 			callback(null, postData); | ||||
| 		}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user