mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
@@ -1,6 +1,5 @@
|
|||||||
import { IncomingWebhook } from '@slack/client';
|
import { IncomingWebhook } from '@slack/client';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import moment from 'moment';
|
|
||||||
import {
|
import {
|
||||||
createAndPopulateGroup,
|
createAndPopulateGroup,
|
||||||
generateUser,
|
generateUser,
|
||||||
@@ -90,32 +89,6 @@ describe('POST /chat', () => {
|
|||||||
message: t('chatPrivilegesRevoked'),
|
message: t('chatPrivilegesRevoked'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an error when user is muted with date', async () => {
|
|
||||||
const userWithChatRevoked = await member.update({
|
|
||||||
'flags.chatRevoked': true,
|
|
||||||
'flags.chatRevokedEndDate': moment().add(1, 'days').toDate(),
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(userWithChatRevoked.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage})).to.eventually.be.rejected.and.eql({
|
|
||||||
code: 401,
|
|
||||||
error: 'NotAuthorized',
|
|
||||||
message: t('chatPrivilegesRevoked'),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('allows a user to chat after revoked time has passed', async () => {
|
|
||||||
const userWithChatRevoked = await member.update({
|
|
||||||
'flags.chatRevoked': true,
|
|
||||||
'flags.chatRevokedEndDate': moment().subtract(1, 'days').toDate(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const newMessage = await userWithChatRevoked.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage});
|
|
||||||
const groupMessages = await userWithChatRevoked.get(`/groups/${groupWithChat._id}/chat`);
|
|
||||||
|
|
||||||
expect(newMessage.message.id).to.exist;
|
|
||||||
expect(groupMessages[0].id).to.exist;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context('banned word', () => {
|
context('banned word', () => {
|
||||||
|
|||||||
@@ -55,21 +55,10 @@
|
|||||||
div(v-if="expandAuth")
|
div(v-if="expandAuth")
|
||||||
pre {{hero.auth}}
|
pre {{hero.auth}}
|
||||||
.form-group
|
.form-group
|
||||||
h5 User Mute Settings
|
|
||||||
.checkbox
|
.checkbox
|
||||||
label
|
label
|
||||||
input(type='checkbox', v-if='hero.flags', v-model='hero.flags.chatRevoked')
|
input(type='checkbox', v-if='hero.flags', v-model='hero.flags.chatRevoked')
|
||||||
strong Chat Privileges Revoked
|
strong Chat Privileges Revoked
|
||||||
div(v-if='hero.flags.chatRevoked && hero.flags.chatRevokedEndDate')
|
|
||||||
strong User is currently muted until
|
|
||||||
br
|
|
||||||
div {{ userRevokedEndDate(hero) }}
|
|
||||||
div(v-else-if='hero.flags.chatRevoked')
|
|
||||||
strong User is currently muted indefinitely
|
|
||||||
div
|
|
||||||
strong For how many days from today do you want to mute this user? Leave as 0 for indefinite.
|
|
||||||
br
|
|
||||||
input(type='number', v-model='numberOfDaysToMute')
|
|
||||||
.form-group
|
.form-group
|
||||||
.checkbox
|
.checkbox
|
||||||
label
|
label
|
||||||
@@ -114,7 +103,6 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import moment from 'moment';
|
|
||||||
import each from 'lodash/each';
|
import each from 'lodash/each';
|
||||||
|
|
||||||
import markdownDirective from 'client/directives/markdown';
|
import markdownDirective from 'client/directives/markdown';
|
||||||
@@ -143,7 +131,6 @@ export default {
|
|||||||
gear,
|
gear,
|
||||||
expandItems: false,
|
expandItems: false,
|
||||||
expandAuth: false,
|
expandAuth: false,
|
||||||
numberOfDaysToMute: 0,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
directives: {
|
directives: {
|
||||||
@@ -156,10 +143,6 @@ export default {
|
|||||||
...mapState({user: 'user.data'}),
|
...mapState({user: 'user.data'}),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
userRevokedEndDate (hero) {
|
|
||||||
if (moment().isAfter(moment(hero.flags.chatRevokedEndDate))) return 'User is no longer muted';
|
|
||||||
return moment(hero.flags.chatRevokedEndDate).format(this.user.preferences.dateFormat.toUpperCase());
|
|
||||||
},
|
|
||||||
getAllItemPaths () {
|
getAllItemPaths () {
|
||||||
// let questsFormat = this.getFormattedItemReference('items.quests', keys(this.quests), 'Numeric Quantity');
|
// let questsFormat = this.getFormattedItemReference('items.quests', keys(this.quests), 'Numeric Quantity');
|
||||||
// let mountsFormat = this.getFormattedItemReference('items.mounts', keys(this.mountInfo), 'Boolean');
|
// let mountsFormat = this.getFormattedItemReference('items.mounts', keys(this.mountInfo), 'Boolean');
|
||||||
@@ -200,11 +183,6 @@ export default {
|
|||||||
this.expandAuth = false;
|
this.expandAuth = false;
|
||||||
},
|
},
|
||||||
async saveHero () {
|
async saveHero () {
|
||||||
if (this.numberOfDaysToMute) {
|
|
||||||
const dayToEndMute = moment().add(this.numberOfDaysToMute, 'days').utc().toDate();
|
|
||||||
this.hero.flags.chatRevokedEndDate = dayToEndMute;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hero.contributor.admin = this.hero.contributor.level > 7 ? true : false;
|
this.hero.contributor.admin = this.hero.contributor.level > 7 ? true : false;
|
||||||
let heroUpdated = await this.$store.dispatch('hall:updateHero', { heroDetails: this.hero });
|
let heroUpdated = await this.$store.dispatch('hall:updateHero', { heroDetails: this.hero });
|
||||||
this.text('User updated');
|
this.text('User updated');
|
||||||
@@ -212,7 +190,6 @@ export default {
|
|||||||
this.heroID = -1;
|
this.heroID = -1;
|
||||||
this.heroes[this.currentHeroIndex] = heroUpdated;
|
this.heroes[this.currentHeroIndex] = heroUpdated;
|
||||||
this.currentHeroIndex = -1;
|
this.currentHeroIndex = -1;
|
||||||
this.numberOfDaysToMute = 0;
|
|
||||||
},
|
},
|
||||||
populateContributorInput (id, index) {
|
populateContributorInput (id, index) {
|
||||||
this.heroID = id;
|
this.heroID = id;
|
||||||
@@ -226,9 +203,6 @@ export default {
|
|||||||
startingPage: 'profile',
|
startingPage: 'profile',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
userLevelStyle () {
|
|
||||||
// @TODO: implement
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { getUserInfo, getGroupUrl, sendTxn } from '../../libs/email';
|
|||||||
import slack from '../../libs/slack';
|
import slack from '../../libs/slack';
|
||||||
import pusher from '../../libs/pusher';
|
import pusher from '../../libs/pusher';
|
||||||
import { getAuthorEmailFromMessage } from '../../libs/chat';
|
import { getAuthorEmailFromMessage } from '../../libs/chat';
|
||||||
import { userIsMuted, muteUserForLife } from '../../libs/chat/mute';
|
|
||||||
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import bannedWords from '../../libs/bannedWords';
|
import bannedWords from '../../libs/bannedWords';
|
||||||
@@ -125,7 +124,6 @@ api.postChat = {
|
|||||||
if (textContainsBannedSlur(req.body.message)) {
|
if (textContainsBannedSlur(req.body.message)) {
|
||||||
let message = req.body.message;
|
let message = req.body.message;
|
||||||
user.flags.chatRevoked = true;
|
user.flags.chatRevoked = true;
|
||||||
muteUserForLife(user);
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
// Email the mods
|
// Email the mods
|
||||||
@@ -162,7 +160,7 @@ api.postChat = {
|
|||||||
|
|
||||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||||
|
|
||||||
if (group.privacy !== 'private' && userIsMuted(user)) {
|
if (group.privacy !== 'private' && user.flags.chatRevoked) {
|
||||||
throw new NotAuthorized(res.t('chatPrivilegesRevoked'));
|
throw new NotAuthorized(res.t('chatPrivilegesRevoked'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ api.getHeroes = {
|
|||||||
// Note, while the following routes are called getHero / updateHero
|
// Note, while the following routes are called getHero / updateHero
|
||||||
// they can be used by admins to get/update any user
|
// they can be used by admins to get/update any user
|
||||||
|
|
||||||
const heroAdminFields = 'contributor balance profile.name purchased items auth flags.chatRevoked flags.chatRevokedEndDate';
|
const heroAdminFields = 'contributor balance profile.name purchased items auth flags.chatRevoked';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} /api/v3/hall/heroes/:heroId Get any user ("hero") given the UUID
|
* @api {get} /api/v3/hall/heroes/:heroId Get any user ("hero") given the UUID
|
||||||
@@ -275,7 +275,6 @@ api.updateHero = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updateData.flags && _.isBoolean(updateData.flags.chatRevoked)) hero.flags.chatRevoked = updateData.flags.chatRevoked;
|
if (updateData.flags && _.isBoolean(updateData.flags.chatRevoked)) hero.flags.chatRevoked = updateData.flags.chatRevoked;
|
||||||
if (updateData.flags && updateData.flags.chatRevokedEndDate) hero.flags.chatRevokedEndDate = updateData.flags.chatRevokedEndDate;
|
|
||||||
|
|
||||||
let savedHero = await hero.save();
|
let savedHero = await hero.save();
|
||||||
let heroJSON = savedHero.toJSON();
|
let heroJSON = savedHero.toJSON();
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
function userIsMuted (user) {
|
|
||||||
if (!user.flags.chatRevoked) return false;
|
|
||||||
|
|
||||||
// User is muted indefinitely
|
|
||||||
if (!user.flags.chatRevokedEndDate) return true;
|
|
||||||
|
|
||||||
return moment(user.flags.chatRevokedEndDate).isAfter(moment());
|
|
||||||
}
|
|
||||||
|
|
||||||
function muteUserForLife (user) {
|
|
||||||
user.flags.chatRevokedEndDate = moment().add(1000, 'years').toDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
userIsMuted,
|
|
||||||
muteUserForLife,
|
|
||||||
};
|
|
||||||
@@ -223,7 +223,6 @@ let schema = new Schema({
|
|||||||
return {};
|
return {};
|
||||||
}},
|
}},
|
||||||
chatRevoked: Boolean,
|
chatRevoked: Boolean,
|
||||||
chatRevokedEndDate: Date,
|
|
||||||
// Used to track the status of recapture emails sent to each user,
|
// Used to track the status of recapture emails sent to each user,
|
||||||
// can be 0 - no email sent - 1, 2, 3 or 4 - 4 means no more email will be sent to the user
|
// can be 0 - no email sent - 1, 2, 3 or 4 - 4 means no more email will be sent to the user
|
||||||
recaptureEmailsPhase: {type: Number, default: 0},
|
recaptureEmailsPhase: {type: Number, default: 0},
|
||||||
|
|||||||
Reference in New Issue
Block a user