Skip to content

Commit

Permalink
feat(VIL-622): adding access rights to archives to admin, s-admin and…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Lukasambry committed Nov 13, 2024
1 parent e274921 commit 4f76344
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
21 changes: 12 additions & 9 deletions server/controllers/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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é.
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 18 additions & 4 deletions src/api/archive/archive.get.ts
Original file line number Diff line number Diff line change
@@ -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,
},
);
};

0 comments on commit 4f76344

Please sign in to comment.