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