diff --git a/website/src/controllers/api-v3/groups.js b/website/src/controllers/api-v3/groups.js index 5866797d40..8a3ce9630b 100644 --- a/website/src/controllers/api-v3/groups.js +++ b/website/src/controllers/api-v3/groups.js @@ -221,7 +221,7 @@ api.joinGroup = { let validationErrors = req.validationErrors(); if (validationErrors) return next(validationErrors); - Group.getGroup(user, req.params.groupId, '-chat') // Do not fetch chat + Group.getGroup(user, req.params.groupId, '-chat', true) // Do not fetch chat and work even if the user is not yet a member of the group .then(group => { if (!group) throw new NotFound(res.t('groupNotFound')); diff --git a/website/src/libs/api-v3/pushNotifications.js b/website/src/libs/api-v3/pushNotifications.js index 1db4c740bd..fbf5e2666a 100644 --- a/website/src/libs/api-v3/pushNotifications.js +++ b/website/src/libs/api-v3/pushNotifications.js @@ -24,6 +24,7 @@ if (gcm) { }); } +// TODO test export default function sendNotify (user, title, message, timeToLive = 15) { // TODO need investigation: // https://github.com/HabitRPG/habitrpg/issues/5252 diff --git a/website/src/models/group.js b/website/src/models/group.js index 95f5a82b94..f425a6a667 100644 --- a/website/src/models/group.js +++ b/website/src/models/group.js @@ -126,10 +126,13 @@ schema.post('remove', function postRemoveGroup (group) { }); // TODO populate (invites too), isMember? -schema.statics.getGroup = function getGroup (user, groupId, fields) { +schema.statics.getGroup = function getGroup (user, groupId, fields, optionalMembership) { let query; - if (groupId === 'party' || user.party._id === groupId) { + // When optionalMembership is true it's not required for the user to be a member of the group + if (optionalMembership === true) { + query = {_id: groupId}; + } else if (groupId === 'party' || user.party._id === groupId) { query = {type: 'party', _id: user.party._id}; } else if (user.guilds.indexOf(groupId) !== -1) { query = {type: 'guild', _id: groupId}; @@ -137,12 +140,10 @@ schema.statics.getGroup = function getGroup (user, groupId, fields) { query = {type: 'guild', privacy: 'public', _id: groupId}; } - return this - .findOne(query) - .select(fields) - .exec(); // TODO catch errors here? - - // TODO purge chat flags info? in tojson? + let mQuery = this.findOne(query); + if (fields) mQuery.select(fields); + return mQuery.exec(); // TODO catch errors here? + // TODO purge chat flags info? in tojson? }; // TODO move to its own model