Prevent quest leaders from leaving party

(cherry picked from commit dc43aa5902)
This commit is contained in:
Blade Barringer
2015-09-08 19:24:26 -05:00
parent f8850755d0
commit 9abe67b0ad
2 changed files with 21 additions and 2 deletions

View File

@@ -197,6 +197,19 @@ describe('Groups Controller', function() {
expect(res.json).to.be.calledWith(403, 'You cannot leave party during an active quest. Please leave the quest first'); expect(res.json).to.be.calledWith(403, 'You cannot leave party during an active quest. Please leave the quest first');
}); });
it('prevents quest leader from leaving a party if they have started a quest', function() {
group.quest = {
active: false,
leader: 'user-id'
};
groupsController.leave(req, res);
expect(group.leave).to.not.be.called;
expect(res.json).to.be.calledOnce;
expect(res.json).to.be.calledWith(403, 'You cannot leave when you have started a quest. Abort the quest first.');
});
it('leaves party if quest is not active', function() { it('leaves party if quest is not active', function() {
group.quest = { group.quest = {
active: false, active: false,

View File

@@ -505,8 +505,14 @@ api.leave = function(req, res, next) {
var user = res.locals.user; var user = res.locals.user;
var group = res.locals.group; var group = res.locals.group;
if (group.type === 'party' && group.quest && group.quest.active && group.quest.members && group.quest.members[user._id]) { if (group.type === 'party') {
return res.json(403, 'You cannot leave party during an active quest. Please leave the quest first'); if (group.quest && group.quest.leader === user._id) {
return res.json(403, 'You cannot leave party when you have started a quest. Abort the quest first.');
}
if (group.quest && group.quest.active && group.quest.members && group.quest.members[user._id]) {
return res.json(403, 'You cannot leave party during an active quest. Please leave the quest first');
}
} }
// When removing the user from challenges, should we keep the tasks? // When removing the user from challenges, should we keep the tasks?