From 0cfe0473b99e665a9a8527efec9cfacf094d8908 Mon Sep 17 00:00:00 2001 From: Alexander Colen Date: Mon, 17 Aug 2020 06:38:07 -0400 Subject: [PATCH] Remove Tavern from API v3 list of guilds when 'guild' or 'publicGuilds' type parameter get added. (Fixes #12407) (#12438) * Excluding tavern from showing up in GET /groups API when 'guilds' or 'publicGuilds' type parameter is included. * Fixed test errors. * Resolved pull request #12438 issues. Moved Tavern exclusion to Group model, removed Group controller back to the original and resolved test failures. --- .../v3/integration/groups/GET-groups.test.js | 19 +++++++++++++++---- website/server/models/group.js | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/api/v3/integration/groups/GET-groups.test.js b/test/api/v3/integration/groups/GET-groups.test.js index 3414ec795a..aaea5b397d 100644 --- a/test/api/v3/integration/groups/GET-groups.test.js +++ b/test/api/v3/integration/groups/GET-groups.test.js @@ -12,7 +12,7 @@ import apiError from '../../../../../website/server/libs/apiError'; describe('GET /groups', () => { let user; let userInGuild; - const NUMBER_OF_PUBLIC_GUILDS = 3; // 2 + the tavern + const NUMBER_OF_PUBLIC_GUILDS = 2; const NUMBER_OF_PUBLIC_GUILDS_USER_IS_LEADER = 2; const NUMBER_OF_PUBLIC_GUILDS_USER_IS_MEMBER = 1; const NUMBER_OF_USERS_PRIVATE_GUILDS = 1; @@ -236,11 +236,22 @@ describe('GET /groups', () => { await expect(user.get('/groups?type=publicGuilds&paginate=true&page=1')) .to.eventually.have.a.lengthOf(GUILD_PER_PAGE); const page2 = await expect(user.get('/groups?type=publicGuilds&paginate=true&page=2')) - .to.eventually.have.a.lengthOf(1 + 4); // 1 created now, 4 by other tests - expect(page2[4].name).to.equal('guild with less members'); + // 1 created now, 4 by other tests, -1 for no more tavern. + .to.eventually.have.a.lengthOf(1 + 4 - 1); + expect(page2[3].name).to.equal('guild with less members'); }).timeout(10000); }); + it('makes sure that the tavern doesn\'t show up when guilds is passed as a query', async () => { + const guilds = await user.get('/groups?type=guilds'); + expect(guilds.find(g => g.id === TAVERN_ID)).to.be.undefined; + }); + + it('makes sure that the tavern doesn\'t show up when publicGuilds is passed as a query', async () => { + const guilds = await user.get('/groups?type=publicGuilds'); + expect(guilds.find(g => g.id === TAVERN_ID)).to.be.undefined; + }); + it('returns all the user\'s guilds when guilds passed in as query', async () => { await expect(user.get('/groups?type=guilds')) .to.eventually.have.a @@ -254,7 +265,7 @@ describe('GET /groups', () => { it('returns a list of groups user has access to', async () => { await expect(user.get('/groups?type=privateGuilds,publicGuilds,party,tavern')) - .to.eventually.have.lengthOf(NUMBER_OF_GROUPS_USER_CAN_VIEW); + .to.eventually.have.lengthOf(NUMBER_OF_GROUPS_USER_CAN_VIEW - 1); // -1 for no Tavern. }); it('returns a list of groups user has access to', async () => { diff --git a/website/server/models/group.js b/website/server/models/group.js index 7d764c1fdb..4d3c4f13df 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -301,7 +301,7 @@ schema.statics.getGroups = async function getGroups (options = {}) { case 'guilds': { const query = { type: 'guild', - _id: { $in: user.guilds }, + _id: { $in: user.guilds, $ne: TAVERN_ID }, }; _.assign(query, filters); const userGuildsQuery = this.find(query).select(groupFields); @@ -330,6 +330,7 @@ schema.statics.getGroups = async function getGroups (options = {}) { const query = { type: 'guild', privacy: 'public', + _id: { $ne: TAVERN_ID }, }; _.assign(query, filters);