mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Challenge privacy fix (#11222)
* fix(challenges): filter out private content API-side * fix(challenges): cleaner fix + test
This commit is contained in:
@@ -171,7 +171,7 @@ describe('GET challenges/user', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return not return challenges in user groups if we send member true param', async () => {
|
it('should not return challenges in user groups if we send member true param', async () => {
|
||||||
let challenges = await member.get(`/challenges/user?member=${true}`);
|
let challenges = await member.get(`/challenges/user?member=${true}`);
|
||||||
|
|
||||||
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
|
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
|
||||||
@@ -214,6 +214,28 @@ describe('GET challenges/user', () => {
|
|||||||
let foundChallenge = _.find(challenges, { _id: privateChallenge._id });
|
let foundChallenge = _.find(challenges, { _id: privateChallenge._id });
|
||||||
expect(foundChallenge).to.not.exist;
|
expect(foundChallenge).to.not.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return challenges user doesn\'t have access to, even with query parameters', async () => {
|
||||||
|
let { group, groupLeader } = await createAndPopulateGroup({
|
||||||
|
groupDetails: {
|
||||||
|
name: 'TestPrivateGuild',
|
||||||
|
summary: 'summary for TestPrivateGuild',
|
||||||
|
type: 'guild',
|
||||||
|
privacy: 'private',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let privateChallenge = await generateChallenge(groupLeader, group, {categories: [{
|
||||||
|
name: 'academics',
|
||||||
|
slug: 'academics',
|
||||||
|
}]});
|
||||||
|
await groupLeader.post(`/challenges/${privateChallenge._id}/join`);
|
||||||
|
|
||||||
|
let challenges = await nonMember.get('/challenges/user?categories=academics&owned=not_owned');
|
||||||
|
|
||||||
|
let foundChallenge = _.find(challenges, { _id: privateChallenge._id });
|
||||||
|
expect(foundChallenge).to.not.exist;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('official challenge is present', () => {
|
context('official challenge is present', () => {
|
||||||
|
|||||||
@@ -366,11 +366,11 @@ api.getUserChallenges = {
|
|||||||
|
|
||||||
if (owned) {
|
if (owned) {
|
||||||
if (owned === 'not_owned') {
|
if (owned === 'not_owned') {
|
||||||
query.$and = [{leader: {$ne: user._id}}];
|
query.$and.push({leader: {$ne: user._id}});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owned === 'owned') {
|
if (owned === 'owned') {
|
||||||
query.$and = [{leader: user._id}];
|
query.$and.push({leader: user._id});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user