mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
pass userId for admin-calls
This commit is contained in:
@@ -45,7 +45,6 @@ describe('POST /members/flag-private-message/:messageId', () => {
|
|||||||
|
|
||||||
expect(sendersMessageInReceiversInbox).to.exist;
|
expect(sendersMessageInReceiversInbox).to.exist;
|
||||||
await expect(receiver.post(`/members/flag-private-message/${sendersMessageInReceiversInbox.id}`)).to.eventually.be.ok;
|
await expect(receiver.post(`/members/flag-private-message/${sendersMessageInReceiversInbox.id}`)).to.eventually.be.ok;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns an error when user tries to flag a private message that is already flagged', async () => {
|
it('Returns an error when user tries to flag a private message that is already flagged', async () => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
|
import { model as User } from '../../models/user';
|
||||||
|
|
||||||
import ChatReporter from './chatReporter';
|
import ChatReporter from './chatReporter';
|
||||||
import {
|
import {
|
||||||
@@ -18,7 +19,8 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
constructor (req, res) {
|
constructor (req, res) {
|
||||||
super(req, res);
|
super(req, res);
|
||||||
|
|
||||||
this.user = res.locals.user;
|
this.reporter = res.locals.user;
|
||||||
|
this.inboxUser = res.locals.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async validate () {
|
async validate () {
|
||||||
@@ -27,7 +29,11 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
let validationErrors = this.req.validationErrors();
|
let validationErrors = this.req.validationErrors();
|
||||||
if (validationErrors) throw validationErrors;
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
let messages = this.user.inbox.messages;
|
if (this.reporter.contributor.admin && this.req.query.userId) {
|
||||||
|
this.inboxUser = await User.findOne({_id: this.req.query.userId});
|
||||||
|
}
|
||||||
|
|
||||||
|
let messages = this.inboxUser.inbox.messages;
|
||||||
|
|
||||||
const message = _find(messages, (m) => m.id === this.req.params.messageId);
|
const message = _find(messages, (m) => m.id === this.req.params.messageId);
|
||||||
if (!message) throw new NotFound(this.res.t('messageGroupChatNotFound'));
|
if (!message) throw new NotFound(this.res.t('messageGroupChatNotFound'));
|
||||||
@@ -55,7 +61,7 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
|
|
||||||
slack.sendInboxFlagNotification({
|
slack.sendInboxFlagNotification({
|
||||||
authorEmail: this.authorEmail,
|
authorEmail: this.authorEmail,
|
||||||
flagger: this.user,
|
flagger: this.reporter,
|
||||||
message,
|
message,
|
||||||
userComment,
|
userComment,
|
||||||
});
|
});
|
||||||
@@ -64,26 +70,26 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
updateMessageAndSave (message, updateFunc) {
|
updateMessageAndSave (message, updateFunc) {
|
||||||
updateFunc(message);
|
updateFunc(message);
|
||||||
|
|
||||||
this.user.inbox.messages[message.id] = message;
|
this.inboxUser.inbox.messages[message.id] = message;
|
||||||
this.user.markModified('inbox.messages');
|
this.inboxUser.markModified('inbox.messages');
|
||||||
|
|
||||||
return this.user.save();
|
return this.inboxUser.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
flagInboxMessage (message) {
|
flagInboxMessage (message) {
|
||||||
// Log user ids that have flagged the message
|
// Log user ids that have flagged the message
|
||||||
if (!message.flags) message.flags = {};
|
if (!message.flags) message.flags = {};
|
||||||
// TODO fix error type
|
// TODO fix error type
|
||||||
if (message.flags[this.user._id] && !this.user.contributor.admin) {
|
if (message.flags[this.reporter._id] && !this.reporter.contributor.admin) {
|
||||||
throw new NotFound(this.res.t('messageGroupChatFlagAlreadyReported'));
|
throw new NotFound(this.res.t('messageGroupChatFlagAlreadyReported'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.updateMessageAndSave(message, (m) => {
|
return this.updateMessageAndSave(message, (m) => {
|
||||||
m.flags[this.user._id] = true;
|
m.flags[this.reporter._id] = true;
|
||||||
|
|
||||||
// Log total number of flags (publicly viewable)
|
// Log total number of flags (publicly viewable)
|
||||||
if (!m.flagCount) m.flagCount = 0;
|
if (!m.flagCount) m.flagCount = 0;
|
||||||
if (this.user.contributor.admin) {
|
if (this.reporter.contributor.admin) {
|
||||||
// Arbitrary amount, higher than 2
|
// Arbitrary amount, higher than 2
|
||||||
m.flagCount = 5;
|
m.flagCount = 5;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ function sendInboxFlagNotification ({
|
|||||||
title,
|
title,
|
||||||
title_link: titleLink,
|
title_link: titleLink,
|
||||||
text: messageText,
|
text: messageText,
|
||||||
footer: `<${SLACK_FLAGGING_FOOTER_LINK}?groupId=privateMessages&chatId=${message.id}|Flag this message>`,
|
footer: `<${SLACK_FLAGGING_FOOTER_LINK}?userId=${flagger.id}&chatMessageId=${message.id}|Flag this message>`,
|
||||||
mrkdwn_in: [
|
mrkdwn_in: [
|
||||||
'text',
|
'text',
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user