Skip to content

Commit

Permalink
Merge pull request #331 from Arquisoft/develop_samuel
Browse files Browse the repository at this point in the history
Fixed bug when displaying statistics and implemented conditional redirection on home
  • Loading branch information
uo288543 authored Apr 27, 2024
2 parents c0a2070 + 8896ea2 commit c3af4e2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
7 changes: 0 additions & 7 deletions users/__tests/routes/user-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,13 +1023,6 @@ describe('User Routes', () => {
.expect(403);

expect(responseWithoutLoggedUser.body).toHaveProperty('error');

const responseWithInvalidLoggedUser = await request(app)
.get('/user/statistics/testuser2')
.query({ loggedUser: 'testuser1' })
.expect(403);

expect(responseWithInvalidLoggedUser.body).toHaveProperty('error');
});

it('Should return the user when the username is valid when getting the profile', async () => {
Expand Down
14 changes: 8 additions & 6 deletions users/routes/user-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,14 @@ router.get('/statistics/:username', async (req,res) => {
}
});

const hasCommonGroup = userGroups.some(userGroup => {
return loggedUserGroups.some(loggedUserGroup => loggedUserGroup.groupName === userGroup.groupName);
});

if(!hasCommonGroup){
return res.status(403).json({ error: 'You are not allowed to see this user statistics' });
if (loggedUserGroups.length != 0 && userGroups != 0){
const hasCommonGroup = userGroups.some(userGroup => {
return loggedUserGroups.some(loggedUserGroup => loggedUserGroup.groupName === userGroup.groupName);
});

if(!hasCommonGroup){
return res.status(403).json({ error: 'You are not allowed to see this user statistics' });
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion users/services/user-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const QuestionsRecord = sequelize.define('QuestionsRecord', {
});

// Synchronize the model with the database
sequelize.sync()
sequelize.sync({force:true})
.then(() => {
console.log('Model synchronized successfully with the database');
})
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import {Box, Button, useTheme } from "@mui/material";
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTranslation } from 'react-i18next';
import AndroidIcon from '@mui/icons-material/Android';
import { SessionContext } from '../SessionContext';
import { useContext } from 'react';

const Home = () => {
const xxl = useMediaQuery('(min-width:1920px)');
const { t } = useTranslation();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const {username} = useContext(SessionContext) || {};

const redirectPath = username === '' ? "/login" : "/homepage";

const styles = {
logo:{
Expand Down Expand Up @@ -100,7 +105,7 @@ const Home = () => {
<img src="./home/HomeLogo.png" alt="Logo" style={{ width: '100%' }} />
</Box>

<Button variant='contained' href={"/login"} sx={styles.playButton}> {t("Home")} </Button>
<Button variant='contained' href={redirectPath} sx={styles.playButton}> {t("Home")} </Button>

<video data-testid="video" ref={videoRef} autoPlay muted loop style={{ ...styles.video}}>
<source src="./home/Background-White.webm" type="video/mp4" />
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/pages/games/TheChallengeGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const TheChallengeGame = () => {
<Typography fontWeight="bold" color="primary" fontSize="1.5em">
{numRounds}
</Typography>
<IconButton size="large" color="success" onClick={() => setNumRounds(numRounds + 1)} variant="outlined" data-testId="addRound">
<IconButton size="large" color="success" disabled={numRounds === 30} onClick={() => setNumRounds(numRounds + 1)} variant="outlined" data-testId="addRound">
<AddIcon fontSize="inherit" />
</IconButton>
</Box>
Expand All @@ -255,13 +255,13 @@ const TheChallengeGame = () => {
<Typography htmlFor="questionTime" variant="h5">
{t("Game.config.time")}:
</Typography>
<IconButton size="large" color="error" disabled={timerConfig === 1} onClick={() => setTimerConfig(timerConfig - 1)} variant="outlined" data-testId="removeSecond">
<IconButton size="large" color="error" disabled={timerConfig === 5} onClick={() => setTimerConfig(timerConfig - 1)} variant="outlined" data-testId="removeSecond">
<RemoveIcon fontSize="inherit" />
</IconButton>
<Typography fontWeight="bold" color="primary" fontSize="1.5em">
{timerConfig}
</Typography>
<IconButton size="large" color="success" onClick={() => setTimerConfig(timerConfig + 1)} variant="outlined" data-testId="addSecond">
<IconButton size="large" color="success" disabled={numRounds === 99} onClick={() => setTimerConfig(timerConfig + 1)} variant="outlined" data-testId="addSecond">
<AddIcon fontSize="inherit" />
</IconButton>
</Box>
Expand Down

0 comments on commit c3af4e2

Please sign in to comment.