Skip to content

Commit

Permalink
fix: login (#148)
Browse files Browse the repository at this point in the history
* fix: login

* fix: login

* fix: seed

* fix: login/pdf

* fix: add more fixes
  • Loading branch information
DevNono authored Oct 5, 2023
1 parent a8e1841 commit a1c41b6
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ INSERT INTO `settings` (`id`, `value`) VALUES

INSERT INTO `tournaments` (`id`, `name`, `maxPlayers`, `playersPerTeam`, `cashprize`) VALUES
('lol', 'League of Legends', 160, 5, 0),
('ssbu', 'SSBU', 64, 1, 0),
('csgo', 'Counter-Strike : Global Offensive', 80, 5, 0),
('ssbu', 'Super Smash Bros. Ultimate', 64, 1, 0),
('cs2', 'Counter-Strike 2', 80, 5, 0),
('rl', 'Rocket League', 60, 3, 0),
('osu', 'Osu!', 64, 1, 0),
('tft', 'Teamfight Tactics', 32, 1, 0),
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const isLoginAllowed = async (request: Request, response: Response, next:
if (
login ||
(user && user.permissions && user.permissions.length > 0) ||
request.originalUrl === '/admin/auth/login'
request.originalUrl === '/admin/auth/login' ||
request.route.path === '/admin/auth/login'
) {
return next();
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export const enum Error {
IsOrga = "L'utilisateur est un organisateur",
TeamNotPaid = "Tous les membres de l'équipe n'ont pas payé",
LoginNotAllowed = 'Tu ne peux pas te connecter actuellement',
NotAdmin = "Tu n'es pas administrateur",
ShopNotAllowed = 'La billetterie est fermée',
EmailNotConfirmed = "Le compte n'est pas confirmé",
NoPermission = "Tu n'as pas la permission d'accéder à cette ressource",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function loginAccount(request: Request, response: Response, next: N

// If admin check that the user has any permissions
if (admin && (!user.permissions || user.permissions.length === 0)) {
return forbidden(response, ResponseError.LoginNotAllowed);
return forbidden(response, ResponseError.NotAdmin);
}

const token = generateToken(user);
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/auth/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('POST /admin/auth/login', () => {
login: user.email,
password,
})
.expect(403, { error: Error.LoginNotAllowed });
.expect(403, { error: Error.NotAdmin });
await database.user.update({
where: {
id: user.id,
Expand Down
10 changes: 5 additions & 5 deletions tests/admin/emails/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('POST /admin/emails', () => {

before(async () => {
admin = await createFakeUser({ type: UserType.orga, permissions: [Permission.admin] });
await createFakeTeam({ members: 4, tournament: 'csgo' });
await createFakeTeam({ members: 4, tournament: 'cs2' });
await createFakeTeam({ members: 2, tournament: 'lol' });
[nonAdminUser] = (await createFakeTeam({ members: 5, tournament: 'csgo', locked: true })).players;
[nonAdminUser] = (await createFakeTeam({ members: 5, tournament: 'cs2', locked: true })).players;
adminToken = generateToken(admin);
});

Expand Down Expand Up @@ -163,7 +163,7 @@ describe('POST /admin/emails', () => {
request(app)
.post(`/admin/emails`)
.send({
tournamentId: 'csgo',
tournamentId: 'cs2',
...validMailBody,
})
.set('Authorization', `Bearer ${adminToken}`)
Expand All @@ -173,7 +173,7 @@ describe('POST /admin/emails', () => {
request(app)
.post(`/admin/emails`)
.send({
tournamentId: 'csgo',
tournamentId: 'cs2',
locked: true,
...validMailBody,
})
Expand All @@ -184,7 +184,7 @@ describe('POST /admin/emails', () => {
request(app)
.post(`/admin/emails`)
.send({
tournamentId: 'csgo',
tournamentId: 'cs2',
locked: false,
...validMailBody,
})
Expand Down
6 changes: 3 additions & 3 deletions tests/discord/syncRoles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('POST /discord/sync-roles', () => {
locked: true,
paid: true,
members: 5,
tournament: 'csgo',
tournament: 'cs2',
});
// We will test with one missing user (he may have left the server)
for (const user of [...team.players.slice(1), ...team.coaches]) registerMember(user.discordId);
Expand All @@ -27,13 +27,13 @@ describe('POST /discord/sync-roles', () => {
const team2 = await createFakeTeam({
locked: false,
members: 2,
tournament: 'csgo',
tournament: 'cs2',
});
registerMember(team2.players[0].discordId);

await database.tournament.update({
where: {
id: 'csgo',
id: 'cs2',
},
data: {
discordRoleId: registerRole(),
Expand Down
4 changes: 2 additions & 2 deletions tests/teams/createTeam.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ describe('POST /teams', () => {

const { body } = await request(app)
.post('/teams')
.send({ ...teamBody, tournamentId: 'csgo' })
.send({ ...teamBody, tournamentId: 'cs2' })
.set('Authorization', `Bearer ${newToken}`)
.expect(201);

expect(body.name).to.be.equal(teamBody.name);
expect(body.tournamentId).to.be.equal('csgo');
expect(body.tournamentId).to.be.equal('cs2');
expect(body.captainId).to.be.equal(newUser.id);
const remoteUser = await userOperations.fetchUser(body.captainId);
expect(remoteUser.type).to.be.equal(teamBody.userType);
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/pdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Tests the PDF utils', () => {
});

let placeId = 0;
for (const tournamentId of ['lol', 'ssbu', 'csgo', 'rl', 'osu', 'tft', 'open', 'pokemon']) {
for (const tournamentId of ['lol', 'ssbu', 'cs2', 'rl', 'osu', 'tft', 'open', 'pokemon']) {
it(`should generate a PDF ticket for ${tournamentId}`, async () => {
// Create a fake user and add it in a random team
const team = await createFakeTeam({ tournament: tournamentId as string });
Expand Down

0 comments on commit a1c41b6

Please sign in to comment.