mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: closes #12477, allow editing moderation notes
This commit is contained in:
@@ -103,10 +103,10 @@
|
|||||||
"nodebb-plugin-ntfy": "1.7.4",
|
"nodebb-plugin-ntfy": "1.7.4",
|
||||||
"nodebb-plugin-spam-be-gone": "2.2.2",
|
"nodebb-plugin-spam-be-gone": "2.2.2",
|
||||||
"nodebb-rewards-essentials": "1.0.0",
|
"nodebb-rewards-essentials": "1.0.0",
|
||||||
"nodebb-theme-harmony": "1.2.52",
|
"nodebb-theme-harmony": "1.2.53",
|
||||||
"nodebb-theme-lavender": "7.1.8",
|
"nodebb-theme-lavender": "7.1.8",
|
||||||
"nodebb-theme-peace": "2.2.4",
|
"nodebb-theme-peace": "2.2.4",
|
||||||
"nodebb-theme-persona": "13.3.17",
|
"nodebb-theme-persona": "13.3.18",
|
||||||
"nodebb-widget-essentials": "7.0.15",
|
"nodebb-widget-essentials": "7.0.15",
|
||||||
"nodemailer": "6.9.13",
|
"nodemailer": "6.9.13",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/s
|
|||||||
|
|
||||||
function handleModerationNote() {
|
function handleModerationNote() {
|
||||||
$('[component="account/save-moderation-note"]').on('click', function () {
|
$('[component="account/save-moderation-note"]').on('click', function () {
|
||||||
const note = $('[component="account/moderation-note"]').val();
|
const noteEl = $('[component="account/moderation-note"]');
|
||||||
socket.emit('user.setModerationNote', { uid: ajaxify.data.uid, note: note }, function (err, notes) {
|
const note = noteEl.val();
|
||||||
|
socket.emit('user.setModerationNote', {
|
||||||
|
uid: ajaxify.data.uid,
|
||||||
|
note: note,
|
||||||
|
}, function (err, notes) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return alerts.error(err);
|
return alerts.error(err);
|
||||||
}
|
}
|
||||||
$('[component="account/moderation-note"]').val('');
|
noteEl.val('');
|
||||||
|
|
||||||
app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, function (html) {
|
app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, function (html) {
|
||||||
$('[component="account/moderation-note/list"]').prepend(html);
|
$('[component="account/moderation-note/list"]').prepend(html);
|
||||||
@@ -25,6 +29,54 @@ define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/s
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('[component="account/moderation-note/edit"]').on('click', function () {
|
||||||
|
const parent = $(this).parents('[data-id]');
|
||||||
|
const contentArea = parent.find('[component="account/moderation-note/content-area"]');
|
||||||
|
const editArea = parent.find('[component="account/moderation-note/edit-area"]');
|
||||||
|
contentArea.addClass('hidden');
|
||||||
|
editArea.removeClass('hidden');
|
||||||
|
editArea.find('textarea').trigger('focus').putCursorAtEnd();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('[component="account/moderation-note/save-edit"]').on('click', function () {
|
||||||
|
const parent = $(this).parents('[data-id]');
|
||||||
|
const contentArea = parent.find('[component="account/moderation-note/content-area"]');
|
||||||
|
const editArea = parent.find('[component="account/moderation-note/edit-area"]');
|
||||||
|
contentArea.removeClass('hidden');
|
||||||
|
const textarea = editArea.find('textarea');
|
||||||
|
|
||||||
|
socket.emit('user.editModerationNote', {
|
||||||
|
uid: ajaxify.data.uid,
|
||||||
|
id: parent.attr('data-id'),
|
||||||
|
note: textarea.val(),
|
||||||
|
}, function (err, notes) {
|
||||||
|
if (err) {
|
||||||
|
return alerts.error(err);
|
||||||
|
}
|
||||||
|
textarea.css({
|
||||||
|
height: textarea.prop('scrollHeight') + 'px',
|
||||||
|
});
|
||||||
|
editArea.addClass('hidden');
|
||||||
|
contentArea.find('.content').html(notes[0].note);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('[component="account/moderation-note/cancel-edit"]').on('click', function () {
|
||||||
|
const parent = $(this).parents('[data-id]');
|
||||||
|
const contentArea = parent.find('[component="account/moderation-note/content-area"]');
|
||||||
|
const editArea = parent.find('[component="account/moderation-note/edit-area"]');
|
||||||
|
contentArea.removeClass('hidden');
|
||||||
|
editArea.addClass('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('[component="account/moderation-note/edit-area"] textarea').each((i, el) => {
|
||||||
|
const $el = $(el);
|
||||||
|
$el.css({
|
||||||
|
height: $el.prop('scrollHeight') + 'px',
|
||||||
|
}).parent().addClass('hidden');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Info;
|
return Info;
|
||||||
|
|||||||
@@ -155,6 +155,26 @@ SocketUser.setModerationNote = async function (socket, data) {
|
|||||||
return await user.getModerationNotes(data.uid, 0, 0);
|
return await user.getModerationNotes(data.uid, 0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketUser.editModerationNote = async function (socket, data) {
|
||||||
|
if (!socket.uid || !data || !data.uid || !data.note || !data.id) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
const noteData = {
|
||||||
|
note: data.note,
|
||||||
|
timestamp: data.id,
|
||||||
|
};
|
||||||
|
let canEdit = await privileges.users.canEdit(socket.uid, data.uid);
|
||||||
|
if (!canEdit) {
|
||||||
|
canEdit = await user.isModeratorOfAnyCategory(socket.uid);
|
||||||
|
}
|
||||||
|
if (!canEdit) {
|
||||||
|
throw new Error('[[error:no-privileges]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
await user.setModerationNote({ uid: data.uid, noteData });
|
||||||
|
return await user.getModerationNotesByIds(data.uid, [data.id]);
|
||||||
|
};
|
||||||
|
|
||||||
SocketUser.deleteUpload = async function (socket, data) {
|
SocketUser.deleteUpload = async function (socket, data) {
|
||||||
if (!data || !data.name || !data.uid) {
|
if (!data || !data.name || !data.uid) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
|||||||
@@ -112,12 +112,17 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
User.getModerationNotes = async function (uid, start, stop) {
|
User.getModerationNotes = async function (uid, start, stop) {
|
||||||
const noteIds = await db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, start, stop);
|
const noteIds = await db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, start, stop);
|
||||||
|
return await User.getModerationNotesByIds(uid, noteIds);
|
||||||
|
};
|
||||||
|
|
||||||
|
User.getModerationNotesByIds = async (uid, noteIds) => {
|
||||||
const keys = noteIds.map(id => `uid:${uid}:moderation:note:${id}`);
|
const keys = noteIds.map(id => `uid:${uid}:moderation:note:${id}`);
|
||||||
const notes = await db.getObjects(keys);
|
const notes = await db.getObjects(keys);
|
||||||
const uids = [];
|
const uids = [];
|
||||||
|
|
||||||
notes.forEach((note) => {
|
notes.forEach((note, idx) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
|
note.id = noteIds[idx];
|
||||||
uids.push(note.uid);
|
uids.push(note.uid);
|
||||||
note.timestampISO = utils.toISOString(note.timestamp);
|
note.timestampISO = utils.toISOString(note.timestamp);
|
||||||
}
|
}
|
||||||
@@ -125,6 +130,7 @@ module.exports = function (User) {
|
|||||||
const userData = await User.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);
|
const userData = await User.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);
|
||||||
await Promise.all(notes.map(async (note, index) => {
|
await Promise.all(notes.map(async (note, index) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
|
note.rawNote = validator.escape(String(note.note));
|
||||||
note.note = await plugins.hooks.fire('filter:parse.raw', String(note.note));
|
note.note = await plugins.hooks.fire('filter:parse.raw', String(note.note));
|
||||||
note.user = userData[index];
|
note.user = userData[index];
|
||||||
}
|
}
|
||||||
@@ -136,4 +142,8 @@ module.exports = function (User) {
|
|||||||
await db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp);
|
await db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp);
|
||||||
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, noteData);
|
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, noteData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.setModerationNote = async ({ uid, noteData }) => {
|
||||||
|
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, noteData);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user