Skip to content

Commit

Permalink
Merge pull request #32 from parlemonde/fix/user_feedbacks
Browse files Browse the repository at this point in the history
fix user_feedbacks
  • Loading branch information
valentin-vrps authored Jun 24, 2024
2 parents 115a13b + b7f478b commit a1514a8
Show file tree
Hide file tree
Showing 37 changed files with 492 additions and 364 deletions.
90 changes: 44 additions & 46 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DKC = docker compose
DK = docker
.DEFAULT_GOAL = help

help:
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'

## —— Docker ———————————————————————————————————————————————————————————————————
up: ## start containers in the background
@$(DKC) up -d
run: ## start containers in attached mode
@$(DKC) up
down: ## stop containers
@$(DKC) down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
"qrcode": "^1.5.3",
"query-string": "^8.1.0",
"react": "^18.2.0",
"react-advanced-cropper": "^0.19.6",
"react-charts": "^2.0.0-beta.7",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-easy-crop": "^5.0.5",
"react-html5-camera-photo": "^1.5.11",
"react-qr-code": "^2.0.12",
"react-qr-reader": "^3.0.0-beta-1",
Expand Down
Binary file removed public/black.jpg
Binary file not shown.
2 changes: 2 additions & 0 deletions server/authentication/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export async function login(req: Request, res: Response): Promise<void> {
.execute();

const { accessToken, refreshToken } = await getAccessToken(user.id, !!data.getRefreshToken);
user.loginCount += 1;
await getRepository(User).save(user);
res.cookie('access-token', accessToken, {
maxAge: 4 * 60 * 60000,
expires: new Date(Date.now() + 4 * 60 * 60000),
Expand Down
4 changes: 4 additions & 0 deletions server/authentication/plmSSO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { JSONSchemaType } from 'ajv';
import type { NextFunction, Request, Response } from 'express';
import { getRepository } from 'typeorm';

import { User } from '../entities/user';
import { getUserFromPLM } from '../legacy-plm/api';
import { ajv, sendInvalidDataError } from '../lib/json-schema-validator';
import { AppError } from '../middlewares/handle-errors';
Expand Down Expand Up @@ -40,6 +42,8 @@ export async function loginWithPlmSSO(req: Request, res: Response, next: NextFun
throw new AppError('forbidden', ['Please use normal login'], 6);
}
const { accessToken, refreshToken } = await getAccessToken(user.id, true);
user.loginCount += 1;
await getRepository(User).save(user);
res.cookie('access-token', accessToken, {
maxAge: 4 * 60 * 60000,
expires: new Date(Date.now() + 4 * 60 * 60000),
Expand Down
39 changes: 38 additions & 1 deletion server/controllers/plans.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSONSchemaType } from 'ajv';
import { getRepository } from 'typeorm';
import { getManager, getRepository } from 'typeorm';

import { Plan } from '../entities/plan';
import { UserType } from '../entities/user';
Expand Down Expand Up @@ -79,6 +79,43 @@ planController.post({ path: '/', userType: UserType.CLASS }, async (req, res, ne
res.sendJSON(newPlan);
});

type PutPlanOrderData = {
order: number[];
};
const PUT_PLAN_ORDER_SCHEMA: JSONSchemaType<PutPlanOrderData> = {
type: 'object',
properties: {
order: {
type: 'array',
items: {
type: 'number',
},
},
},
required: ['order'],
additionalProperties: false,
};
const putPlanOrderValidator = ajv.compile(PUT_PLAN_ORDER_SCHEMA);
planController.put({ path: '/order', userType: UserType.CLASS }, async (req, res) => {
const data = req.body;
if (!putPlanOrderValidator(data)) {
sendInvalidDataError(putPlanOrderValidator);
return;
}

const plans: Plan[] = [];
for (let i = 0; i < data.order.length; i++) {
const plan = new Plan();
plan.id = data.order[i];
plan.index = i;
plans.push(plan);
}
await getManager().transaction(async (transactionalEntityManager) => {
await transactionalEntityManager.save(plans);
});
res.status(204).send();
});

type PutPlanData = {
description?: string;
index?: number;
Expand Down
10 changes: 8 additions & 2 deletions server/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ userController.get({ path: '' }, async (req, res) => {
}
if (req.query.order !== undefined || req.query.orderBy !== undefined) {
const orderBy = (req.query.order as string) || (req.query.orderBy as string);
if (orderBy === 'id' || orderBy === 'pseudo' || orderBy === 'email' || orderBy === 'level' || orderBy === 'school') {
if (
orderBy === 'id' ||
orderBy === 'pseudo' ||
orderBy === 'email' ||
orderBy === 'level' ||
orderBy === 'school' ||
orderBy === 'createDate'
) {
queryParams.order = {
[orderBy]: direction,
};
Expand All @@ -58,7 +65,6 @@ userController.get({ path: '' }, async (req, res) => {
{ pseudo: Like(`%${req.query.search}%`) },
{ email: Like(`%${req.query.search}%`) },
{ school: Like(`%${req.query.search}%`) },
{ level: Like(`%${req.query.search}%`) },
];
}
const users: User[] = await getRepository(User).find(queryParams);
Expand Down
8 changes: 7 additions & 1 deletion server/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';

import type { User as UserInterface } from '../../types/models/user.type';
import { UserType } from '../../types/models/user.type';
Expand All @@ -25,6 +25,9 @@ export class User implements UserInterface {
@Column({ default: 0 })
public accountRegistration: number; // 0 to 3 -> Ok, 4 -> Account blocked, 10 -> Account use PLM SSO

@Column({ default: 0 })
public loginCount: number;

@Column({ type: 'varchar', length: 180, select: false })
public passwordHash?: string;

Expand All @@ -39,4 +42,7 @@ export class User implements UserInterface {
type: UserType;

teacherId?: number | undefined;

@CreateDateColumn()
public createDate: string;
}
5 changes: 4 additions & 1 deletion server/translations/defaultLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const locales = {
small: "petit",
medium: "moyen",
big: "grand",
left: "gauche",
center: "centre",
right: "droite",
//--- part4 ---
part4_title: 'Prémontez votre <1>film</1>',
part4_subtitle1: 'Pour chaque séquence vous pouvez écrire et enregistrer une voix-off.',
Expand Down Expand Up @@ -114,7 +117,7 @@ export const locales = {
part6_mp4_user_disabled: 'Connectez-vous et créez un projet pour générer une vidéo.',
part6_mp4_project_disabled: 'Créez un projet pour générer une vidéo.',
part6_subtitle2:
'Vous pouvez également télécharger ce diaporama sonore comme film, télécharger le storyboard ainsi qu’un fichier de montage pour y intégrer vos plans vidéos.',
'Vous pouvez maintenant télécharger ce diaporama ou son fichier de montage pour y intégrer vos plans vidéos.',
//--- project ---
project: 'Projet :',
project_name: 'Nom du projet',
Expand Down
2 changes: 2 additions & 0 deletions server/utils/anonymous-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export const ANONYMOUS_USER: User = {
school: '',
type: UserType.STUDENT,
accountRegistration: 0,
loginCount: 0,
createDate: '',
};
6 changes: 3 additions & 3 deletions server/xml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ export function projectToMlt(allQuestions: Question[], project: Project, urlTran
size: fontSize,
weight: '500',
style: 'normal',
fgcolour: '#ffffffff',
bgcolour: '#00000000',
olcolour: '#aa000000',
fgcolour: '#000000',
bgcolour: '#ffffffff',
olcolour: '#ffffffff',
halign: 'center',
valign: 'middle',
mlt_service: 'dynamictext',
Expand Down
36 changes: 36 additions & 0 deletions src/api/plans/plans.order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { UseMutationOptions } from 'react-query';
import { useMutation, useQueryClient } from 'react-query';

import type { HttpRequestError } from 'src/utils/http-request';
import { httpRequest } from 'src/utils/http-request';

type PUTParams = {
order: number[];
};

export const reorderPlans = async (data: PUTParams): Promise<void> => {
const response = await httpRequest<void>({
method: 'PUT',
url: `/plans/order`,
data,
});
if (response.success) {
return;
} else {
throw response;
}
};

export const useReorderPlansMutation = (mutationOpts: Omit<UseMutationOptions<void, HttpRequestError, PUTParams>, 'mutationFn'> = {}) => {
const queryClient = useQueryClient();
return useMutation(reorderPlans, {
...mutationOpts,
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries('plans');
queryClient.invalidateQueries('plan');
if (mutationOpts.onSuccess !== undefined) {
mutationOpts.onSuccess(data, variables, context);
}
},
});
};
Loading

0 comments on commit a1514a8

Please sign in to comment.