Group plans misc fixes (#8388)

* Added notification for approval request in the group leaders language

* Added test for group task meta actions. Added sync when user claims

* Added tests for group task actions. Ensured assigned members are synce when added or removed

* Fixed approval required toggle

* Added support for users with comma in their name

* Fixed sync issue when user is approved and reloads the website

* Added advance options for group rewards

* Added back ticks to group claim message

* Fixed disappearing tasks that need approval

* Up chat limit to 400 for subbed groups

* Fixed line endings

* Updated activie subscription check

* Added group isSubscribed function

* Changed to isAfter
This commit is contained in:
Keith Holliday
2017-01-18 07:54:49 -07:00
committed by GitHub
parent e4bb82768c
commit 28fec237fe
16 changed files with 169 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import moment from 'moment';
import mongoose from 'mongoose';
import {
model as User,
@@ -392,7 +393,17 @@ schema.methods.sendChat = function sendChat (message, user) {
let newMessage = chatDefaults(message, user);
this.chat.unshift(newMessage);
this.chat.splice(200);
const MAX_CHAT_COUNT = 200;
const MAX_SUBBED_GROUP_CHAT_COUNT = 400;
let maxCount = MAX_CHAT_COUNT;
if (this.isSubscribed()) {
maxCount = MAX_SUBBED_GROUP_CHAT_COUNT;
}
this.chat.splice(maxCount);
// do not send notifications for guilds with more than 5000 users and for the tavern
if (NO_CHAT_NOTIFICATIONS.indexOf(this._id) !== -1 || this.memberCount > LARGE_GROUP_COUNT_MESSAGE_CUTOFF) {
@@ -882,8 +893,7 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all') {
let group = this;
let update = {};
let plan = group.purchased.plan;
if (group.memberCount <= 1 && group.privacy === 'private' && plan && plan.customerId && !plan.dateTerminated) {
if (group.memberCount <= 1 && group.privacy === 'private' && group.isSubscribed()) {
throw new NotAuthorized(shared.i18n.t('cannotDeleteActiveGroup'));
}
@@ -1136,6 +1146,12 @@ schema.methods.removeTask = async function groupRemoveTask (task) {
}, {multi: true}).exec();
};
schema.methods.isSubscribed = function isSubscribed () {
let now = new Date();
let plan = this.purchased.plan;
return plan && plan.customerId && (!plan.dateTerminated || moment(plan.dateTerminated).isAfter(now));
};
export let model = mongoose.model('Group', schema);
// initialize tavern if !exists (fresh installs)