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

View File

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