mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
#3664 fix edit post
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
validator = require('validator'),
|
validator = require('validator'),
|
||||||
|
_ = require('underscore'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
@@ -20,25 +21,26 @@ module.exports = function(Posts) {
|
|||||||
Posts.edit = function(data, callback) {
|
Posts.edit = function(data, callback) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var postData;
|
var postData;
|
||||||
|
var results;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
privileges.posts.canEdit(data.pid, data.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(data.pid, next);
|
Posts.getPostData(data.pid, next);
|
||||||
},
|
},
|
||||||
function(_postData, next) {
|
function (_postData, next) {
|
||||||
postData = _postData;
|
postData = _postData;
|
||||||
postData.content = data.content;
|
postData.content = data.content;
|
||||||
postData.edited = now;
|
postData.edited = now;
|
||||||
postData.editor = data.uid;
|
postData.editor = data.uid;
|
||||||
plugins.fireHook('filter:post.edit', {post: postData, uid: data.uid}, next);
|
plugins.fireHook('filter:post.edit', {post: postData, uid: data.uid}, next);
|
||||||
},
|
},
|
||||||
function(result, next) {
|
function (result, next) {
|
||||||
postData = result.post;
|
postData = result.post;
|
||||||
var updateData = {
|
var updateData = {
|
||||||
edited: postData.edited,
|
edited: postData.edited,
|
||||||
@@ -49,34 +51,34 @@ module.exports = function(Posts) {
|
|||||||
updateData.handle = data.handle;
|
updateData.handle = data.handle;
|
||||||
}
|
}
|
||||||
Posts.setPostFields(data.pid, updateData, next);
|
Posts.setPostFields(data.pid, updateData, next);
|
||||||
}
|
},
|
||||||
], function(err, result) {
|
function (next) {
|
||||||
if (err) {
|
async.parallel({
|
||||||
return callback(err);
|
editor: function(next) {
|
||||||
}
|
user.getUserFields(data.uid, ['username', 'userslug'], next);
|
||||||
|
},
|
||||||
|
topic: function(next) {
|
||||||
|
editMainPost(data, postData, next);
|
||||||
|
}
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (_results, next) {
|
||||||
|
results = _results;
|
||||||
|
|
||||||
async.parallel({
|
|
||||||
editor: function(next) {
|
|
||||||
user.getUserFields(data.uid, ['username', 'userslug'], next);
|
|
||||||
},
|
|
||||||
topic: function(next) {
|
|
||||||
editMainPost(data, postData, next);
|
|
||||||
},
|
|
||||||
post: function(next) {
|
|
||||||
cache.del(postData.pid);
|
|
||||||
pubsub.publish('post:edit', postData.pid);
|
|
||||||
Posts.parsePost(postData, next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
postData.cid = results.topic.cid;
|
postData.cid = results.topic.cid;
|
||||||
plugins.fireHook('action:post.edit', postData);
|
|
||||||
|
|
||||||
callback(null, results);
|
plugins.fireHook('action:post.edit', _.clone(postData));
|
||||||
});
|
|
||||||
});
|
cache.del(postData.pid);
|
||||||
|
pubsub.publish('post:edit', postData.pid);
|
||||||
|
|
||||||
|
Posts.parsePost(postData, next);
|
||||||
|
},
|
||||||
|
function (postData, next) {
|
||||||
|
results.post = postData;
|
||||||
|
next(null, results);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function editMainPost(data, postData, callback) {
|
function editMainPost(data, postData, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user