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.
This commit is contained in:
Alexander Colen
2020-08-17 06:38:07 -04:00
committed by GitHub
parent 10f89c8d79
commit 0cfe0473b9
2 changed files with 17 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ import apiError from '../../../../../website/server/libs/apiError';
describe('GET /groups', () => { describe('GET /groups', () => {
let user; let user;
let userInGuild; 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_LEADER = 2;
const NUMBER_OF_PUBLIC_GUILDS_USER_IS_MEMBER = 1; const NUMBER_OF_PUBLIC_GUILDS_USER_IS_MEMBER = 1;
const NUMBER_OF_USERS_PRIVATE_GUILDS = 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')) await expect(user.get('/groups?type=publicGuilds&paginate=true&page=1'))
.to.eventually.have.a.lengthOf(GUILD_PER_PAGE); .to.eventually.have.a.lengthOf(GUILD_PER_PAGE);
const page2 = await expect(user.get('/groups?type=publicGuilds&paginate=true&page=2')) 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 // 1 created now, 4 by other tests, -1 for no more tavern.
expect(page2[4].name).to.equal('guild with less members'); .to.eventually.have.a.lengthOf(1 + 4 - 1);
expect(page2[3].name).to.equal('guild with less members');
}).timeout(10000); }).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 () => { it('returns all the user\'s guilds when guilds passed in as query', async () => {
await expect(user.get('/groups?type=guilds')) await expect(user.get('/groups?type=guilds'))
.to.eventually.have.a .to.eventually.have.a
@@ -254,7 +265,7 @@ describe('GET /groups', () => {
it('returns a list of groups user has access to', async () => { it('returns a list of groups user has access to', async () => {
await expect(user.get('/groups?type=privateGuilds,publicGuilds,party,tavern')) 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 () => { it('returns a list of groups user has access to', async () => {

View File

@@ -301,7 +301,7 @@ schema.statics.getGroups = async function getGroups (options = {}) {
case 'guilds': { case 'guilds': {
const query = { const query = {
type: 'guild', type: 'guild',
_id: { $in: user.guilds }, _id: { $in: user.guilds, $ne: TAVERN_ID },
}; };
_.assign(query, filters); _.assign(query, filters);
const userGuildsQuery = this.find(query).select(groupFields); const userGuildsQuery = this.find(query).select(groupFields);
@@ -330,6 +330,7 @@ schema.statics.getGroups = async function getGroups (options = {}) {
const query = { const query = {
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'public',
_id: { $ne: TAVERN_ID },
}; };
_.assign(query, filters); _.assign(query, filters);