Skip to content

Node.js based forum software built for the modern web

flag assignees, state, notes WIP, #5232

Julian Lamc5c2d27180a5
diff --git a/public/language/en-GB/flags.json b/public/language/en-GB/flags.json
index bf22e68df6..d266e2c4db 100644
--- a/public/language/en-GB/flags.json
+++ b/public/language/en-GB/flags.json
@@ -4,10 +4,15 @@
"reporter": "Reporter",
"reported-at": "Reported At",
"no-flags": "Hooray! No flags found.",
+ "assignee": "Assignee",
+ "update": "Update",
+ "notes": "Flag Notes",
+ "add-note": "Add Note",
"state": "State",
"state-open": "New/Open",
"state-wip": "Work in Progress",
"state-resolved": "Resolved",
- "state-rejected": "Rejected"
+ "state-rejected": "Rejected",
+ "no-assignee": "Not Assigned"
}
\ No newline at end of file
diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json
index 885afe5d62..ce7f35f816 100644
--- a/public/language/en-GB/topic.json
+++ b/public/language/en-GB/topic.json
@@ -37,12 +37,8 @@
"flag_title": "Flag this post for moderation",
"flag_success": "This post has been flagged for moderation.",
- "flag_manage_title": "Flagged post in %1",
"flag_manage_history": "Action History",
"flag_manage_no_history": "No event history to report",
- "flag_manage_assignee": "Assignee",
- "flag_manage_notes": "Shared Notes",
- "flag_manage_update": "Update Flag Status",
"flag_manage_history_assignee": "Assigned to %1",
"flag_manage_history_state": "Updated state to %1",
"flag_manage_history_notes": "Updated flag notes",
diff --git a/src/controllers/mods.js b/src/controllers/mods.js
index 7ebb70d888..012ffde3c6 100644
--- a/src/controllers/mods.js
+++ b/src/controllers/mods.js
@@ -41,7 +41,8 @@ modsController.flags.detail = function (req, res, next) {
async.parallel({
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
moderatedCids: async.apply(user.getModeratedCids, req.uid),
- flagData: async.apply(flags.get, req.params.flagId)
+ flagData: async.apply(flags.get, req.params.flagId),
+ assignees: async.apply(user.getAdminsandGlobalModsandModerators)
}, function (err, results) {
if (err || !results.flagData) {
return next(err || new Error('[[error:invalid-data]]'));
@@ -49,7 +50,9 @@ modsController.flags.detail = function (req, res, next) {
return next(new Error('[[error:no-privileges]]'));
}
- res.render('flags/detail', results.flagData);
+ res.render('flags/detail', Object.assign(results.flagData, {
+ assignees: results.assignees
+ }));
});
};
diff --git a/src/flags.js b/src/flags.js
index 65ab029e2a..b88dac6b2f 100644
--- a/src/flags.js
+++ b/src/flags.js
@@ -10,6 +10,7 @@ var analytics = require('./analytics');
var topics = require('./topics');
var posts = require('./posts');
var utils = require('../public/src/utils');
+var _ = require('underscore');
var Flags = {
_defaults: {
@@ -24,7 +25,7 @@ Flags.get = function (flagId, callback) {
async.apply(async.parallel, {
base: async.apply(db.getObject.bind(db), 'flag:' + flagId),
history: async.apply(db.getSortedSetRevRange.bind(db), 'flag:' + flagId + ':history', 0, -1),
- notes: async.apply(db.getSortedSetRevRange.bind(db), 'flag:' + flagId + ':notes', 0, -1)
+ notes: async.apply(Flags.getNotes, flagId)
}),
function (data, next) {
// Second stage
@@ -130,6 +131,43 @@ Flags.getTarget = function (type, id, uid, callback) {
}
};
+Flags.getNotes = function (flagId, callback) {
+ async.waterfall([
+ async.apply(db.getSortedSetRevRangeWithScores.bind(db), 'flag:' + flagId + ':notes', 0, -1),
+ function (notes, next) {
+ var uids = [];
+ var noteObj;
+ notes = notes.map(function (note) {
+ try {
+ noteObj = JSON.parse(note.value);
+ uids.push(noteObj[0]);
+ return {
+ uid: noteObj[0],
+ content: noteObj[1],
+ datetime: note.score,
+ datetimeISO: new Date(note.score).toISOString()
+ };
+ } catch (e) {
+ return next(e);
+ }
+ });
+ next(null, notes, uids);
+ },
+ function (notes, uids, next) {
+ user.getUsersData(uids, function (err, users) {
+ if (err) {
+ return next(err);
+ }
+
+ next(null, notes.map(function (note, idx) {
+ note.user = users[idx];
+ return note;
+ }));
+ });
+ }
+ ], callback);
+};
+
Flags.create = function (type, id, uid, reason, callback) {
async.waterfall([
function (next) {
diff --git a/src/user/data.js b/src/user/data.js
index cbaf066ded..1e10704c73 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -80,6 +80,15 @@ module.exports = function (User) {
return callback(null, []);
}
+ // Eliminate duplicates and build ref table
+ uids = uids.filter(function (uid, index) {
+ return index === uids.indexOf(uid);
+ });
+ var ref = uids.reduce(function (memo, cur, idx) {
+ memo[cur] = idx;
+ return memo;
+ }, {});
+
var keys = uids.map(function (uid) {
return 'user:' + uid;
});
@@ -89,6 +98,10 @@ module.exports = function (User) {
return callback(err);
}
+ users = uids.map(function (uid) {
+ return users[ref[uid]];
+ });
+
modifyUserData(users, [], callback);
});
};