From 4f76344e4bf13a661f73058672ee94f5c1dfbe64 Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 13 Nov 2024 16:10:21 +0100 Subject: [PATCH] feat(VIL-622): adding access rights to archives to admin, s-admin and mediator fix: lint lint fix: staging build failed adding mediator account to test on staging restoring initial state after testing fixing ts errors revert changes to signatures --- server/controllers/archive.ts | 21 ++++++++++++--------- server/controllers/controller.ts | 2 +- src/api/archive/archive.get.ts | 22 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/server/controllers/archive.ts b/server/controllers/archive.ts index 0351e456f..0d08f3019 100644 --- a/server/controllers/archive.ts +++ b/server/controllers/archive.ts @@ -8,15 +8,18 @@ import { Controller } from './controller'; const archiveController = new Controller('/archives'); // get file -archiveController.get({ path: '/*', userType: UserType.ADMIN }, async (req: Request, res: Response, next: NextFunction) => { - const url = decodeURI(req.url); - const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`; - try { - streamFile(key, req, res, next); - } catch { - next(); - } -}); +archiveController.get( + { path: '/*', userType: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR] }, + async (req: Request, res: Response, next: NextFunction) => { + const url = decodeURI(req.url); + const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`; + try { + streamFile(key, req, res, next); + } catch { + next(); + } + }, +); /** * Liste les dossiers dans un préfixe S3 spécifié. diff --git a/server/controllers/controller.ts b/server/controllers/controller.ts index a86b6a164..a76171e27 100644 --- a/server/controllers/controller.ts +++ b/server/controllers/controller.ts @@ -11,7 +11,7 @@ import { diskStorage } from '../middlewares/multer'; type RouteOptions = { path: string; - userType?: UserType; + userType?: UserType | UserType[]; }; fs.ensureDir(path.join(__dirname, '../fileUpload/videos')).catch(); diff --git a/src/api/archive/archive.get.ts b/src/api/archive/archive.get.ts index e781cd039..07389117d 100644 --- a/src/api/archive/archive.get.ts +++ b/src/api/archive/archive.get.ts @@ -1,12 +1,26 @@ import axios from 'axios'; +import React from 'react'; import { useQuery } from 'react-query'; +import { UserType } from '../../../types/user.type'; +import { UserContext } from '../../contexts/userContext'; + const BASE_URL = '/api/archives'; // Récupérer la liste des années déjà archivées export const useListArchives = () => { - return useQuery(['archives'], async () => { - const { data } = await axios.get(`${BASE_URL}`); - return data; - }); + const { user } = React.useContext(UserContext); + + const hasAccess = user?.type === UserType.SUPER_ADMIN || user?.type === UserType.ADMIN || user?.type === UserType.MEDIATOR; + + return useQuery( + ['archives'], + async () => { + const { data } = await axios.get(`${BASE_URL}`); + return data; + }, + { + enabled: hasAccess, + }, + ); };