mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
feat: show editor in post diffs if available
This commit is contained in:
@@ -16,10 +16,11 @@ define('forum/topic/diffs', ['forum/topic/images', 'benchpress', 'translator'],
|
||||
}
|
||||
|
||||
Benchpress.parse('partials/modals/post_history', {
|
||||
diffs: data.timestamps.map(function (timestamp) {
|
||||
timestamp = parseInt(timestamp, 10);
|
||||
diffs: data.revisions.map(function (revision) {
|
||||
var timestamp = parseInt(revision.timestamp, 10);
|
||||
|
||||
return {
|
||||
username: revision.username,
|
||||
timestamp: timestamp,
|
||||
pretty: new Date(timestamp).toLocaleString(config.userLang.replace('_', '-'), localeStringOpts),
|
||||
};
|
||||
|
||||
@@ -23,6 +23,10 @@ module.exports = function (Posts) {
|
||||
|
||||
Diffs.get = async function (pid, since) {
|
||||
const timestamps = await Diffs.list(pid);
|
||||
if (!since) {
|
||||
since = 0;
|
||||
}
|
||||
|
||||
// Pass those made after `since`, and create keys
|
||||
const keys = timestamps.filter(t => (parseInt(t, 10) || 0) > since)
|
||||
.map(t => 'diff:' + pid + '.' + t);
|
||||
@@ -49,11 +53,6 @@ module.exports = function (Posts) {
|
||||
|
||||
Diffs.load = async function (pid, since, uid) {
|
||||
const post = await postDiffLoad(pid, since, uid);
|
||||
|
||||
// Clear editor data (as it is outdated for this content)
|
||||
delete post.edited;
|
||||
post.editor = null;
|
||||
|
||||
post.content = String(post.content || '');
|
||||
|
||||
const result = await plugins.fireHook('filter:parse.post', { postData: post });
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const posts = require('../../posts');
|
||||
const user = require('../../user');
|
||||
const privileges = require('../../privileges');
|
||||
const websockets = require('..');
|
||||
|
||||
@@ -8,12 +9,24 @@ module.exports = function (SocketPosts) {
|
||||
SocketPosts.getDiffs = async function (socket, data) {
|
||||
await privilegeCheck(data.pid, socket.uid);
|
||||
const timestamps = await posts.diffs.list(data.pid);
|
||||
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
|
||||
|
||||
const diffs = await posts.diffs.get(data.pid);
|
||||
const uids = diffs.map(diff => diff.uid || null);
|
||||
uids.push(post.uid);
|
||||
let usernames = await user.getUsersFields(uids, ['username']);
|
||||
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
|
||||
|
||||
const cid = await posts.getCidByPid(data.pid);
|
||||
const canEdit = await privileges.categories.can('edit', cid, socket.uid);
|
||||
const postTime = await posts.getPostField(data.pid, 'timestamp');
|
||||
timestamps.push(postTime);
|
||||
timestamps.push(post.timestamp);
|
||||
|
||||
return {
|
||||
timestamps: timestamps,
|
||||
revisions: timestamps.map((timestamp, idx) => ({
|
||||
timestamp: timestamp,
|
||||
username: usernames[idx],
|
||||
})),
|
||||
editable: canEdit,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -593,10 +593,16 @@ describe('Post\'s', function () {
|
||||
it('should allow registered-users group to view diffs', function (done) {
|
||||
socketPosts.getDiffs({ uid: 1 }, { pid: 1 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
|
||||
assert.strictEqual('boolean', typeof data.editable);
|
||||
assert.strictEqual(false, data.editable);
|
||||
|
||||
assert.equal(true, Array.isArray(data.timestamps));
|
||||
assert.strictEqual(1, data.timestamps.length);
|
||||
|
||||
assert.equal(true, Array.isArray(data.revisions));
|
||||
assert.strictEqual(data.timestamps.length, data.revisions.length);
|
||||
['timestamp', 'username'].every(prop => Object.keys(data.revisions[0]).includes(prop));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user