mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: logic for flag note deletion, #8499
This commit is contained in:
@@ -43,6 +43,9 @@
|
|||||||
"notes": "Flag Notes",
|
"notes": "Flag Notes",
|
||||||
"add-note": "Add Note",
|
"add-note": "Add Note",
|
||||||
"no-notes": "No shared notes.",
|
"no-notes": "No shared notes.",
|
||||||
|
"delete-note-confirm": "Are you sure you want to delete this flag note?",
|
||||||
|
"note-added": "Note Added",
|
||||||
|
"note-deleted": "Note Deleted",
|
||||||
|
|
||||||
"history": "Account & Flag History",
|
"history": "Account & Flag History",
|
||||||
"no-history": "No flag history.",
|
"no-history": "No flag history.",
|
||||||
@@ -53,7 +56,6 @@
|
|||||||
"state-resolved": "Resolved",
|
"state-resolved": "Resolved",
|
||||||
"state-rejected": "Rejected",
|
"state-rejected": "Rejected",
|
||||||
"no-assignee": "Not Assigned",
|
"no-assignee": "Not Assigned",
|
||||||
"note-added": "Note Added",
|
|
||||||
|
|
||||||
"modal-title": "Report Inappropriate Content",
|
"modal-title": "Report Inappropriate Content",
|
||||||
"modal-body": "Please specify your reason for flagging %1 %2 for review. Alternatively, use one of the quick report buttons if applicable.",
|
"modal-body": "Please specify your reason for flagging %1 %2 for review. Alternatively, use one of the quick report buttons if applicable.",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
|
|||||||
$('#state').val(ajaxify.data.state).removeAttr('disabled');
|
$('#state').val(ajaxify.data.state).removeAttr('disabled');
|
||||||
$('#assignee').val(ajaxify.data.assignee).removeAttr('disabled');
|
$('#assignee').val(ajaxify.data.assignee).removeAttr('disabled');
|
||||||
|
|
||||||
$('[data-action]').on('click', function () {
|
$('#content > div').on('click', '[data-action]', function () {
|
||||||
var action = this.getAttribute('data-action');
|
var action = this.getAttribute('data-action');
|
||||||
var uid = $(this).parents('[data-uid]').attr('data-uid');
|
var uid = $(this).parents('[data-uid]').attr('data-uid');
|
||||||
|
|
||||||
@@ -75,6 +75,26 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
|
|||||||
case 'restore-post':
|
case 'restore-post':
|
||||||
postAction('restore', ajaxify.data.target.pid, ajaxify.data.target.tid);
|
postAction('restore', ajaxify.data.target.pid, ajaxify.data.target.tid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'delete-note':
|
||||||
|
var datetime = this.closest('[data-datetime]').getAttribute('data-datetime');
|
||||||
|
bootbox.confirm('[[flags:delete-note-confirm]]', function (ok) {
|
||||||
|
if (ok) {
|
||||||
|
socket.emit('flags.deleteNote', {
|
||||||
|
flagId: ajaxify.data.flagId,
|
||||||
|
datetime: datetime,
|
||||||
|
}, function (err, payload) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.alertSuccess('[[flags:note-deleted]]');
|
||||||
|
Detail.reloadNotes(payload.notes);
|
||||||
|
Detail.reloadHistory(payload.history);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
24
src/flags.js
24
src/flags.js
@@ -228,6 +228,21 @@ Flags.validate = async function (payload) {
|
|||||||
|
|
||||||
Flags.getNotes = async function (flagId) {
|
Flags.getNotes = async function (flagId) {
|
||||||
let notes = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':notes', 0, -1);
|
let notes = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':notes', 0, -1);
|
||||||
|
notes = await modifyNotes(notes);
|
||||||
|
return notes;
|
||||||
|
};
|
||||||
|
|
||||||
|
Flags.getNote = async function (flagId, datetime) {
|
||||||
|
let notes = await db.getSortedSetRangeByScoreWithScores('flag:' + flagId + ':notes', 0, 1, datetime, datetime);
|
||||||
|
if (!notes.length) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
notes = await modifyNotes(notes);
|
||||||
|
return notes[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
async function modifyNotes(notes) {
|
||||||
const uids = [];
|
const uids = [];
|
||||||
notes = notes.map(function (note) {
|
notes = notes.map(function (note) {
|
||||||
const noteObj = JSON.parse(note.value);
|
const noteObj = JSON.parse(note.value);
|
||||||
@@ -245,6 +260,15 @@ Flags.getNotes = async function (flagId) {
|
|||||||
note.content = validator.escape(note.content);
|
note.content = validator.escape(note.content);
|
||||||
return note;
|
return note;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags.deleteNote = async function (flagId, datetime) {
|
||||||
|
const note = await db.getSortedSetRangeByScore('flag:' + flagId + ':notes', 0, 1, datetime, datetime);
|
||||||
|
if (!note.length) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.sortedSetRemove('flag:' + flagId + ':notes', note[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Flags.create = async function (type, id, uid, reason, timestamp) {
|
Flags.create = async function (type, id, uid, reason, timestamp) {
|
||||||
|
|||||||
@@ -62,4 +62,23 @@ SocketFlags.appendNote = async function (socket, data) {
|
|||||||
return { notes: notes, history: history };
|
return { notes: notes, history: history };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketFlags.deleteNote = async function (socket, data) {
|
||||||
|
if (!data || !(data.flagId && data.datetime)) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
const note = await flags.getNote(data.flagId, data.datetime);
|
||||||
|
if (note.uid !== socket.uid) {
|
||||||
|
throw new Error('[[error:no-privileges]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
await flags.deleteNote(data.flagId, data.datetime);
|
||||||
|
|
||||||
|
const [notes, history] = await Promise.all([
|
||||||
|
flags.getNotes(data.flagId),
|
||||||
|
flags.getHistory(data.flagId),
|
||||||
|
]);
|
||||||
|
return { notes: notes, history: history };
|
||||||
|
};
|
||||||
|
|
||||||
require('../promisify')(SocketFlags);
|
require('../promisify')(SocketFlags);
|
||||||
|
|||||||
Reference in New Issue
Block a user