Skip to content

Commit

Permalink
feat: wip simplification écrans mes effectifs + paramètres
Browse files Browse the repository at this point in the history
feat: configuration ERP v2

feat: wip configuration v3

feat: enregistrement ERP non supporté

feat: sauvegarde l'auteur de la configuration ERP

feat: redirection apiv3 ok
  • Loading branch information
totakoko committed Oct 5, 2023
1 parent 5bd42c9 commit 7082b65
Show file tree
Hide file tree
Showing 34 changed files with 1,124 additions and 288 deletions.
54 changes: 45 additions & 9 deletions server/src/common/actions/organismes/organismes.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,46 @@ export async function configureOrganismeERP(
if (!(await canConfigureOrganismeERP(ctx, organismeId))) {
throw Boom.forbidden("Permissions invalides");
}
if (conf.mode_de_transmission === null) {
await organismesDb().updateOne(
{ _id: new ObjectId(organismeId) },
{
$unset: { mode_de_transmission: "" },
}
);
await organismesDb().updateOne(
{ _id: new ObjectId(organismeId) },
{
$set: {
mode_de_transmission: conf.mode_de_transmission,
erps: conf.erps ?? [],
...(conf.erp_unsupported ? { erp_unsupported: conf.erp_unsupported } : {}),
mode_de_transmission_configuration_date: new Date(),
mode_de_transmission_configuration_author_fullname: `${ctx.prenom} ${ctx.nom}`,
},
$unset: conf.erp_unsupported
? {}
: {
erp_unsupported: 1,
},
}
);
}

export async function resetConfigurationERP(ctx: AuthContext, organismeId: ObjectId): Promise<void> {
if (!(await canConfigureOrganismeERP(ctx, organismeId))) {
throw Boom.forbidden("Permissions invalides");
}
await organismesDb().updateOne({ _id: new ObjectId(organismeId) }, { $set: stripEmptyFields(conf) as any });
await organismesDb().updateOne(
{ _id: new ObjectId(organismeId) },
{
$unset: {
mode_de_transmission: 1,
mode_de_transmission_configuration_date: 1,
erp_unsupported: 1,
api_configuration_date: 1,
api_siret: 1,
api_uai: 1,
// pas besoin de réinitialiser api_key
},
$set: {
erps: [],
},
}
);
}

export async function verifyOrganismeAPIKeyToUser(
Expand Down Expand Up @@ -813,10 +844,12 @@ export function getOrganismeProjection(
organismesFormateurs: 1,
fiabilisation_statut: 1,
erps: permissionsOrganisme.infoTransmissionEffectifs,
erp_unsupported: permissionsOrganisme.infoTransmissionEffectifs,
first_transmission_date: permissionsOrganisme.infoTransmissionEffectifs,
last_transmission_date: permissionsOrganisme.infoTransmissionEffectifs,
mode_de_transmission: permissionsOrganisme.infoTransmissionEffectifs,
setup_step_courante: permissionsOrganisme.infoTransmissionEffectifs,
mode_de_transmission_configuration_date: permissionsOrganisme.infoTransmissionEffectifs,
mode_de_transmission_configuration_author_fullname: permissionsOrganisme.infoTransmissionEffectifs,

// configuration API
api_key: permissionsOrganisme.manageEffectifs,
Expand Down Expand Up @@ -852,6 +885,9 @@ export function getOrganismeListProjection(
erps: {
$cond: [infoTransmissionEffectifsCondition, "$erps", undefined],
},
erp_unsupported: {
$cond: [infoTransmissionEffectifsCondition, "$erp_unsupported", undefined],
},
first_transmission_date: {
$cond: [infoTransmissionEffectifsCondition, "$first_transmission_date", undefined],
},
Expand Down
12 changes: 10 additions & 2 deletions server/src/common/model/@types/Organisme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface Organisme {
* ERPs rattachés au CFA, s'ils existent
*/
erps?: string[];
/**
* ERP renseigné par l'utilisateur à la configuration quand il n'est pas supporté
*/
erp_unsupported?: string;
/**
* Compteur sur le nombre d'effectifs de l'organisme
*/
Expand Down Expand Up @@ -1009,9 +1013,13 @@ export interface Organisme {
*/
mode_de_transmission?: "API" | "MANUEL";
/**
* Etape d'installation courante
* Date à laquelle le mode de transmission a été configuré
*/
mode_de_transmission_configuration_date?: Date;
/**
* Auteur de la configuration (prénom nom)
*/
setup_step_courante?: "STEP1" | "STEP2" | "STEP3" | "COMPLETE";
mode_de_transmission_configuration_author_fullname?: string;
/**
* Flag pour identifier que c'est un organisme créé à partir d'un lieu
*/
Expand Down
11 changes: 8 additions & 3 deletions server/src/common/model/organismes.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const schema = object(
description: "ERPs rattachés au CFA, s'ils existent",
}
),
erp_unsupported: string({
description: "ERP renseigné par l'utilisateur à la configuration quand il n'est pas supporté",
}),
effectifs_count: integer({ description: "Compteur sur le nombre d'effectifs de l'organisme" }),
effectifs_current_year_count: integer({
description: "Compteur sur le nombre d'effectifs de l'organisme sur l'année courante",
Expand Down Expand Up @@ -181,9 +184,11 @@ const schema = object(
description: "Mode de transmission des effectifs",
enum: ["API", "MANUEL"],
}),
setup_step_courante: string({
description: "Etape d'installation courante",
enum: ["STEP1", "STEP2", "STEP3", "COMPLETE"],
mode_de_transmission_configuration_date: date({
description: "Date à laquelle le mode de transmission a été configuré",
}),
mode_de_transmission_configuration_author_fullname: string({
description: "Auteur de la configuration (prénom nom)",
}),
creation_statut: string({
description: "Flag pour identifier que c'est un organisme créé à partir d'un lieu",
Expand Down
6 changes: 3 additions & 3 deletions server/src/common/validation/configurationERPSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from "zod";

export const configurationERPSchema = {
erps: z.string().array().optional(),
mode_de_transmission: z.enum(["API", "MANUEL"]).nullable().optional(),
setup_step_courante: z.enum(["STEP1", "STEP2", "STEP3", "COMPLETE"]).optional(),
erps: z.string().toLowerCase().array().optional(),
mode_de_transmission: z.enum(["API", "MANUEL"]).optional(),
erp_unsupported: z.string().optional(),
};

export type ConfigurationERP = z.infer<z.ZodObject<typeof configurationERPSchema>>;
8 changes: 8 additions & 0 deletions server/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
getOrganismeByUAIAndSIRET,
getInvalidSiretsFromDossierApprenant,
getInvalidUaisFromDossierApprenant,
resetConfigurationERP,
} from "@/common/actions/organismes/organismes.actions";
import { searchOrganismesFormations } from "@/common/actions/organismes/organismes.formations.actions";
import { createSession } from "@/common/actions/sessions.actions";
Expand Down Expand Up @@ -459,6 +460,13 @@ function setupRoutes(app: Application) {
await configureOrganismeERP(req.user, res.locals.organismeId, conf);
})
)
.delete(
"/configure-erp",
requireOrganismePermission("manageEffectifs"),
returnResult(async (req, res) => {
await resetConfigurationERP(req.user, res.locals.organismeId);
})
)
.post(
"/verify-user",
requireOrganismePermission("manageEffectifs"),
Expand Down
2 changes: 0 additions & 2 deletions server/tests/integration/http/organisme.routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ describe("Routes /organismes/:id", () => {
it("Erreur si non authentifié", async () => {
const response = await httpClient.put(`/api/v1/organismes/${id(1)}/configure-erp`, {
mode_de_transmission: "MANUEL",
setup_step_courante: "COMPLETE",
});

expectUnauthorizedError(response);
Expand Down Expand Up @@ -665,7 +664,6 @@ describe("Routes /organismes/:id", () => {
`/api/v1/organismes/${id(1)}/configure-erp`,
{
mode_de_transmission: "MANUEL",
setup_step_courante: "COMPLETE",
}
);

Expand Down
56 changes: 56 additions & 0 deletions shared/constants/erps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { sortAlphabeticallyBy } from "../utils";

interface ERP {
id: string;
name: string;
helpFilePath?: string;
helpFileSize?: string;
apiV3?: boolean;
}

export const ERPS = sortAlphabeticallyBy("name", [
{
id: "gesti",
name: "Gesti",
helpFilePath: "https://files.tableau-de-bord.apprentissage.beta.gouv.fr/pas-a-pas/gesti.pdf",
helpFileSize: "352 ko",
},
{
id: "ymag",
name: "Ypareo",
helpFilePath: "https://files.tableau-de-bord.apprentissage.beta.gouv.fr/pas-a-pas/ypareo.pdf",
helpFileSize: "1.7 Mo",
},
{
id: "scform",
name: "SC Form",
// helpFilePath: "https://files.tableau-de-bord.apprentissage.beta.gouv.fr/pas-a-pas/scform.pdf",
// helpFileSize: "734 ko",
apiV3: true,
},
{
id: "formasup",
name: "Formasup",
},
{
id: "fcamanager",
name: "FCA Manager",
helpFilePath: "https://files.tableau-de-bord.apprentissage.beta.gouv.fr/pas-a-pas/fcamanager.pdf",
helpFileSize: "288 ko",
},
] satisfies ERP[]);

export const ERPS_BY_ID = ERPS.reduce(
(acc, erp) => {
acc[erp.id] = erp;
return acc;
},
{} as Record<string, ERP>
);

// obsolète, utilisé par les anciens composants uniquement
export const ERPS_FORM: any[] = [
...ERPS,
{ id: "AUTRE", name: "Autre ERP", state: "otherErp" },
{ id: "NON", name: "Je n'ai pas d'ERP", state: "noErp" },
];
1 change: 1 addition & 0 deletions shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./erps";
export * from "./plausible-goals";
export * from "./sifa";
export * from "./territoires";
71 changes: 0 additions & 71 deletions ui/common/constants/erps.ts

This file was deleted.

12 changes: 10 additions & 2 deletions ui/common/internal/Organisme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface Organisme {
* ERPs rattachés au CFA, s'ils existent
*/
erps?: string[];
/**
* ERP renseigné par l'utilisateur à la configuration quand il n'est pas supporté
*/
erp_unsupported?: string;
/**
* Compteur sur le nombre d'effectifs de l'organisme
*/
Expand Down Expand Up @@ -973,9 +977,13 @@ export interface Organisme {
*/
mode_de_transmission?: "API" | "MANUEL";
/**
* Etape d'installation courante
* Date à laquelle le mode de transmission a été configuré
*/
mode_de_transmission_configuration_date?: string;
/**
* Auteur de la configuration (prénom nom)
*/
setup_step_courante?: "STEP1" | "STEP2" | "STEP3" | "COMPLETE";
mode_de_transmission_configuration_author_fullname?: string;
/**
* Date de mise à jour en base de données
*/
Expand Down
3 changes: 1 addition & 2 deletions ui/components/ErpTutorial/ErpTutorial.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ArrowForwardIcon } from "@chakra-ui/icons";
import { Box, Button, Heading, Stack, Text } from "@chakra-ui/react";
import React from "react";

import { ERPS_BY_ID } from "@/common/constants/erps";
import { ERPS_BY_ID } from "shared";

const ErpTutorial = ({ erp, ...rest }) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion ui/components/Links/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const Link = ({ children, href, shallow, plausibleGoal, ...rest }: LinkProps) =>
const { trackPlausibleEvent } = usePlausibleTracking();
return (
<ChakraLink
{...rest}
as={NavLink}
href={href}
shallow={shallow ?? false}
onClick={() => {
plausibleGoal && trackPlausibleEvent(plausibleGoal);
}}
{...rest}
>
{children}
</ChakraLink>
Expand Down
Loading

0 comments on commit 7082b65

Please sign in to comment.