Merge pull request 'preprod' (#5) from preprod into main
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-images-lecoffre (push) Successful in 20s
Prod - Build & Deploy to Scaleway / deploy-back-lecoffre (push) Successful in 3s
Prod - Build & Deploy to Scaleway / deploy-cron-lecoffre (push) Successful in 3s

Reviewed-on: #5
This commit is contained in:
Omar 2025-07-21 23:39:59 +00:00
commit 6fe5540784
2 changed files with 51 additions and 24 deletions

View File

@ -18,16 +18,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Copy SSH
run: cp ~/.ssh/id_rsa id_rsa
#- name: Setup SSH
# run: |
# mkdir -p ~/.ssh
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
# chmod 600 ~/.ssh/id_rsa
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# env:
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
#- name: Copy SSH
# run: cp ~/.ssh/id_rsa id_rsa
- name: Login to Scaleway Container Registry
uses: docker/login-action@v3
with:

View File

@ -2,7 +2,7 @@ import { Response, Request } from "express";
import { Controller, Get, Post } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import { Document, OfficeFolder } from "le-coffre-resources/dist/Notary";
import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary";
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
@ -162,24 +162,34 @@ export default class OfficeFoldersController extends ApiController {
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
// Check if every document is validated in a folder
const documents = officeFolder.documents ?? [];
const documentsValidated = documents.filter((document) => {
let documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
return documentHydrated.document_status === "VALIDATED";
if (documents.length === 0) {
this.httpBadRequest(response, "OfficeFolder has no documents at all");
return;
}
const hasInvalidDocument = documents.some((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
return documentHydrated.document_status !== "VALIDATED" &&
documentHydrated.document_status !== "REFUSED";
});
if (documentsValidated.length !== documents.length && documents.length !== 0) {
this.httpBadRequest(response, "Cannot anchor a folder with non validated documents");
if (hasInvalidDocument) {
this.httpBadRequest(response, "OfficeFolder has non validated documents");
return;
}
const folderHashes = getFolderHashes(officeFolder);
if (folderHashes.length === 0) {
this.httpNotFoundRequest(response, "No file hash to anchor");
return;
}
const folderHashes: string[] = [];
documents.forEach((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
if (documentHydrated.document_status === "VALIDATED") {
documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
}
});
const sortedHashes = [...folderHashes].sort();
const data = await this.secureService.anchor(sortedHashes);
@ -230,7 +240,24 @@ export default class OfficeFoldersController extends ApiController {
}
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
const folderHashes = getFolderHashes(officeFolder);
const documents = officeFolder.documents ?? [];
if (documents.length === 0) {
this.httpNotFoundRequest(response, "Office folder has no documents");
return;
}
const folderHashes: string[] = [];
documents.forEach((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
if (documentHydrated.document_status === "VALIDATED") {
documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
}
});
if (folderHashes.length === 0) {
this.httpNotFoundRequest(response, "No file hash to anchor");