Skip to content

Node.js based forum software built for the modern web

closes #6019

Barış Soner Uşaklı25cd21fba829
diff --git a/public/language/en-GB/admin/manage/post-queue.json b/public/language/en-GB/admin/manage/post-queue.json
index f748fb0ee2..4de24c991b 100644
--- a/public/language/en-GB/admin/manage/post-queue.json
+++ b/public/language/en-GB/admin/manage/post-queue.json
@@ -6,5 +6,6 @@
"title": "Title",
"content": "Content",
"posted": "Posted",
- "reply-to": "Reply to \"%1\""
+ "reply-to": "Reply to \"%1\"",
+ "content-editable": "You can click on individual content to edit before posting."
}
\ No newline at end of file
diff --git a/public/src/admin/manage/post-queue.js b/public/src/admin/manage/post-queue.js
index 2bb9931dec..9413a839e2 100644
--- a/public/src/admin/manage/post-queue.js
+++ b/public/src/admin/manage/post-queue.js
@@ -5,6 +5,8 @@ define('admin/manage/post-queue', function () {
var PostQueue = {};
PostQueue.init = function () {
+ $('[data-toggle="tooltip"]').tooltip();
+
$('.posts-list').on('click', '[data-action]', function () {
var parent = $(this).parents('[data-id]');
var action = $(this).attr('data-action');
@@ -19,6 +21,18 @@ define('admin/manage/post-queue', function () {
});
return false;
});
+
+ $('.posts-list').on('input', '[data-id]', function () {
+ var el = $(this);
+ socket.emit('posts.editQueuedContent', {
+ id: el.attr('data-id'),
+ content: el.find('.post-content').html(),
+ }, function (err) {
+ if (err) {
+ return app.alertError(err);
+ }
+ });
+ });
};
return PostQueue;
diff --git a/src/posts/queue.js b/src/posts/queue.js
index 4cdedeca03..5419a28d98 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -70,6 +70,8 @@ module.exports = function (Posts) {
},
function (next) {
next(null, {
+ id: id,
+ type: type,
queued: true,
message: '[[success:post-queued]]',
});
@@ -178,4 +180,27 @@ module.exports = function (Posts) {
},
], callback);
}
+
+ Posts.editQueuedContent = function (uid, id, content, callback) {
+ async.waterfall([
+ function (next) {
+ user.isAdminOrGlobalMod(uid, next);
+ },
+ function (isAdminOrGlobalMod, next) {
+ if (!isAdminOrGlobalMod) {
+ return callback(new Error('[[error:no-privileges]]'));
+ }
+ db.getObject('post:queue:' + id, next);
+ },
+ function (data, next) {
+ try {
+ data.data = JSON.parse(data.data);
+ } catch (err) {
+ return next(err);
+ }
+ data.data.content = content;
+ db.setObjectField('post:queue:' + id, 'data', JSON.stringify(data.data), next);
+ },
+ ], callback);
+ };
};
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index a5462ef5bb..3cad4b6db0 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -175,6 +175,12 @@ SocketPosts.accept = function (socket, data, callback) {
SocketPosts.reject = function (socket, data, callback) {
acceptOrReject(posts.removeFromQueue, socket, data, callback);
};
+SocketPosts.editQueuedContent = function (socket, data, callback) {
+ if (!data || !data.id || !data.content) {
+ return callback(new Error('[[error:invalid-data]]'));
+ }
+ posts.editQueuedContent(socket.uid, data.id, data.content, callback);
+};
function acceptOrReject(method, socket, data, callback) {
async.waterfall([
diff --git a/src/views/admin/manage/post-queue.tpl b/src/views/admin/manage/post-queue.tpl
index 001479aa58..5e46db2a36 100644
--- a/src/views/admin/manage/post-queue.tpl
+++ b/src/views/admin/manage/post-queue.tpl
@@ -18,7 +18,7 @@
<th>[[admin/manage/post-queue:user]]</th>
<th>[[admin/manage/post-queue:category]]</th>
<th>[[admin/manage/post-queue:title]]</th>
- <th>[[admin/manage/post-queue:content]]</th>
+ <th>[[admin/manage/post-queue:content]] <i class="fa fa-info-circle" data-toggle="tooltip" title="[[admin/manage/post-queue:content-editable]]"></i></th>
<th>[[admin/manage/post-queue:posted]]</th>
<th></th>
</tr>
@@ -42,9 +42,7 @@
<!-- ENDIF posts.data.tid -->
{posts.data.title}
</td>
- <td class="col-md-5">
- {posts.data.content}
- </td>
+ <td class="col-md-5 post-content" contenteditable="true">{posts.data.content}</td>
<td class="col-md-1">
<span class="timeago" title={posts.data.timestampISO}></span>
</td>
diff --git a/test/posts.js b/test/posts.js
index 7eb96d1cde..a517270e26 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -761,6 +761,8 @@ describe('Post\'s', function () {
describe('post queue', function () {
var uid;
+ var queueId;
+ var jar;
before(function (done) {
meta.config.postQueue = 1;
user.create({ username: 'newuser' }, function (err, _uid) {
@@ -780,6 +782,7 @@ describe('Post\'s', function () {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
+
done();
});
});
@@ -789,12 +792,14 @@ describe('Post\'s', function () {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
+ queueId = result.id;
done();
});
});
it('should load queued posts', function (done) {
- helpers.loginUser('globalmod', 'globalmodpwd', function (err, jar) {
+ helpers.loginUser('globalmod', 'globalmodpwd', function (err, _jar) {
+ jar = _jar;
assert.ifError(err);
request(nconf.get('url') + '/api/post-queue', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err);
@@ -807,6 +812,25 @@ describe('Post\'s', function () {
});
});
+ it('should error if data is invalid', function (done) {
+ socketPosts.editQueuedContent({ uid: globalModUid }, null, function (err) {
+ assert.equal(err.message, '[[error:invalid-data]]');
+ done();
+ });
+ });
+
+ it('should edit post in queue', function (done) {
+ socketPosts.editQueuedContent({ uid: globalModUid }, { id: queueId, content: 'newContent' }, function (err) {
+ assert.ifError(err);
+ request(nconf.get('url') + '/api/post-queue', { jar: jar, json: true }, function (err, res, body) {
+ assert.ifError(err);
+ assert.equal(body.posts[1].type, 'reply');
+ assert.equal(body.posts[1].data.content, 'newContent');
+ done();
+ });
+ });
+ });
+
it('should accept queued posts submit', function (done) {
var ids;
async.waterfall([