mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #12732 editing of remote post content
title can now be edited, post content is not-editable.
This commit is contained in:
@@ -90,17 +90,25 @@ postsAPI.edit = async function (caller, data) {
|
|||||||
if (!caller.uid) {
|
if (!caller.uid) {
|
||||||
throw new Error('[[error:not-logged-in]]');
|
throw new Error('[[error:not-logged-in]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discard content for non-local posts
|
||||||
|
if (!utils.isNumber(data.pid)) {
|
||||||
|
data.content = null;
|
||||||
|
} else {
|
||||||
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
||||||
const contentLen = utils.stripHTMLTags(data.content).trim().length;
|
const contentLen = utils.stripHTMLTags(data.content).trim().length;
|
||||||
|
|
||||||
|
if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
|
||||||
|
throw new Error(`[[error:content-too-short, ${meta.config.minimumPostLength}]]`);
|
||||||
|
} else if (contentLen > meta.config.maximumPostLength) {
|
||||||
|
throw new Error(`[[error:content-too-long, ${meta.config.maximumPostLength}]]`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data.title && data.title.length < meta.config.minimumTitleLength) {
|
if (data.title && data.title.length < meta.config.minimumTitleLength) {
|
||||||
throw new Error(`[[error:title-too-short, ${meta.config.minimumTitleLength}]]`);
|
throw new Error(`[[error:title-too-short, ${meta.config.minimumTitleLength}]]`);
|
||||||
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
|
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
|
||||||
throw new Error(`[[error:title-too-long, ${meta.config.maximumTitleLength}]]`);
|
throw new Error(`[[error:title-too-long, ${meta.config.maximumTitleLength}]]`);
|
||||||
} else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
|
|
||||||
throw new Error(`[[error:content-too-short, ${meta.config.minimumPostLength}]]`);
|
|
||||||
} else if (contentLen > meta.config.maximumPostLength) {
|
|
||||||
throw new Error(`[[error:content-too-long, ${meta.config.maximumPostLength}]]`);
|
|
||||||
} else if (!await posts.canUserPostContentWithLinks(caller.uid, data.content)) {
|
} else if (!await posts.canUserPostContentWithLinks(caller.uid, data.content)) {
|
||||||
throw new Error(`[[error:not-enough-reputation-to-post-links, ${meta.config['min:rep:post-links']}]]`);
|
throw new Error(`[[error:not-enough-reputation-to-post-links, ${meta.config['min:rep:post-links']}]]`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ module.exports = function (Posts) {
|
|||||||
|
|
||||||
await scheduledTopicCheck(data, topicData);
|
await scheduledTopicCheck(data, topicData);
|
||||||
|
|
||||||
|
data.content = data.content === null ? postData.content : data.content;
|
||||||
const oldContent = postData.content; // for diffing purposes
|
const oldContent = postData.content; // for diffing purposes
|
||||||
const editPostData = getEditPostData(data, topicData, postData);
|
const editPostData = getEditPostData(data, topicData, postData);
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ module.exports = function (Posts) {
|
|||||||
const { tid } = postData;
|
const { tid } = postData;
|
||||||
const title = data.title ? data.title.trim() : '';
|
const title = data.title ? data.title.trim() : '';
|
||||||
|
|
||||||
const isMain = parseInt(data.pid, 10) === parseInt(topicData.mainPid, 10);
|
const isMain = String(data.pid) === String(topicData.mainPid);
|
||||||
if (!isMain) {
|
if (!isMain) {
|
||||||
return {
|
return {
|
||||||
tid: tid,
|
tid: tid,
|
||||||
|
|||||||
Reference in New Issue
Block a user