mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
closes #6020
This commit is contained in:
@@ -128,18 +128,12 @@ module.exports = function (Posts) {
|
||||
Posts.submitFromQueue = function (id, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getObject('post:queue:' + id, next);
|
||||
getParsedObject(id, next);
|
||||
},
|
||||
function (data, next) {
|
||||
if (!data) {
|
||||
return callback();
|
||||
}
|
||||
try {
|
||||
data.data = JSON.parse(data.data);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (data.type === 'topic') {
|
||||
createTopic(data.data, next);
|
||||
} else if (data.type === 'reply') {
|
||||
@@ -152,6 +146,25 @@ module.exports = function (Posts) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
function getParsedObject(id, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getObject('post:queue:' + id, next);
|
||||
},
|
||||
function (data, next) {
|
||||
if (!data) {
|
||||
return callback();
|
||||
}
|
||||
try {
|
||||
data.data = JSON.parse(data.data);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(null, data);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
function createTopic(data, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -184,23 +197,52 @@ module.exports = function (Posts) {
|
||||
Posts.editQueuedContent = function (uid, id, content, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.isAdminOrGlobalMod(uid, next);
|
||||
Posts.canEditQueue(uid, id, next);
|
||||
},
|
||||
function (isAdminOrGlobalMod, next) {
|
||||
if (!isAdminOrGlobalMod) {
|
||||
function (canEditQueue, next) {
|
||||
if (!canEditQueue) {
|
||||
return callback(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
db.getObject('post:queue:' + id, next);
|
||||
getParsedObject(id, next);
|
||||
},
|
||||
function (data, next) {
|
||||
try {
|
||||
data.data = JSON.parse(data.data);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
if (!data) {
|
||||
return callback();
|
||||
}
|
||||
data.data.content = content;
|
||||
db.setObjectField('post:queue:' + id, 'data', JSON.stringify(data.data), next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.canEditQueue = function (uid, id, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isAdminOrGlobalMod: function (next) {
|
||||
user.isAdminOrGlobalMod(uid, next);
|
||||
},
|
||||
data: function (next) {
|
||||
getParsedObject(id, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (results.isAdminOrGlobalMod) {
|
||||
return callback(null, true);
|
||||
}
|
||||
if (!results.data) {
|
||||
return callback(null, false);
|
||||
}
|
||||
if (results.data.type === 'topic') {
|
||||
next(null, results.data.data.cid);
|
||||
} else if (results.data.type === 'reply') {
|
||||
topics.getTopicField(results.data.data.tid, 'cid', next);
|
||||
}
|
||||
},
|
||||
function (cid, next) {
|
||||
user.isModerator(uid, cid, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user