From 96a93dad3a66b023cdaead5f9c62c8e9affe39d1 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Wed, 14 Dec 2022 18:27:59 +0100 Subject: [PATCH] feat: safer portfolio submit --- api/src/routes/candidate.rs | 1 - core/src/error.rs | 3 +++ core/src/services/portfolio_service.rs | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/src/routes/candidate.rs b/api/src/routes/candidate.rs index 75a40ff..91e0cab 100644 --- a/api/src/routes/candidate.rs +++ b/api/src/routes/candidate.rs @@ -213,7 +213,6 @@ pub async fn submit_portfolio( if submit.is_err() { let e = submit.err().unwrap(); // Delete on critical error - // TODO: VĂ­ce kontrol? if e.code() == 500 { // Cleanup PortfolioService::delete_portfolio(candidate.application) diff --git a/core/src/error.rs b/core/src/error.rs index b4870d1..dc5992a 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -56,6 +56,8 @@ pub enum ServiceError { AesError(#[from] aes_gcm_siv::Error), #[error("Portfolio is incomplete")] IncompletePortfolio, + #[error("Portfolio write error")] + PortfolioWriteError, #[error("Zip error")] ZipError(#[from] async_zip::error::ZipError), #[error("Csv error")] @@ -95,6 +97,7 @@ impl ServiceError { ServiceError::TokioJoinError(_) => 500, ServiceError::AesError(_) => 500, ServiceError::ArgonConfigError(_) => 500, + ServiceError::PortfolioWriteError => 500, ServiceError::ZipError(_) => 500, ServiceError::CsvError(_) => 500, ServiceError::CsvIntoInnerError => 500, diff --git a/core/src/services/portfolio_service.rs b/core/src/services/portfolio_service.rs index 556f31c..2552154 100644 --- a/core/src/services/portfolio_service.rs +++ b/core/src/services/portfolio_service.rs @@ -314,6 +314,11 @@ impl PortfolioService { ).await?; tokio::fs::remove_file(final_path).await?; + + if !Self::is_portfolio_submitted(candidate_id).await { + return Err(ServiceError::PortfolioWriteError) + } + Ok(()) }