mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Server setting to disallow chat from new accounts (#13952)
* feat(chat): server setting to disallow chat from new accounts * fix(tests): many adjustments to handle chat minimum age * fix(tests): address issues outside of chat posting * chore(analytics): add incident logging * fix(config): allow instant chat for dev purposes * fix(test): finely age one more user * fix(test): member not leader Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import moment from 'moment';
|
||||
import nconf from 'nconf';
|
||||
import { authWithHeaders } from '../../middlewares/auth';
|
||||
import { model as Group } from '../../models/group';
|
||||
@@ -22,7 +23,11 @@ import { getMatchesByWordArray } from '../../libs/stringUtils';
|
||||
import bannedSlurs from '../../libs/bannedSlurs';
|
||||
import apiError from '../../libs/apiError';
|
||||
import highlightMentions from '../../libs/highlightMentions';
|
||||
import { getAnalyticsServiceByEnvironment } from '../../libs/analyticsService';
|
||||
|
||||
const analytics = getAnalyticsServiceByEnvironment();
|
||||
|
||||
const ACCOUNT_MIN_CHAT_AGE = Number(nconf.get('ACCOUNT_MIN_CHAT_AGE'));
|
||||
const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map(email => ({ email, canSend: true }));
|
||||
|
||||
/**
|
||||
@@ -188,6 +193,17 @@ api.postChat = {
|
||||
throw new NotAuthorized(res.t('messageGroupChatSpam'));
|
||||
}
|
||||
|
||||
// Check if account is newer than the minimum age for chat participation
|
||||
if (moment().diff(user.auth.timestamps.created, 'minutes') < ACCOUNT_MIN_CHAT_AGE) {
|
||||
analytics.track('chat age error', {
|
||||
uuid: user._id,
|
||||
hitType: 'event',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
throw new BadRequest(res.t('chatTemporarilyUnavailable'));
|
||||
}
|
||||
|
||||
const sanitizedMessageText = sanitizeMessageText(req.body.message);
|
||||
const [message, mentions, mentionedMembers] = await highlightMentions(sanitizedMessageText);
|
||||
let client = req.headers['x-client'] || '3rd Party';
|
||||
|
||||
Reference in New Issue
Block a user