mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 02:02:19 +00:00
WIP. Accepting a redundant party invite will not remove the user from the party and let the user still be a part of it. Fixes #12291. (#12356)
* Getting the latest code * Temporary fix for Redundant Party Invite. Needs changes. * Added logic to check if the user is an existing member of the party that the user is invited to. * Added a test case for redundant party invite check. * Changed the test case for redundant party invite to see if it runs successfully. * Made changes to the test cases. * Fixed lint errors. * Removed the exclusive mocha test. * Referred the issue in the name of the new test case. * Modified test case to check its veracity. * Checking if the update statement is working or not.
This commit is contained in:
parent
616a0b7509
commit
a02c4c1cfd
2 changed files with 23 additions and 10 deletions
|
|
@ -203,6 +203,16 @@ describe('POST /group/:groupId/join', () => {
|
|||
await expect(invitedUser.get('/user')).to.eventually.have.nested.property('party._id', party._id);
|
||||
});
|
||||
|
||||
it('Issue #12291: accepting a redundant party invite will let the user stay in the party', async () => {
|
||||
await invitedUser.update({
|
||||
'party._id': party._id,
|
||||
});
|
||||
await expect(invitedUser.get('/user')).to.eventually.have.nested.property('party._id', party._id);
|
||||
await invitedUser.post(`/groups/${party._id}/join`);
|
||||
|
||||
await expect(invitedUser.get('/user')).to.eventually.have.nested.property('party._id', party._id);
|
||||
});
|
||||
|
||||
it('notifies inviting user that their invitation was accepted', async () => {
|
||||
await invitedUser.post(`/groups/${party._id}/join`);
|
||||
|
||||
|
|
|
|||
|
|
@ -544,20 +544,23 @@ api.joinGroup = {
|
|||
// Check if was invited to party
|
||||
const inviterParty = _.find(user.invitations.parties, { id: group._id });
|
||||
if (inviterParty) {
|
||||
inviter = inviterParty.inviter;
|
||||
// Check if the user is already a member of the party or not. Only make the user leave the
|
||||
// party if the user is not a member of the party. See #12291 for more details.
|
||||
if (user.party._id !== group._id) {
|
||||
inviter = inviterParty.inviter;
|
||||
|
||||
// If user was in a different party (when partying solo you can be invited to a new party)
|
||||
// make them leave that party before doing anything
|
||||
if (user.party._id) {
|
||||
const userPreviousParty = await Group.getGroup({ user, groupId: user.party._id });
|
||||
// If user was in a different party (when partying solo you can be invited to a new party)
|
||||
// make them leave that party before doing anything
|
||||
if (user.party._id) {
|
||||
const userPreviousParty = await Group.getGroup({ user, groupId: user.party._id });
|
||||
|
||||
if (userPreviousParty.memberCount === 1 && user.party.quest.key) {
|
||||
throw new NotAuthorized(res.t('messageCannotLeaveWhileQuesting'));
|
||||
if (userPreviousParty.memberCount === 1 && user.party.quest.key) {
|
||||
throw new NotAuthorized(res.t('messageCannotLeaveWhileQuesting'));
|
||||
}
|
||||
|
||||
if (userPreviousParty) await userPreviousParty.leave(user);
|
||||
}
|
||||
|
||||
if (userPreviousParty) await userPreviousParty.leave(user);
|
||||
}
|
||||
|
||||
// Clear all invitations of new user
|
||||
user.invitations.parties = [];
|
||||
user.invitations.party = {};
|
||||
|
|
|
|||
Loading…
Reference in a new issue