mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 00:45:47 +01:00
use water in post edit
This commit is contained in:
@@ -27,7 +27,25 @@ var winston = require('winston'),
|
|||||||
PostTools.edit = function(uid, pid, title, content, options, callback) {
|
PostTools.edit = function(uid, pid, title, content, options, callback) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
function success(postData) {
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
privileges.posts.canEdit(pid, uid, next);
|
||||||
|
},
|
||||||
|
function(canEdit, next) {
|
||||||
|
if (!canEdit) {
|
||||||
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
|
}
|
||||||
|
posts.getPostData(pid, next);
|
||||||
|
},
|
||||||
|
function(postData, next) {
|
||||||
|
postData.content = content;
|
||||||
|
plugins.fireHook('filter:post.save', postData, next);
|
||||||
|
}
|
||||||
|
], function(err, postData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
posts.setPostFields(pid, {
|
posts.setPostFields(pid, {
|
||||||
edited: Date.now(),
|
edited: Date.now(),
|
||||||
editor: uid,
|
editor: uid,
|
||||||
@@ -46,12 +64,15 @@ var winston = require('winston'),
|
|||||||
|
|
||||||
if (isMainPost) {
|
if (isMainPost) {
|
||||||
title = title.trim();
|
title = title.trim();
|
||||||
var slug = tid + '/' + utils.slugify(title);
|
|
||||||
|
|
||||||
topics.setTopicField(tid, 'title', title);
|
var topicData = {
|
||||||
topics.setTopicField(tid, 'slug', slug);
|
title: title,
|
||||||
|
slug: tid + '/' + utils.slugify(title)
|
||||||
topics.setTopicField(tid, 'thumb', options.topic_thumb);
|
};
|
||||||
|
if (options.topic_thumb) {
|
||||||
|
topicData.thumb = options.topic_thumb;
|
||||||
|
}
|
||||||
|
db.setObject('topic:' + tid, topicData);
|
||||||
|
|
||||||
topics.updateTags(tid, options.tags);
|
topics.updateTags(tid, options.tags);
|
||||||
|
|
||||||
@@ -72,27 +93,6 @@ var winston = require('winston'),
|
|||||||
PostTools.parse(postData.content, next);
|
PostTools.parse(postData.content, next);
|
||||||
}
|
}
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
|
||||||
|
|
||||||
privileges.posts.canEdit(pid, uid, function(err, canEdit) {
|
|
||||||
if (err || !canEdit) {
|
|
||||||
return callback(err || new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
posts.getPostData(pid, function(err, postData) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
postData.content = content;
|
|
||||||
plugins.fireHook('filter:post.save', postData, function(err, postData) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
success(postData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user