flag assignees, state, notes WIP, #5232

v1.18.x
Julian Lam 8 years ago
parent 77809b2b52
commit c5c2d27180

@ -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"
}

@ -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",

@ -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
}));
});
};

@ -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) {

@ -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);
});
};

Loading…
Cancel
Save