Merge branch 'develop' into report-profile-modal

This commit is contained in:
CuriousMagpie
2023-08-11 12:40:07 -04:00
274 changed files with 6703 additions and 4579 deletions
+21 -10
View File
@@ -264,9 +264,10 @@ api.joinChallenge = {
if (!challenge) throw new NotFound(res.t('challengeNotFound'));
const group = await Group.getGroup({
user, groupId: challenge.group, fields: basicGroupFields, optionalMembership: true,
user, groupId: challenge.group, fields: `${basicGroupFields} purchased`, optionalMembership: true,
});
if (!group || !challenge.canJoin(user, group)) throw new NotFound(res.t('challengeNotFound'));
group.purchased = undefined;
const addedSuccessfully = await challenge.addToUser(user);
if (!addedSuccessfully) {
@@ -396,16 +397,25 @@ api.getUserChallenges = {
const { page } = req.query;
const { user } = res.locals;
const orOptions = [
{ _id: { $in: user.challenges } }, // Challenges where the user is participating
];
orOptions.push({ leader: user._id });
// Challenges the user owns
const orOptions = [{ leader: user._id }];
// Challenges where the user is participating
if (user.challenges.length > 0) {
orOptions.push({ _id: { $in: user.challenges } });
}
// Challenges in groups user is a member of, plus public challenges
if (!req.query.member) {
const userGroups = await Group.getGroups({
user,
types: ['party', 'guilds', 'tavern'],
});
const userGroupIds = userGroups.map(userGroup => userGroup._id);
orOptions.push({
group: { $in: user.getGroups() },
}); // Challenges in groups where I'm a member
group: { $in: userGroupIds },
});
}
const query = {
@@ -565,9 +575,10 @@ api.getChallenge = {
// Fetching basic group data
const group = await Group.getGroup({
user, groupId: challenge.group, fields: basicGroupFields, optionalMembership: true,
user, groupId: challenge.group, fields: `${basicGroupFields} purchased`, optionalMembership: true,
});
if (!group || !challenge.canView(user, group)) throw new NotFound(res.t('challengeNotFound'));
group.purchased = undefined;
const chalRes = challenge.toJSON();
chalRes.group = group.toJSON({ minimize: true });
@@ -724,11 +735,11 @@ api.updateChallenge = {
if (!challenge) throw new NotFound(res.t('challengeNotFound'));
const group = await Group.getGroup({
user, groupId: challenge.group, fields: basicGroupFields, optionalMembership: true,
user, groupId: challenge.group, fields: `${basicGroupFields} purchased`, optionalMembership: true,
});
if (!group || !challenge.canView(user, group)) throw new NotFound(res.t('challengeNotFound'));
if (!challenge.canModify(user)) throw new NotAuthorized(res.t('onlyLeaderUpdateChal'));
group.purchased = undefined;
_.merge(challenge, Challenge.sanitizeUpdate(req.body));
const savedChal = await challenge.save();
+9 -2
View File
@@ -129,6 +129,15 @@ api.postChat = {
if (validationErrors) throw validationErrors;
const group = await Group.getGroup({ user, groupId });
if (!group) throw new NotFound(res.t('groupNotFound'));
const { purchased } = group;
const isUpgraded = purchased && purchased.plan && purchased.plan.customerId
&& (!purchased.plan.dateTerminated || moment().isBefore(purchased.plan.dateTerminated));
if (group.type !== 'party' && !isUpgraded) {
throw new BadRequest(res.t('featureRetired'));
}
// Check message for banned slurs
if (group && group.privacy !== 'private' && textContainsBannedSlur(req.body.message)) {
@@ -168,8 +177,6 @@ api.postChat = {
throw new BadRequest(res.t('bannedSlurUsed'));
}
if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.privacy === 'public' && user.flags.chatRevoked) {
throw new NotAuthorized(res.t('chatPrivilegesRevoked'));
}
+12 -15
View File
@@ -126,17 +126,11 @@ api.createGroup = {
if (validationErrors) throw validationErrors;
if (group.type === 'guild') {
if (group.privacy === 'public' && user.flags.chatRevoked) throw new NotAuthorized(res.t('chatPrivilegesRevoked'));
if (user.balance < 1) throw new NotAuthorized(res.t('messageInsufficientGems'));
group.balance = 1;
await user.updateBalance(-1, 'create_guild', group._id, group.name);
user.guilds.push(group._id);
if (!user.achievements.joinedGuild) {
user.achievements.joinedGuild = true;
user.addNotification('GUILD_JOINED_ACHIEVEMENT');
if (!user.hasPermission('fullAccess')) {
throw new BadRequest(res.t('featureRetired'));
}
group.balance = 1;
user.guilds.push(group._id);
} else {
if (group.privacy !== 'private') throw new NotAuthorized(res.t('partyMustbePrivate'));
if (user.party._id) throw new NotAuthorized(res.t('messageGroupAlreadyInParty'));
@@ -493,7 +487,9 @@ api.updateGroup = {
if (group.leader !== user._id && group.type === 'party') throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
else if (group.leader !== user._id && !user.hasPermission('moderator')) throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
if (req.body.leader !== user._id && group.hasNotCancelled()) throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
if (req.body.leader && req.body.leader !== user._id && group.hasNotCancelled()) {
throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
}
const handleArrays = (currentValue, updatedValue) => {
if (!_.isArray(currentValue)) {
@@ -568,6 +564,7 @@ api.joinGroup = {
if (!group) throw new NotFound(res.t('groupNotFound'));
let isUserInvited = false;
const seekingParty = Boolean(user.party.seeking);
if (group.type === 'party') {
// Check if was invited to party
@@ -590,9 +587,10 @@ api.joinGroup = {
if (userPreviousParty) await userPreviousParty.leave(user);
}
}
// Clear all invitations of new user
// Clear all invitations of new user and reset looking for party state
user.invitations.parties = [];
user.invitations.party = {};
user.party.seeking = null;
// invite new user to pending quest
if (group.quest.key && !group.quest.active) {
@@ -732,12 +730,11 @@ api.joinGroup = {
invited: isUserInvited,
};
if (group.type === 'party') {
analyticsObject.seekingParty = Boolean(user.party.seeking);
analyticsObject.seekingParty = seekingParty;
}
if (group.privacy === 'public') {
analyticsObject.groupName = group.name;
}
user.party.seeking = undefined;
if (inviter) promises.push(inviter.save());
promises = await Promise.all(promises);
@@ -1393,6 +1390,7 @@ api.getLookingForParty = {
const seekers = await User
.find({
'party.seeking': { $exists: true },
'invitations.party.id': { $exists: false },
'auth.timestamps.loggedin': {
$gt: moment().subtract(7, 'days').toDate(),
},
@@ -1408,7 +1406,6 @@ api.getLookingForParty = {
const filteredSeekers = seekers.filter(seeker => {
if (seeker.party._id) return false;
if (seeker.invitations.party.id) return false;
if (seeker.flags.chatRevoked) return false;
if (seeker.auth.blocked) return false;
if (seeker.inbox.blocks.indexOf(user._id) !== -1) return false;