-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): add patch of documents
- Loading branch information
Showing
44 changed files
with
723 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
packages/backend/src/_common/model/usager/UsagerDoc.type.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
//@index('./*', f => `export * from '${f.path}'`) | ||
export * from "./cerfa"; | ||
export * from "./history"; | ||
export * from "./UsagerDoc.type"; | ||
export * from "./UsagerImport.type"; | ||
export * from "./UsagerLight.type"; |
29 changes: 29 additions & 0 deletions
29
packages/backend/src/_migrations/1730216743164-auto-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import { domifaConfig } from "../config"; | ||
|
||
export class AutoMigration1730216743164 implements MigrationInterface { | ||
name = "AutoMigration1730216743164"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
if ( | ||
domifaConfig().envId === "prod" || | ||
domifaConfig().envId === "preprod" || | ||
domifaConfig().envId === "local" | ||
) { | ||
await queryRunner.query( | ||
`ALTER TABLE "usager_docs" ADD "shared" boolean NOT NULL DEFAULT false` | ||
); | ||
|
||
await queryRunner.query( | ||
`UPDATE "structure_doc" SET label = 'Attestation postale' where label='attestation_postale'` | ||
); | ||
await queryRunner.query( | ||
`UPDATE "structure_doc" SET label = 'Courrier de radiation' where label='courrier_radiation'` | ||
); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "usager_docs" DROP COLUMN "shared"`); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/backend/src/auth/decorators/current-usager-doc.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { UsagerDoc } from "@domifa/common"; | ||
import { createParamDecorator, ExecutionContext } from "@nestjs/common"; | ||
|
||
export const CurrentUsagerDoc = createParamDecorator( | ||
(_data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.usagerDoc as UsagerDoc; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/backend/src/auth/guards/usager-doc-access.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
} from "@nestjs/common"; | ||
|
||
import { appLogger } from "../../util"; | ||
import { isNumber, isUUID } from "class-validator"; | ||
import { usagerDocsRepository } from "../../database"; | ||
import { UserStructureAuthenticated } from "../../_common/model"; | ||
|
||
@Injectable() | ||
export class UsagerDocAccessGuard implements CanActivate { | ||
public async canActivate(context: ExecutionContext) { | ||
const request = context.switchToHttp().getRequest(); | ||
const user = request?.user as UserStructureAuthenticated; | ||
|
||
if ( | ||
user?.role === "simple" || | ||
!isUUID(request.params.docUuid) || | ||
!isNumber(user?.structureId) | ||
) { | ||
appLogger.error("[UsagerDocAccessGuard] invalid docUuid or structureId", { | ||
sentry: true, | ||
context: { | ||
docUuid: request?.params?.docUuid, | ||
structureId: user.structureId, | ||
user: user.id, | ||
role: user.role, | ||
}, | ||
}); | ||
throw new HttpException("USAGER_DOC_NOT_FOUND", HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
const docUuid = request.params.docUuid; | ||
|
||
try { | ||
// Todo: optimize this request, generate one request with a join | ||
const usagerDoc = await usagerDocsRepository.findOneOrFail({ | ||
where: { | ||
structureId: user.structureId, | ||
uuid: docUuid, | ||
}, | ||
}); | ||
request.usagerDoc = usagerDoc; | ||
return request; | ||
} catch (e) { | ||
appLogger.error("[UsagerDocAccessGuard] usager not found", { | ||
sentry: true, | ||
context: { | ||
docUuid: request.params.docUuid, | ||
structureId: user.structureId, | ||
user: user.id, | ||
role: user.role, | ||
}, | ||
}); | ||
throw new HttpException("USAGER_DOC_NOT_FOUND", HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.