chore: activer ESLint sur le backend
Installe eslint, ajoute le script lint, modernise le parser (retrait de babel-eslint obsolète) et applique l'autofix (points-virgules manquants sur l'ensemble du code, conformément à la règle "semi" déjà présente dans .eslintrc mais jamais appliquée faute d'ESLint installé et d'un script pour l'exécuter).
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const { UnauthorizedError, NotFoundError } = require('@strapi/utils').errors
|
||||
const { UnauthorizedError, NotFoundError } = require('@strapi/utils').errors;
|
||||
|
||||
module.exports = async (policyContext, config, {strapi}) => {
|
||||
const {request, params} = policyContext
|
||||
const {request, params} = policyContext;
|
||||
|
||||
if (!request?.header?.authorization) {
|
||||
throw new UnauthorizedError('Opération non autorisée')
|
||||
throw new UnauthorizedError('Opération non autorisée');
|
||||
}
|
||||
|
||||
let jwtUserId
|
||||
let jwtUserId;
|
||||
try {
|
||||
({id: jwtUserId} = await strapi.plugins['users-permissions'].services.jwt.getToken(policyContext))
|
||||
({id: jwtUserId} = await strapi.plugins['users-permissions'].services.jwt.getToken(policyContext));
|
||||
} catch (err) {
|
||||
throw new UnauthorizedError('Opération non autorisée')
|
||||
throw new UnauthorizedError('Opération non autorisée');
|
||||
}
|
||||
|
||||
const documentId = params?.id ?? request.body?.data?.documentId
|
||||
const documentId = params?.id ?? request.body?.data?.documentId;
|
||||
|
||||
const document = await strapi.db.query(config.uid).findOne({
|
||||
where: {documentId},
|
||||
populate: {user: true}
|
||||
})
|
||||
});
|
||||
|
||||
if (!document) {
|
||||
throw new NotFoundError('Ressource introuvable.')
|
||||
throw new NotFoundError('Ressource introuvable.');
|
||||
}
|
||||
|
||||
if (document.user?.id !== jwtUserId) {
|
||||
throw new UnauthorizedError('Opération non autorisée')
|
||||
throw new UnauthorizedError('Opération non autorisée');
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user