From 9fa355fbcc019b2814837b26675bb43e49e23c48 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Mon, 7 Aug 2023 15:04:44 -0500 Subject: [PATCH] fix(sunset): release candidate --- .../src/components/static/communityGuidelines.vue | 1 - website/common/locales/en/communityGuidelines.json | 2 +- website/server/controllers/api-v3/challenges.js | 11 +++++++++-- website/server/controllers/api-v3/groups.js | 5 +++-- website/server/libs/challenges/index.js | 3 +++ website/server/models/user/methods.js | 9 ++++++--- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/website/client/src/components/static/communityGuidelines.vue b/website/client/src/components/static/communityGuidelines.vue index dfb1cef9f3..52a653439e 100644 --- a/website/client/src/components/static/communityGuidelines.vue +++ b/website/client/src/components/static/communityGuidelines.vue @@ -169,7 +169,6 @@ diff --git a/website/common/locales/en/communityGuidelines.json b/website/common/locales/en/communityGuidelines.json index 69a7836cd1..1585b80ab5 100644 --- a/website/common/locales/en/communityGuidelines.json +++ b/website/common/locales/en/communityGuidelines.json @@ -30,7 +30,7 @@ "commGuideHeadingInfractionsEtc": "Infractions, Consequences, and Restoration", "commGuideHeadingInfractions": "Infractions", - "commGuidePara050": "Overwhelmingly, Habiticans assist each other, are respectful, and work to make the whole community fun and friendly. However, once in a blue moon, something that a Habitican does may violate one of the above Guidelines. When this happens, the Staff will take whatever actions they deem necessary to keep Habitica safe and comfortable for everyone.", + "commGuidePara050": "Overwhelmingly, Habiticans assist each other, are respectful, and work to make the atmosphere here fun and friendly. However, once in a blue moon, something that a Habitican does may violate one of the above Guidelines. When this happens, the Staff will take whatever actions they deem necessary to keep Habitica safe and comfortable for everyone.", "commGuidePara051": "There are a variety of infractions, and they are dealt with depending on their severity. These are not comprehensive lists, and the Staff can make decisions on topics not covered here at their own discretion. The Staff will take context into account when evaluating infractions.", "commGuideHeadingSevereInfractions": "Severe Infractions", diff --git a/website/server/controllers/api-v3/challenges.js b/website/server/controllers/api-v3/challenges.js index 064d03962b..c5dcb991f2 100644 --- a/website/server/controllers/api-v3/challenges.js +++ b/website/server/controllers/api-v3/challenges.js @@ -14,6 +14,7 @@ import { import { NotFound, NotAuthorized, + BadRequest, } from '../../libs/errors'; import * as Tasks from '../../models/task'; import csvStringify from '../../libs/csvStringify'; @@ -266,7 +267,12 @@ api.joinChallenge = { const group = await Group.getGroup({ user, groupId: challenge.group, fields: basicGroupFields, optionalMembership: true, }); - if (!group || !challenge.canJoin(user, group)) throw new NotFound(res.t('challengeNotFound')); + if (!group || group.type === 'party' && group._id !== user.party._id) { + throw new NotFound(res.t('challengeNotFound')); + } + if (group.type === 'guild' && group._id !== TAVERN_ID && !group.hasActiveGroupPlan()) { + throw new BadRequest(res.t('featureRetired')); + } const addedSuccessfully = await challenge.addToUser(user); if (!addedSuccessfully) { @@ -403,8 +409,9 @@ api.getUserChallenges = { orOptions.push({ leader: user._id }); if (!req.query.member) { + const userGroups = await user.getGroups(); orOptions.push({ - group: { $in: user.getGroups() }, + group: { $in: userGroups }, }); // Challenges in groups where I'm a member } diff --git a/website/server/controllers/api-v3/groups.js b/website/server/controllers/api-v3/groups.js index 4d8fdc4084..c489bd2342 100644 --- a/website/server/controllers/api-v3/groups.js +++ b/website/server/controllers/api-v3/groups.js @@ -5,6 +5,7 @@ import { authWithHeaders } from '../../middlewares/auth'; import { model as Group, basicFields as basicGroupFields, + TAVERN_ID, } from '../../models/group'; import { model as User, @@ -411,7 +412,7 @@ api.getGroup = { const { groupId } = req.params; const group = await Group.getGroup({ user, groupId, populateLeader: false }); - if (!group) { + if (!group || group.type === 'guild' && group._id !== TAVERN_ID && !group.hasActiveGroupPlan()) { throw new NotFound(res.t('groupNotFound')); } @@ -1337,7 +1338,7 @@ api.getGroupPlans = { async handler (req, res) { const { user } = res.locals; - const userGroups = user.getGroups(); + const userGroups = await user.getGroups(); const groups = await Group .find({ diff --git a/website/server/libs/challenges/index.js b/website/server/libs/challenges/index.js index 47a4b1b706..086db00264 100644 --- a/website/server/libs/challenges/index.js +++ b/website/server/libs/challenges/index.js @@ -41,6 +41,9 @@ export async function createChallenge (user, req, res) { }); if (!group) throw new NotFound(res.t('groupNotFound')); if (!group.isMember(user)) throw new NotAuthorized(res.t('mustBeGroupMember')); + if (group.type === 'guild' && group._id !== TAVERN_ID && !group.hasActiveGroupPlan()) { + throw new BadRequest(res.t('featureRetired')); + } if (group.leaderOnly && group.leaderOnly.challenges && group.leader !== user._id) { throw new NotAuthorized(res.t('onlyGroupLeaderChal')); diff --git a/website/server/models/user/methods.js b/website/server/models/user/methods.js index 6272c84b72..4885eeed7a 100644 --- a/website/server/models/user/methods.js +++ b/website/server/models/user/methods.js @@ -45,8 +45,11 @@ schema.methods.hasCancelled = function hasCancelled () { }; // Get an array of groups ids the user is member of -schema.methods.getGroups = function getUserGroups () { - const userGroups = this.guilds.slice(0); // clone this.guilds so we don't modify the original +schema.methods.getGroups = async function getUserGroups () { + const userGroups = await Group.getGroups({ + user: this, + types: ['party', 'guilds', 'tavern'], + }); if (this.party._id) userGroups.push(this.party._id); userGroups.push(TAVERN_ID); return userGroups; @@ -465,7 +468,7 @@ schema.methods.daysUserHasMissed = function daysUserHasMissed (now, req = {}) { }; async function getUserGroupData (user) { - const userGroups = user.getGroups(); + const userGroups = await user.getGroups(); const groups = await Group .find({