mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Prevent quest leaders from leaving party
(cherry picked from commit dc43aa5902)
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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?
|
||||||
|
|||||||
Reference in New Issue
Block a user