diff --git a/app/(header-default)/dirigeants/_component/sections/index.tsx b/app/(header-default)/dirigeants/_component/sections/index.tsx index 6ab6f9994..e5167882b 100644 --- a/app/(header-default)/dirigeants/_component/sections/index.tsx +++ b/app/(header-default)/dirigeants/_component/sections/index.tsx @@ -3,7 +3,7 @@ import { DonneesPriveesSection } from '#components/donnees-privees-section'; import { estDiffusible } from '#models/core/statut-diffusion'; import { IUniteLegale } from '#models/core/types'; import { getMandatairesRCS } from '#models/espace-agent/mandataires-rcs'; -import getImmatriculationRNE from '#models/immatriculation/rne'; +import { getImmatriculationRNE } from '#models/immatriculation/rne'; import { EScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import BeneficiairesSection from './beneficiaires'; diff --git a/app/(header-default)/justificatif/[slug]/_components/index.tsx b/app/(header-default)/justificatif/[slug]/_components/index.tsx index 717f863c7..a1d84fa10 100644 --- a/app/(header-default)/justificatif/[slug]/_components/index.tsx +++ b/app/(header-default)/justificatif/[slug]/_components/index.tsx @@ -1,5 +1,5 @@ import { IUniteLegale } from '#models/core/types'; -import getImmatriculationRNE from '#models/immatriculation/rne'; +import { getImmatriculationRNE } from '#models/immatriculation/rne'; import { ISession } from '#models/user/session'; import { IJustificatifs, ImmatriculationsSection } from './container'; diff --git a/app/api/data-fetching/espace-agent/_helper/index.ts b/app/api/data-fetching/espace-agent/_helper/index.ts deleted file mode 100644 index 137eda437..000000000 --- a/app/api/data-fetching/espace-agent/_helper/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { HttpForbiddenError } from '#clients/exceptions'; -import { EAdministration } from '#models/administrations/EAdministration'; -import { FetchRessourceException } from '#models/exceptions'; -import { EScope, hasRights } from '#models/user/rights'; -import { logFatalErrorInSentry } from '#utils/sentry'; -import getSession from '#utils/server-side-helper/app/get-session'; - -export async function ProtectedAPIRoute( - routeLabel: string, - slug: string, - administration: EAdministration, - scope: EScope, - run: (agentSiret: string) => Promise -) { - const session = await getSession(); - try { - if (!hasRights(session, scope)) { - throw new HttpForbiddenError('Unauthorized account'); - } - - const agentSiret = session?.user?.siret || 'Inconnu'; - - const data = await run(agentSiret); - return Response.json(data, { status: 200 }); - } catch (e: any) { - const message = `Failed to get donnees ${routeLabel}`; - logFatalErrorInSentry( - new FetchRessourceException({ - ressource: routeLabel, - context: { slug }, - cause: e, - message, - administration, - }) - ); - return Response.json({ message }, { status: e.status || 500 }); - } -} diff --git a/app/api/data-fetching/espace-agent/documents/[slug]/route.ts b/app/api/data-fetching/espace-agent/documents/[slug]/route.ts deleted file mode 100644 index 72e1d2654..000000000 --- a/app/api/data-fetching/espace-agent/documents/[slug]/route.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { clientDocuments } from '#clients/api-proxy/rne/documents'; -import { EAdministration } from '#models/administrations/EAdministration'; -import { EScope } from '#models/user/rights'; -import { verifySiren } from '#utils/helpers'; -import { ProtectedAPIRoute } from '../../_helper'; - -export async function GET( - _request: Request, - { params }: { params: { slug: string } } -) { - const slug = params.slug; - return ProtectedAPIRoute( - 'RNEDocuments', - slug, - EAdministration.INPI, - EScope.documentsRne, - async () => { - const siren = verifySiren(slug as string); - - const actes = await clientDocuments(siren); - actes.hasBilanConsolide = - actes.bilans.filter((b) => b.typeBilan === 'K').length > 0; - return actes; - } - ); -} diff --git a/clients/routes.ts b/clients/routes.ts index 68218d861..daa38f5fa 100644 --- a/clients/routes.ts +++ b/clients/routes.ts @@ -2,7 +2,6 @@ const routes = { api: { rne: { documents: { - list: '/api/data-fetching/espace-agent/documents/', download: '/api/download/espace-agent/documents/', }, }, diff --git a/components/espace-agent-components/documents/actes-walled.tsx b/components/espace-agent-components/documents/actes-walled.tsx index 7c16dc047..52611a138 100644 --- a/components/espace-agent-components/documents/actes-walled.tsx +++ b/components/espace-agent-components/documents/actes-walled.tsx @@ -1,4 +1,5 @@ import { IUniteLegale } from '#models/core/types'; +import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; import { EScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import AgentWallDocuments from '../agent-wall/document'; @@ -7,16 +8,18 @@ import { AgentActesSection } from './data-section/actes'; const ActesSection: React.FC<{ uniteLegale: IUniteLegale; session: ISession | null; -}> = ({ uniteLegale, session }) => - !hasRights(session, EScope.actesRne) ? ( - - ) : ( - - ); - +}> = async ({ uniteLegale, session }) => { + if (!hasRights(session, EScope.actesRne)) { + return ( + + ); + } + const documents = getDocumentsRNEProtected(uniteLegale.siren); + return ; +}; export default ActesSection; diff --git a/components/espace-agent-components/documents/bilans-walled.tsx b/components/espace-agent-components/documents/bilans-walled.tsx index 362fbbb24..cd91210f7 100644 --- a/components/espace-agent-components/documents/bilans-walled.tsx +++ b/components/espace-agent-components/documents/bilans-walled.tsx @@ -1,4 +1,5 @@ import { IUniteLegale } from '#models/core/types'; +import { getDocumentsRNEProtected } from '#models/immatriculation/rne'; import { EScope, hasRights } from '#models/user/rights'; import { ISession } from '#models/user/session'; import AgentWallDocuments from '../agent-wall/document'; @@ -7,16 +8,19 @@ import AgentBilansSection from './data-section/bilans'; const BilansSection: React.FC<{ uniteLegale: IUniteLegale; session: ISession | null; -}> = ({ uniteLegale, session }) => - !hasRights(session, EScope.bilansRne) ? ( - - ) : ( - - ); +}> = async ({ uniteLegale, session }) => { + if (!hasRights(session, EScope.bilansRne)) { + return ( + + ); + } + const documents = getDocumentsRNEProtected(uniteLegale.siren); + return ; +}; export default BilansSection; diff --git a/components/espace-agent-components/documents/data-section/actes.tsx b/components/espace-agent-components/documents/data-section/actes.tsx index 48e725daf..563da177a 100644 --- a/components/espace-agent-components/documents/data-section/actes.tsx +++ b/components/espace-agent-components/documents/data-section/actes.tsx @@ -5,9 +5,10 @@ import { Warning } from '#components-ui/alerts'; import ButtonLink from '#components-ui/button'; import { PrintNever } from '#components-ui/print-visibility'; import ShowMore from '#components-ui/show-more'; -import { AsyncDataSectionClient } from '#components/section/data-section/client'; +import { AsyncDataSectionServer } from '#components/section/data-section/server'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; +import { IAPINotRespondingError } from '#models/api-not-responding'; import { IUniteLegale, isAssociation, @@ -15,7 +16,6 @@ import { } from '#models/core/types'; import { IActesRNE } from '#models/immatriculation'; import { formatDateLong } from '#utils/helpers'; -import useFetchActesRNE from 'hooks/fetch/actes-RNE'; const NoDocument = () => ( <>Aucun document n’a été retrouvé dans le RNE pour cette entreprise. @@ -23,12 +23,11 @@ const NoDocument = () => ( export const AgentActesSection: React.FC<{ uniteLegale: IUniteLegale; -}> = ({ uniteLegale }) => { - const documents = useFetchActesRNE(uniteLegale); - + documents: Promise; +}> = ({ uniteLegale, documents }) => { return ( - ) } - + ); }; diff --git a/components/espace-agent-components/documents/data-section/bilans.tsx b/components/espace-agent-components/documents/data-section/bilans.tsx index 4bb899923..6b29ad78d 100644 --- a/components/espace-agent-components/documents/data-section/bilans.tsx +++ b/components/espace-agent-components/documents/data-section/bilans.tsx @@ -6,17 +6,18 @@ import ButtonLink from '#components-ui/button'; import FAQLink from '#components-ui/faq-link'; import { PrintNever } from '#components-ui/print-visibility'; import { Tag } from '#components-ui/tag'; -import { AsyncDataSectionClient } from '#components/section/data-section/client'; +import { AsyncDataSectionServer } from '#components/section/data-section/server'; import { FullTable } from '#components/table/full'; import { EAdministration } from '#models/administrations/EAdministration'; +import { IAPINotRespondingError } from '#models/api-not-responding'; import { IUniteLegale, isAssociation, isServicePublic, } from '#models/core/types'; +import { IActesRNE } from '#models/immatriculation'; import { formatDateLong } from '#utils/helpers'; import { getFiscalYear } from '#utils/helpers/formatting/format-fiscal-year'; -import useFetchActesRNE from 'hooks/fetch/actes-RNE'; const NoBilans = () => ( <>Aucun comptes n’a été déposé au RNE pour cette entreprise. @@ -24,12 +25,11 @@ const NoBilans = () => ( const AgentBilansSection: React.FC<{ uniteLegale: IUniteLegale; -}> = ({ uniteLegale }) => { - const documents = useFetchActesRNE(uniteLegale); - + documents: Promise; +}> = ({ uniteLegale, documents }) => { return ( - ) } - + ); }; diff --git a/cypress/e2e/data-fetching.cy.js b/cypress/e2e/data-fetching.cy.js index 588a00c6f..a3e248fc7 100644 --- a/cypress/e2e/data-fetching.cy.js +++ b/cypress/e2e/data-fetching.cy.js @@ -1,12 +1,5 @@ describe('Data fetching routes', () => { it('Agent-only routes are forbidden', () => { - cy.request({ - url: '/api/data-fetching/espace-agent/documents/552032534', - failOnStatusCode: false, - }).then((resp) => { - expect(resp.status).to.eq(403); - }); - cy.request({ url: '/api/download/espace-agent/documents/552032534', failOnStatusCode: false, diff --git a/hooks/fetch/actes-RNE.ts b/hooks/fetch/actes-RNE.ts deleted file mode 100644 index 9c78bd78f..000000000 --- a/hooks/fetch/actes-RNE.ts +++ /dev/null @@ -1,34 +0,0 @@ -import routes from '#clients/routes'; -import { EAdministration } from '#models/administrations/EAdministration'; -import { FetchRessourceException } from '#models/exceptions'; -import { IActesRNE } from '#models/immatriculation'; -import { IUniteLegale } from '#models/core/types'; -import { httpGet } from '#utils/network'; -import logErrorInSentry from '#utils/sentry'; -import { useFetchData } from './use-fetch-data'; - -export function useFetchActesRNE(uniteLegale: IUniteLegale) { - const { siren } = uniteLegale; - return useFetchData( - { - fetchData: () => - httpGet(routes.api.rne.documents.list + siren), - administration: EAdministration.INPI, - logError: (e: any) => { - if (e.status) { - return; - } - logErrorInSentry( - new FetchRessourceException({ - ressource: 'ActesRNE', - administration: EAdministration.INPI, - cause: e, - }) - ); - }, - }, - [siren] - ); -} - -export default useFetchActesRNE; diff --git a/models/espace-agent/conformite.ts b/models/espace-agent/conformite.ts index 3aec15620..91297770c 100644 --- a/models/espace-agent/conformite.ts +++ b/models/espace-agent/conformite.ts @@ -22,6 +22,8 @@ export const getConformiteEntreprise = async ( siret: Siret, recipientSiret?: string ): Promise => { + await new Promise((resolve) => setTimeout(resolve, 20000)); + const [fiscale, vigilance, msa] = await Promise.all([ clientApiEntrepriseConformiteFiscale(siren, recipientSiret).catch((error) => handleApiEntrepriseError(error, { siren, siret }) diff --git a/models/immatriculation/rne.ts b/models/immatriculation/rne.ts index db170994e..e1d3f51eb 100644 --- a/models/immatriculation/rne.ts +++ b/models/immatriculation/rne.ts @@ -1,4 +1,5 @@ import { fetchRNEImmatriculation } from '#clients/api-proxy/rne'; +import { clientDocuments } from '#clients/api-proxy/rne/documents'; import { HttpNotFound } from '#clients/exceptions'; import routes from '#clients/routes'; import { EAdministration } from '#models/administrations/EAdministration'; @@ -13,7 +14,7 @@ import { IImmatriculationRNE } from '.'; * Request Immatriculation from INPI's RNE * @param siren */ -const getImmatriculationRNE = async ( +export const getImmatriculationRNE = async ( siren: Siren ): Promise => { try { @@ -47,4 +48,19 @@ const getImmatriculationRNE = async ( } }; -export default getImmatriculationRNE; +export async function getDocumentsRNEProtected(siren: Siren) { + try { + const actes = await clientDocuments(siren); + actes.hasBilanConsolide = + actes.bilans.filter((b) => b.typeBilan === 'K').length > 0; + return actes; + } catch (e: any) { + if (e instanceof HttpNotFound) { + return APINotRespondingFactory(EAdministration.INPI, 404); + } + + // no need to log an error as API-Proxy already logged it + + return APINotRespondingFactory(EAdministration.INPI, 500); + } +}