feat: do not encrypt field of study; list candidates filtering

This commit is contained in:
Sebastian Pravda 2022-11-17 20:41:03 +01:00
parent 315966acba
commit d8a269edd3
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
5 changed files with 29 additions and 20 deletions

View file

@ -95,6 +95,12 @@ pub async fn list_candidates(
) -> Result<Json<Vec<CandidateResponse>>, Custom<String>> { ) -> Result<Json<Vec<CandidateResponse>>, Custom<String>> {
let db = conn.into_inner(); let db = conn.into_inner();
let private_key = session.get_private_key(); let private_key = session.get_private_key();
if let Some(field) = field.clone() {
if !(field == "KB".to_string() || field == "IT".to_string() || field == "G") {
return Err(Custom(Status::BadRequest, "Invalid field of study".to_string()));
}
}
let candidates = CandidateService::list_candidates(private_key, db, field) let candidates = CandidateService::list_candidates(private_key, db, field)
.await .await

View file

@ -70,7 +70,7 @@ pub struct EncryptedApplicationDetails {
pub citizenship: EncryptedString, pub citizenship: EncryptedString,
pub email: EncryptedString, pub email: EncryptedString,
pub sex: EncryptedString, pub sex: EncryptedString,
pub study: EncryptedString, pub study: String,
// Parent // Parent
pub parent_name: EncryptedString, pub parent_name: EncryptedString,
@ -95,7 +95,7 @@ impl EncryptedApplicationDetails {
EncryptedString::new(&form.citizenship, &recipients), EncryptedString::new(&form.citizenship, &recipients),
EncryptedString::new(&form.email, &recipients), EncryptedString::new(&form.email, &recipients),
EncryptedString::new(&form.sex, &recipients), EncryptedString::new(&form.sex, &recipients),
EncryptedString::new(&form.study, &recipients),
EncryptedString::new(&form.parent_name, &recipients), EncryptedString::new(&form.parent_name, &recipients),
EncryptedString::new(&form.parent_surname, &recipients), EncryptedString::new(&form.parent_surname, &recipients),
EncryptedString::new(&form.parent_telephone, &recipients), EncryptedString::new(&form.parent_telephone, &recipients),
@ -112,12 +112,12 @@ impl EncryptedApplicationDetails {
citizenship: d.6, citizenship: d.6,
email: d.7, email: d.7,
sex: d.8, sex: d.8,
study: d.9, study: form.study,
parent_name: d.10, parent_name: d.9,
parent_surname: d.11, parent_surname: d.10,
parent_telephone: d.12, parent_telephone: d.11,
parent_email: d.13, parent_email: d.12,
}) })
} }
@ -132,7 +132,6 @@ impl EncryptedApplicationDetails {
self.citizenship.decrypt(&priv_key), // 6 self.citizenship.decrypt(&priv_key), // 6
self.email.decrypt(&priv_key), // 7 self.email.decrypt(&priv_key), // 7
self.sex.decrypt(&priv_key), // 8 self.sex.decrypt(&priv_key), // 8
self.study.decrypt(&priv_key), // 9
self.parent_name.decrypt(&priv_key), self.parent_name.decrypt(&priv_key),
self.parent_surname.decrypt(&priv_key), self.parent_surname.decrypt(&priv_key),
self.parent_telephone.decrypt(&priv_key), self.parent_telephone.decrypt(&priv_key),
@ -149,12 +148,12 @@ impl EncryptedApplicationDetails {
citizenship: d.6, citizenship: d.6,
email: d.7, email: d.7,
sex: d.8, sex: d.8,
study: d.9, study: self.study,
parent_name: d.10, parent_name: d.9,
parent_surname: d.11, parent_surname: d.10,
parent_telephone: d.12, parent_telephone: d.11,
parent_email: d.13, parent_email: d.12,
}) })
} }
} }
@ -175,7 +174,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails
citizenship: EncryptedString::try_from(candidate.citizenship)?, citizenship: EncryptedString::try_from(candidate.citizenship)?,
email: EncryptedString::try_from(candidate.email)?, email: EncryptedString::try_from(candidate.email)?,
sex: EncryptedString::try_from(candidate.sex)?, sex: EncryptedString::try_from(candidate.sex)?,
study: EncryptedString::try_from(candidate.study)?, study: candidate.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
parent_name: EncryptedString::try_from(parent.name)?, parent_name: EncryptedString::try_from(parent.name)?,
parent_surname: EncryptedString::try_from(parent.surname)?, parent_surname: EncryptedString::try_from(parent.surname)?,

View file

@ -29,9 +29,14 @@ impl Query {
pub async fn list_candidates( pub async fn list_candidates(
db: &DbConn, db: &DbConn,
field_of_study: Option<String>, field_of_study_opt: Option<String>,
) -> Result<Vec<ApplicationResult>, DbErr> { ) -> Result<Vec<ApplicationResult>, DbErr> {
Candidate::find() let select = Candidate::find();
if let Some(study) = field_of_study_opt {
select.filter(candidate::Column::Study.eq(study))
} else {
select
}
.join(JoinType::InnerJoin, candidate::Relation::Parent.def()) .join(JoinType::InnerJoin, candidate::Relation::Parent.def())
.column_as(parent::Column::Name, "parent_name") .column_as(parent::Column::Name, "parent_name")
.column_as(parent::Column::Surname, "parent_surname") .column_as(parent::Column::Surname, "parent_surname")

View file

@ -22,13 +22,12 @@ impl CandidateResponse {
) -> Result<Self, ServiceError> { ) -> Result<Self, ServiceError> {
let name = decrypt_if_exists(private_key, name_opt).await?; let name = decrypt_if_exists(private_key, name_opt).await?;
let surname = decrypt_if_exists(private_key, surname_opt).await?; let surname = decrypt_if_exists(private_key, surname_opt).await?;
let study = decrypt_if_exists(private_key, study_opt).await?;
Ok( Ok(
Self { Self {
application_id,
name, name,
application_id,
surname, surname,
study, study: study_opt.unwrap_or("".to_string()),
submitted, submitted,
} }
) )

View file

@ -147,7 +147,7 @@ impl CandidateService {
field_of_study: Option<String>, field_of_study: Option<String>,
) -> Result<Vec<CandidateResponse>, ServiceError> { ) -> Result<Vec<CandidateResponse>, ServiceError> {
let candidates = Query::list_candidates(db, None).await?; let candidates = Query::list_candidates(db, field_of_study).await?;
let mut result: Vec<CandidateResponse> = vec![]; let mut result: Vec<CandidateResponse> = vec![];
for candidate in candidates { for candidate in candidates {