From b097c531cc6398659767e05dd80b546e02f5e734 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Tue, 10 Jan 2023 15:23:45 +0100 Subject: [PATCH] fix: decrypt_all_details error code --- core/src/models/candidate_details.rs | 26 ++++++++++++++++++++++++ core/src/services/application_service.rs | 7 ++++++- core/src/services/candidate_service.rs | 13 ------------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/core/src/models/candidate_details.rs b/core/src/models/candidate_details.rs index 579b9e1..e6bf323 100644 --- a/core/src/models/candidate_details.rs +++ b/core/src/models/candidate_details.rs @@ -167,6 +167,20 @@ impl EncryptedCandidateDetails { } ) } + + pub fn is_filled(&self) -> bool { + self.name.is_some() && + self.surname.is_some() && + self.birthplace.is_some() && + self.birthdate.is_some() && + self.address.is_some() && + self.telephone.is_some() && + self.citizenship.is_some() && + self.email.is_some() && + self.sex.is_some() && + self.personal_id_number.is_some() && + self.study.is_some() + } } impl From<&candidate::Model> for EncryptedCandidateDetails { fn from( @@ -226,6 +240,13 @@ impl EncryptedParentDetails { } ) } + + pub fn is_filled(&self) -> bool { + self.name.is_some() && + self.surname.is_some() && + self.telephone.is_some() && + self.email.is_some() + } } impl From<&parent::Model> for EncryptedParentDetails { fn from( @@ -272,6 +293,11 @@ impl EncryptedApplicationDetails { parents: decrypted_parents, }) } + + pub fn is_filled(&self) -> bool { + self.candidate.is_filled() && + self.parents.iter().all(|p| p.is_filled()) + } } impl From<(&candidate::Model, Vec)> for EncryptedApplicationDetails { diff --git a/core/src/services/application_service.rs b/core/src/services/application_service.rs index 16b8be9..752973a 100644 --- a/core/src/services/application_service.rs +++ b/core/src/services/application_service.rs @@ -49,7 +49,12 @@ impl ApplicationService { let parents = Query::find_candidate_parents(db, &candidate).await?; let enc_details = EncryptedApplicationDetails::from((&candidate, parents)); - enc_details.decrypt(private_key).await + if enc_details.is_filled() { + enc_details.decrypt(private_key).await + } else { + Err(ServiceError::Forbidden) + } + } } \ No newline at end of file diff --git a/core/src/services/candidate_service.rs b/core/src/services/candidate_service.rs index 3156868..da059f8 100644 --- a/core/src/services/candidate_service.rs +++ b/core/src/services/candidate_service.rs @@ -167,19 +167,6 @@ impl CandidateService { ).await } - pub fn is_candidate_info(candidate: &candidate::Model) -> bool { - candidate.name.is_some() - && candidate.surname.is_some() - && candidate.birthplace.is_some() - && candidate.birthdate.is_some() - && candidate.address.is_some() - && candidate.telephone.is_some() - && candidate.citizenship.is_some() - && candidate.email.is_some() - && candidate.sex.is_some() - && candidate.study.is_some() - } - async fn decrypt_private_key( candidate: candidate::Model, password: String,