mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
fix: prevent 500 error when unflagging a system message
This commit is contained in:
parent
c703517b25
commit
36d3ac4611
2 changed files with 50 additions and 19 deletions
|
|
@ -73,6 +73,36 @@ describe('POST /groups/:id/chat/:id/clearflags', () => {
|
||||||
let messages = await members[0].get(`/groups/${group._id}/chat`);
|
let messages = await members[0].get(`/groups/${group._id}/chat`);
|
||||||
expect(messages[0].flagCount).to.eql(0);
|
expect(messages[0].flagCount).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can unflag a system message', async () => {
|
||||||
|
let { group, members } = await createAndPopulateGroup({
|
||||||
|
groupDetails: {
|
||||||
|
type: 'party',
|
||||||
|
privacy: 'private',
|
||||||
|
},
|
||||||
|
members: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
let member = members[0];
|
||||||
|
|
||||||
|
// make member that can use skills
|
||||||
|
await member.update({
|
||||||
|
'stats.lvl': 100,
|
||||||
|
'stats.mp': 400,
|
||||||
|
'stats.class': 'wizard',
|
||||||
|
});
|
||||||
|
|
||||||
|
await member.post('/user/class/cast/mpheal');
|
||||||
|
|
||||||
|
let [skillMsg] = await member.get(`/groups/${group.id}/chat`);
|
||||||
|
|
||||||
|
await member.post(`/groups/${group._id}/chat/${skillMsg.id}/flag`);
|
||||||
|
await admin.post(`/groups/${group._id}/chat/${skillMsg.id}/clearflags`);
|
||||||
|
|
||||||
|
let messages = await members[0].get(`/groups/${group._id}/chat`);
|
||||||
|
expect(messages[0].id).to.eql(skillMsg.id);
|
||||||
|
expect(messages[0].flagCount).to.eql(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('admin user, group with multiple messages', () => {
|
context('admin user, group with multiple messages', () => {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,22 @@ const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map((email)
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
|
async function getAuthorEmailFromMessage (message) {
|
||||||
|
let authorId = message.uuid;
|
||||||
|
|
||||||
|
if (authorId === 'system') {
|
||||||
|
return 'system';
|
||||||
|
}
|
||||||
|
|
||||||
|
let author = await User.findOne({_id: authorId}, {auth: 1});
|
||||||
|
|
||||||
|
if (author) {
|
||||||
|
return getUserInfo(author, ['email']).email;
|
||||||
|
} else {
|
||||||
|
return 'Author Account Deleted';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} /api/v3/groups/:groupId/chat Get chat messages from a group
|
* @api {get} /api/v3/groups/:groupId/chat Get chat messages from a group
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
|
|
@ -208,8 +224,6 @@ api.flagChat = {
|
||||||
|
|
||||||
if (message.uuid === user._id) throw new NotFound(res.t('messageGroupChatFlagOwnMessage'));
|
if (message.uuid === user._id) throw new NotFound(res.t('messageGroupChatFlagOwnMessage'));
|
||||||
|
|
||||||
let author = await User.findOne({_id: message.uuid}, {auth: 1});
|
|
||||||
|
|
||||||
let update = {$set: {}};
|
let update = {$set: {}};
|
||||||
|
|
||||||
// Log user ids that have flagged the message
|
// Log user ids that have flagged the message
|
||||||
|
|
@ -234,16 +248,7 @@ api.flagChat = {
|
||||||
);
|
);
|
||||||
|
|
||||||
let reporterEmailContent = getUserInfo(user, ['email']).email;
|
let reporterEmailContent = getUserInfo(user, ['email']).email;
|
||||||
|
let authorEmail = await getAuthorEmailFromMessage(message);
|
||||||
let authorEmailContent;
|
|
||||||
if (author) {
|
|
||||||
authorEmailContent = getUserInfo(author, ['email']).email;
|
|
||||||
} else if (message.uuid === 'system') {
|
|
||||||
authorEmailContent = 'system';
|
|
||||||
} else {
|
|
||||||
authorEmailContent = 'Author Account Deleted';
|
|
||||||
}
|
|
||||||
|
|
||||||
let groupUrl = getGroupUrl(group);
|
let groupUrl = getGroupUrl(group);
|
||||||
|
|
||||||
sendTxn(FLAG_REPORT_EMAILS, 'flag-report-to-mods', [
|
sendTxn(FLAG_REPORT_EMAILS, 'flag-report-to-mods', [
|
||||||
|
|
@ -257,7 +262,7 @@ api.flagChat = {
|
||||||
|
|
||||||
{name: 'AUTHOR_USERNAME', content: message.user},
|
{name: 'AUTHOR_USERNAME', content: message.user},
|
||||||
{name: 'AUTHOR_UUID', content: message.uuid},
|
{name: 'AUTHOR_UUID', content: message.uuid},
|
||||||
{name: 'AUTHOR_EMAIL', content: authorEmailContent},
|
{name: 'AUTHOR_EMAIL', content: authorEmail},
|
||||||
{name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${message.uuid}`},
|
{name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${message.uuid}`},
|
||||||
|
|
||||||
{name: 'GROUP_NAME', content: group.name},
|
{name: 'GROUP_NAME', content: group.name},
|
||||||
|
|
@ -329,11 +334,7 @@ api.clearChatFlags = {
|
||||||
);
|
);
|
||||||
|
|
||||||
let adminEmailContent = getUserInfo(user, ['email']).email;
|
let adminEmailContent = getUserInfo(user, ['email']).email;
|
||||||
|
let authorEmail = getAuthorEmailFromMessage(message);
|
||||||
let author = await User.findOne({_id: message.uuid}, {auth: 1});
|
|
||||||
|
|
||||||
let authorEmailContent = getUserInfo(author, ['email']).email;
|
|
||||||
|
|
||||||
let groupUrl = getGroupUrl(group);
|
let groupUrl = getGroupUrl(group);
|
||||||
|
|
||||||
sendTxn(FLAG_REPORT_EMAILS, 'unflag-report-to-mods', [
|
sendTxn(FLAG_REPORT_EMAILS, 'unflag-report-to-mods', [
|
||||||
|
|
@ -347,7 +348,7 @@ api.clearChatFlags = {
|
||||||
|
|
||||||
{name: 'AUTHOR_USERNAME', content: message.user},
|
{name: 'AUTHOR_USERNAME', content: message.user},
|
||||||
{name: 'AUTHOR_UUID', content: message.uuid},
|
{name: 'AUTHOR_UUID', content: message.uuid},
|
||||||
{name: 'AUTHOR_EMAIL', content: authorEmailContent},
|
{name: 'AUTHOR_EMAIL', content: authorEmail},
|
||||||
{name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${message.uuid}`},
|
{name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${message.uuid}`},
|
||||||
|
|
||||||
{name: 'GROUP_NAME', content: group.name},
|
{name: 'GROUP_NAME', content: group.name},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue