Skip to content

Commit

Permalink
feat(general): add structure information management and messages for …
Browse files Browse the repository at this point in the history
…users
  • Loading branch information
pYassine committed Sep 24, 2024
1 parent 45e56b3 commit 232375a
Show file tree
Hide file tree
Showing 68 changed files with 3,398 additions and 162 deletions.
33 changes: 18 additions & 15 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
fileignoreconfig:
- filename: .kontinuous/env/dev/templates/backend.sealed-secret.yaml
checksum: d76fa05f7587f094d19959816a03c4589ae0c8675436f11fa8bf454cfd917741
- filename: .kontinuous/env/preprod/templates/backend.sealed-secret.yaml
checksum: 291f7f330aca385888f414aa9a7f4ebfe0c03bd4d154e0ed0f6ee4895ea139c0
- filename: .kontinuous/env/prod/templates/backend.sealed-secret.yaml
checksum: a066a32a383b37f3e2195d41a309628e64d66e70611aa8ee05159205c0fdcd7c
- filename: _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql
checksum: d61470228208094ecc7a14b8ccb30aa49c363009104aaa4d983fe54baba10c08
- filename: _scripts/db/dumps/domifa_test.postgres.truncate-data.sql
checksum: 0a9b780387e8c40344bd52f033a201da019c8b3e9e5d501ee6cb85040b6e168c
checksum: 502a64b85ffe956adf47db779ed78a2f25bd8b5de188c571180ea7483f88370b
- filename: _scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql
checksum: 82670bbe12e21c9cf5af9a3e75f1c06c4a97d1bf5a8825cfab2553bc075e171e
- filename: packages/backend/.env.backend.dev.example.env
checksum: d52c7fbfae21884e63f84a7aa0759c5296f0ecb483e71866541b2b44d7880758
- filename: packages/backend/.env.backend.test.local.example.env
checksum: 1540bbfa2a80d38a05d5d1628db89f7f0ae1ed1e0f054b54a2589e6fe5ca24e0
- filename: packages/backend/.env.preset/local-dev.preset.env
checksum: 4b681f0cdd8f85ce6b2877c6c1f2b904b48965fb4a411f2caf56485687ddd020
- filename: packages/backend/src/_migrations/1723547616571-create-structure-information-migration.ts
checksum: 1b96083efc358311f59512c87fffead4e00aa557ba70454e7f2e152add1e3089
- filename: packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts
checksum: 9a0633f712677ab1f864b3003cb2c947a4d51ff10bf8488af174acef31b80f9c
- filename: packages/frontend/src/app/modules/admin-portail-usagers/components/manage-structure-information-form/manage-structure-information-form.component.ts
checksum: 120db5b7bac6a61f84dae5a5e04b05774fbfb2a9e81b6df0fed56d38db151ee6
- filename: packages/frontend/src/app/modules/admin-portail-usagers/components/manage-structure-information/manage-structure-information.component.html
checksum: 30d558a1c39242d78b869fe18c594fa82bdf1e173bec521aaf5d6e9768fce4ed
- filename: yarn.lock
checksum: 838a3248dfbc076c42ce2a3e27ca862a0b02aae15a6a20d908bdfe968083577e
version: ""
v
checksum: af5962c1b288218cb9a43c9bff6ddd5d16c086088b7c990278af030261a7f500
- filename: packages/backend/.env.preset/local-test-docker.preset.env
checksum: 2a459a7689ff1c0add9bbea1ff00eb44118cf3f3f0e6f6197830d28016a3272a
Expand Down Expand Up @@ -97,4 +96,8 @@ fileignoreconfig:
checksum: 65d0b914b6baa33b2e8ec95786ef0c9d9960787295f1f02450d0262f71fd3d0e
- filename: yarn.lock
checksum: dce41db10fe65e26fb8b1ca281e9a4672e65131e94a881a5ad6fadbfbcfd9058
version: "1.0"
checksum: 65d0b914b6baa33b2e8ec95786ef0c9d9960787295f1f02450d0262f71fd3d0e
- filename: yarn.lock
checksum: dce41db10fe65e26fb8b1ca281e9a4672e65131e94a881a5ad6fadbfbcfd9058
version: "1.0"
Binary file modified _scripts/db/dumps/domifa_test.postgres.custom.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ COPY public.structure_doc (uuid, "createdAt", "updatedAt", version, id, label, "
\.
--
-- Data for Name: structure_information; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.structure_information (uuid, "createdAt", "updatedAt", version, title, description, "isTemporary", "startDate", "endDate", type, "createdBy", "structureId") FROM stdin;
\.
--
-- Data for Name: structure_stats_reporting; Type: TABLE DATA; Schema: public; Owner: -
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ COPY public.structure_doc (uuid, "createdAt", "updatedAt", version, id, label, "
\.
--
-- Data for Name: structure_information; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.structure_information (uuid, "createdAt", "updatedAt", version, title, description, "isTemporary", "startDate", "endDate", type, "createdBy", "structureId") FROM stdin;
\.
--
-- Data for Name: structure_stats_reporting; Type: TABLE DATA; Schema: public; Owner: -
--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { domifaConfig } from "../config";

export class CreateStructureInformationMigration1723547616571
implements MigrationInterface
{
name = "CreateStructureInformationMigration1723547616571";

public async up(queryRunner: QueryRunner): Promise<void> {
if (
domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local"
) {
await queryRunner.query(
`CREATE TABLE "structure_information" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "version" integer NOT NULL, "title" character varying NOT NULL, "description" character varying, "isTemporary" boolean NOT NULL DEFAULT false, "startDate" TIMESTAMP, "endDate" TIMESTAMP, "type" character varying NOT NULL, "createdBy" jsonb, "structureId" integer NOT NULL, CONSTRAINT "PK_b51c75b37769abf1fdf28fc89ef" PRIMARY KEY ("uuid"))`
);
await queryRunner.query(
`CREATE INDEX "IDX_17cd35c9fdcd9ab82015a46b22" ON "structure_information" ("structureId") `
);
await queryRunner.query(
`ALTER TABLE "structure_information" ADD CONSTRAINT "FK_17cd35c9fdcd9ab82015a46b22c" FOREIGN KEY ("structureId") REFERENCES "structure"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "structure_information" DROP CONSTRAINT "FK_17cd35c9fdcd9ab82015a46b22c"`
);

await queryRunner.query(`DROP TABLE "structure_information"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function createTables(queryRunner: QueryRunner) {
"importDate" date NULL,
"lastLogin" date NULL,
nom text NOT NULL,
"options" jsonb NOT NULL,
"options" jsonb DEFAULT '{"surnom": false, "numeroBoite": true}'::jsonb NOT NULL,
responsable jsonb NOT NULL,
"structureType" text NOT NULL,
"token" text NULL,
Expand All @@ -214,16 +214,91 @@ async function createTables(queryRunner: QueryRunner) {
"organismeType" text NULL,
"departmentName" text NULL,
"regionName" text NULL,
CONSTRAINT " " UNIQUE (email),
CONSTRAINT "PK_a92a6b3dd54efb4ab48b2d6e7c1" PRIMARY KEY (uuid),
CONSTRAINT "UQ_90ac7986e769d602d218075215c" UNIQUE (id),
CONSTRAINT "UQ_b36e92e49b2a68f8fea64ec8d5b" UNIQUE (email)
CONSTRAINT "UQ_90ac7986e769d602d218075215c" UNIQUE (id)
);
CREATE INDEX "IDX_30c4985e1148ec42ad6122f0ff" ON public.structure USING btree ("structureType");
CREATE INDEX "IDX_62204f14a6d17cad41d419d150" ON public.structure USING btree ("codePostal");
CREATE INDEX "IDX_90ac7986e769d602d218075215" ON public.structure USING btree (id);
CREATE INDEX "IDX_b36e92e49b2a68f8fea64ec8d5" ON public.structure USING btree (email);
CREATE INDEX "IDX_e848a2cfbd611ec5edc18074e2" ON public.structure USING btree (region);
CREATE INDEX "IDX_fa4dea9a1ff8deb8fcf47c451e" ON public.structure USING btree (departement);
CREATE UNIQUE INDEX " " ON public.structure USING btree (email);
-- public.structure_information definition
-- Drop table
-- DROP TABLE public.structure_information;
CREATE TABLE public.structure_information (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"createdAt" timestamptz DEFAULT now() NOT NULL,
"updatedAt" timestamptz DEFAULT now() NOT NULL,
"version" int4 NOT NULL,
title varchar NOT NULL,
description varchar NULL,
"isTemporary" bool DEFAULT false NOT NULL,
"startDate" timestamp NULL,
"endDate" timestamp NULL,
"type" varchar NOT NULL,
"createdBy" jsonb NULL,
"structureId" int4 NOT NULL,
CONSTRAINT "PK_b51c75b37769abf1fdf28fc89ef" PRIMARY KEY (uuid)
);
CREATE INDEX "IDX_17cd35c9fdcd9ab82015a46b22" ON public.structure_information USING btree ("structureId");
-- public.typeorm_metadata definition
-- Drop table
-- DROP TABLE public.typeorm_metadata;
CREATE TABLE public.typeorm_metadata (
"type" varchar(255) NOT NULL,
"database" varchar(255) DEFAULT NULL::character varying NULL,
"schema" varchar(255) DEFAULT NULL::character varying NULL,
"table" varchar(255) DEFAULT NULL::character varying NULL,
"name" varchar(255) DEFAULT NULL::character varying NULL,
value text NULL
);
-- public.usager_history_states definition
-- Drop table
-- DROP TABLE public.usager_history_states;
CREATE TABLE public.usager_history_states (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"createdAt" timestamptz DEFAULT now() NOT NULL,
"updatedAt" timestamptz DEFAULT now() NOT NULL,
"version" int4 NOT NULL,
"usagerUUID" uuid NOT NULL,
"structureId" int4 NOT NULL,
"ayantsDroits" jsonb NOT NULL,
decision jsonb NOT NULL,
entretien jsonb NOT NULL,
rdv jsonb NULL,
"createdEvent" text NOT NULL,
"historyBeginDate" timestamptz NOT NULL,
"historyEndDate" timestamptz NULL,
"isActive" bool DEFAULT false NULL,
"typeDom" text DEFAULT 'PREMIERE_DOM'::text NULL,
nationalite text NULL,
sexe text NULL,
"dateNaissance" timestamptz NULL,
CONSTRAINT "PK_c1bd0d42891df5715d2ef8474d7" PRIMARY KEY (uuid)
);
CREATE INDEX "IDX_7ed0bb63b8fc294757b8bd8854" ON public.usager_history_states USING btree ("historyEndDate");
CREATE INDEX "IDX_85ac9012f78c974fb73a5352df" ON public.usager_history_states USING btree ("structureId");
CREATE INDEX "IDX_9beb1346c63a45ba7c15db9ee7" ON public.usager_history_states USING btree ("historyBeginDate");
CREATE INDEX "IDX_e819c8b113a23a4a0c13a741da" ON public.usager_history_states USING btree ("usagerUUID");
CREATE INDEX idx_stats_range ON public.usager_history_states USING btree ("historyBeginDate", "historyEndDate", "isActive");
-- public.message_sms definition
Expand Down Expand Up @@ -477,42 +552,6 @@ async function createTables(queryRunner: QueryRunner) {
CREATE INDEX "IDX_aa19c17fc79f4e4a648643096f" ON public.usager_entretien USING btree ("usagerUUID");
-- public.usager_history_states definition
-- Drop table
-- DROP TABLE public.usager_history_states;
CREATE TABLE public.usager_history_states (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"createdAt" timestamptz DEFAULT now() NOT NULL,
"updatedAt" timestamptz DEFAULT now() NOT NULL,
"version" int4 NOT NULL,
"usagerUUID" uuid NOT NULL,
"structureId" int4 NOT NULL,
"ayantsDroits" jsonb NOT NULL,
decision jsonb NOT NULL,
entretien jsonb NOT NULL,
rdv jsonb NULL,
"createdEvent" text NOT NULL,
"historyBeginDate" timestamptz NOT NULL,
"historyEndDate" timestamptz NULL,
"isActive" bool DEFAULT false NULL,
"typeDom" text DEFAULT 'PREMIERE_DOM'::text NULL,
nationalite text NULL,
sexe text NULL,
"dateNaissance" timestamptz NULL,
CONSTRAINT "PK_c1bd0d42891df5715d2ef8474d7" PRIMARY KEY (uuid),
CONSTRAINT "FK_85ac9012f78c974fb73a5352dfe" FOREIGN KEY ("structureId") REFERENCES public."structure"(id) ON DELETE CASCADE,
CONSTRAINT "FK_e819c8b113a23a4a0c13a741da0" FOREIGN KEY ("usagerUUID") REFERENCES public.usager("uuid") ON DELETE CASCADE
);
CREATE INDEX "IDX_7ed0bb63b8fc294757b8bd8854" ON public.usager_history_states USING btree ("historyEndDate");
CREATE INDEX "IDX_85ac9012f78c974fb73a5352df" ON public.usager_history_states USING btree ("structureId");
CREATE INDEX "IDX_9beb1346c63a45ba7c15db9ee7" ON public.usager_history_states USING btree ("historyBeginDate");
CREATE INDEX "IDX_e819c8b113a23a4a0c13a741da" ON public.usager_history_states USING btree ("usagerUUID");
CREATE INDEX idx_stats_range ON public.usager_history_states USING btree ("historyBeginDate", "historyEndDate", "isActive");
-- public.usager_notes definition
-- Drop table
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
import { UserStructureAuthenticated } from "../../_common/model";

export const CurrentStructureInformation = createParamDecorator(
(_data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return request.structureInformation as UserStructureAuthenticated;
}
);
1 change: 1 addition & 0 deletions packages/backend/src/auth/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./AllowUserProfiles.decorator";
export * from "./AllowUserStructureRoles.decorator";
export * from "./current-chosen-user-structure.decorator";
export * from "./current-interaction.decorator";
export * from "./current-structure-information.decorator";
export * from "./current-usager-note.decorator";
export * from "./current-usager.decorator";
export * from "./current-user.decorator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { userStructureRepository } from "../../database";
export class CanGetUserStructureGuard implements CanActivate {
public async canActivate(context: ExecutionContext) {
const r = context.switchToHttp().getRequest();

const userUuid = r.params.userUuid;
const structureId = r.user.structureId;

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/auth/guards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
export * from "./AppUserGuard.guard";
export * from "./CanGetUserStructure.guard";
export * from "./interactions.guard";
export * from "./structure-information-access.guard";
export * from "./usager-access.guard";
export * from "./usager-note-access.guard";
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
CanActivate,
ExecutionContext,
HttpException,
HttpStatus,
Injectable,
} from "@nestjs/common";

import { appLogger } from "../../util";
import { structureInformationRepository } from "../../database";

@Injectable()
export class StructureInformationAccessGuard implements CanActivate {
public async canActivate(context: ExecutionContext) {
const r = context.switchToHttp().getRequest();

if (
typeof r.params.uuid === "undefined" ||
typeof r.user.structureId === "undefined"
) {
appLogger.error(
`[StructureInformationAccessGuard] invalid uuid or structureId`,
{
sentry: true,
context: {
usagerRef: r?.params?.uui,
structureId: r?.user?.structureId,
user: r?.user?._id,
},
}
);
throw new HttpException(
"STRUCTURE_INFORMATION_NOT_FOUND",
HttpStatus.BAD_REQUEST
);
}

const uuid = r.params.uuid;
const structureId = parseInt(r.user.structureId, 10);

try {
const structureInformation =
await structureInformationRepository.findOneOrFail({
where: {
structureId,
uuid,
},
});
r.structureInformation = structureInformation;
return r;
} catch (e) {
appLogger.error(`[UsagerAccessGuard] structureInformation not found`, {
sentry: true,
context: {
uuid,
structureId,
user: r?.user?._id,
role: r?.user?.role,
},
});
throw new HttpException("USAGER_NOT_FOUND", HttpStatus.BAD_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
StructureInformation,
StructureInformationType,
UserStructureResume,
} from "@domifa/common";
import { Entity, Column, Index, JoinColumn, ManyToOne } from "typeorm";
import { AppTypeormTable } from "../_core";
import { StructureTable } from "./StructureTable.typeorm";

@Entity({ name: "structure_information" })
export class StructureInformationTable
extends AppTypeormTable<StructureInformationTable>
implements StructureInformation
{
@Column({ type: "varchar" })
title: string;

@Column({ nullable: true })
description: string;

@Column({ default: false })
isTemporary: boolean;

@Column({ type: "timestamp", nullable: true })
startDate: Date | null;

@Column({ type: "timestamp", nullable: true })
endDate: Date | null;

@Column({ type: "varchar" })
type: StructureInformationType;

@Column({ type: "jsonb", nullable: true })
createdBy: UserStructureResume;

@Index()
@ManyToOne(() => StructureTable, (structure) => structure.id, {
onDelete: "CASCADE",
})
@Column({ type: "integer", nullable: false })
@JoinColumn({ name: "structureId", referencedColumnName: "id" })
public structureId: number;
}
Loading

0 comments on commit 232375a

Please sign in to comment.