Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug when displaying statistics and implemented conditional redirection on home #329

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2,10 +2,15 @@ import * as React from "react";
import {Box, Button} from "@mui/material";
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTranslation } from 'react-i18next';
import { SessionContext } from '../SessionContext';
import { useContext } from 'react';

const Home = () => {
const xxl = useMediaQuery('(min-width:1920px)');
const { t } = useTranslation();
const {username} = useContext(SessionContext) || {};

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

const styles = {
logo:{
Expand Down Expand Up @@ -97,7 +102,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
Loading