mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
* initial commit * update logic to display flagged challenges properly to users and admins * add report button to pages 'My Challenges' and 'Discover Challenges' * allow mods to view flagged messages on challengeDetail view * update showing flagged challenges for group challenges * update showing flagged challenges for a specific challenge * disallow closing a flagged challenge * update notes to reflect apiParams properly * fix css spacing * update challenge en locales * fix spacing * update title of closeChallengeModal * let user know flagged challenges cannot be cloned * fix linting errors * ensure flagged challenges cannot be declared with a winner and cloned via API * define a non user challenge properly * fix logic to check for a nonParticipant and nonLeader user when grabbing flagged challenges * fix linting of max character of 100 / line * remove reporting on 'my challenges' and 'discover challenges' * WIP(challenges): disable clone button and add notes to new functions * WIP(challenges): smol changes * WIP(challenges): clone button only disabled for admin and flagged user; other users can still clone but the flag goes along with the clone * WIP(challenges): stop flags carrying over on cloned challenges * WIP(challenges): typo fixing, undoing a smol change * fix(challenges): improved query logic for flags * WIP(challenges): more smol changes * fix(challenges): refactor queries * fix(challenges): correct My Challenges tab logic * WIP(challenges): fix clone button state * WIP(challenges): really fixed clone button & clear flags from clones * WIP(challenge): implement new design for reporting modal * WIP(challenge): making things pretty * WIP(challenge): conquering the close button * WIP(challenge): fixin some spacing * WIP(challenge): smol fix * WIP(challenge): making sure the button is actually disabled * WIP(challenge): fix blockquote css * fix(tests): no private guilds * fix(lint): curlies etc * fix(test): moderator permission * fix(lint): sure man whatever * fix(lint): bad vim no tabby * fix(test): permissions not contrib lol * fix(challenges): add icon and fix leaky CSS * fix(challenge): correct clone button behavior --------- Co-authored-by: Julius Jung <me@matchajune.io> Co-authored-by: SabreCat <sabe@habitica.com> Co-authored-by: Sabe Jones <sabrecat@gmail.com>
83 lines
2.9 KiB
JavaScript
83 lines
2.9 KiB
JavaScript
import nconf from 'nconf';
|
|
import { getUserInfo, sendTxn, getGroupUrl } from '../email';
|
|
import { NotFound } from '../errors';
|
|
import * as slack from '../slack';
|
|
|
|
const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map(email => ({ email, canSend: true }));
|
|
|
|
export async function notifyOfFlaggedChallenge (challenge, user, userComment) {
|
|
const reporterEmailContent = getUserInfo(user, ['email']).email;
|
|
|
|
const emailVariables = [
|
|
{ name: 'CHALLENGE_NAME', content: challenge.name },
|
|
{ name: 'CHALLENGE_ID', content: challenge._id },
|
|
|
|
{ name: 'REPORTER_USERNAME', content: user.profile.name },
|
|
{ name: 'REPORTER_UUID', content: user._id },
|
|
{ name: 'REPORTER_EMAIL', content: reporterEmailContent },
|
|
{ name: 'REPORTER_MODAL_URL', content: `/static/front/#?memberId=${user._id}` },
|
|
{ name: 'REPORTER_COMMENT', content: userComment || '' },
|
|
|
|
{ name: 'AUTHOR_UUID', content: challenge.leader._id },
|
|
{ name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${challenge.leader._id}` },
|
|
];
|
|
|
|
sendTxn(FLAG_REPORT_EMAILS, 'flag-report-to-mods', emailVariables);
|
|
|
|
slack.sendChallengeFlagNotification({
|
|
flagger: user,
|
|
challenge,
|
|
userComment,
|
|
});
|
|
}
|
|
|
|
export async function flagChallenge (challenge, user, res) {
|
|
if (challenge.flags[user._id] && !user.contributor.admin) throw new NotFound(res.t('messageChallengeFlagAlreadyReported'));
|
|
|
|
challenge.flags[user._id] = true;
|
|
challenge.markModified('flags');
|
|
|
|
if (user.contributor.admin) {
|
|
// Arbitrary amount, higher than 2
|
|
challenge.flagCount = 5;
|
|
} else {
|
|
challenge.flagCount += 1;
|
|
}
|
|
|
|
await challenge.save();
|
|
}
|
|
|
|
export async function clearFlags (challenge, user) {
|
|
challenge.flagCount = 0;
|
|
if (user.contributor.admin) { // let's get this to a proper "permissions" check later
|
|
challenge.flags = {};
|
|
challenge.markModified('flags');
|
|
} else if (challenge.flags[user._id]) {
|
|
challenge.flags[user._id] = false;
|
|
challenge.markModified('flags');
|
|
}
|
|
await challenge.save();
|
|
|
|
const adminEmailContent = getUserInfo(user, ['email']).email;
|
|
const challengeUrl = `/challenges/${challenge._id}`;
|
|
|
|
const groupUrl = getGroupUrl({ _id: challenge.group, type: 'guild' });
|
|
|
|
sendTxn(FLAG_REPORT_EMAILS, 'unflag-report-to-mods', [
|
|
{ name: 'ADMIN_USERNAME', content: user.profile.name },
|
|
{ name: 'ADMIN_UUID', content: user._id },
|
|
{ name: 'ADMIN_EMAIL', content: adminEmailContent },
|
|
{ name: 'ADMIN_MODAL_URL', content: `/static/front/#?memberId=${user._id}` },
|
|
|
|
{ name: 'AUTHOR_UUID', content: challenge.leader },
|
|
{ name: 'AUTHOR_EMAIL', content: adminEmailContent },
|
|
{ name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${challenge.leader}` },
|
|
|
|
{ name: 'CHALLENGE_NAME', content: challenge.name },
|
|
{ name: 'CHALLENGE_ID', content: challenge._id },
|
|
{ name: 'CHALLENGE_URL', content: challengeUrl },
|
|
|
|
{ name: 'GROUP_URL', content: groupUrl },
|
|
]);
|
|
}
|