fix: #12732 editing of remote post content

title can now be edited, post content is not-editable.
This commit is contained in:
Julian Lam
2024-08-13 15:12:57 -04:00
parent 3474712228
commit 25bf97ae28
2 changed files with 16 additions and 7 deletions

View File

@@ -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']}]]`);
} }

View File

@@ -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,