mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 14:02:14 +00:00
feat: link candidates, so both can decrypt their personal id number
This commit is contained in:
parent
6e1c35f721
commit
3d8487f771
1 changed files with 39 additions and 14 deletions
|
|
@ -44,19 +44,15 @@ impl ApplicationService {
|
||||||
plain_text_password.to_string()
|
plain_text_password.to_string()
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
let recipients = get_recipients(db, &pubkey).await?;
|
|
||||||
let enc_personal_id_number = EncryptedString::new(
|
|
||||||
&personal_id_number,
|
|
||||||
&recipients,
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
let candidate = Self::find_or_create_candidate_with_personal_id(
|
let (candidate, enc_personal_id_number) = Self::find_or_create_candidate_with_personal_id(
|
||||||
admin_private_key,
|
admin_private_key,
|
||||||
db,
|
db,
|
||||||
personal_id_number,
|
personal_id_number,
|
||||||
&enc_personal_id_number,
|
&pubkey,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
|
|
||||||
let application = Mutation::create_application(
|
let application = Mutation::create_application(
|
||||||
db,
|
db,
|
||||||
application_id,
|
application_id,
|
||||||
|
|
@ -74,8 +70,9 @@ impl ApplicationService {
|
||||||
admin_private_key: &String,
|
admin_private_key: &String,
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
personal_id_number: String,
|
personal_id_number: String,
|
||||||
enc_personal_id_number: &EncryptedString,
|
pubkey: &String,
|
||||||
) -> Result<candidate::Model, ServiceError> {
|
// enc_personal_id_number: &EncryptedString,
|
||||||
|
) -> Result<(candidate::Model, String), ServiceError> {
|
||||||
let candidates = Query::list_candidates_full(db).await?;
|
let candidates = Query::list_candidates_full(db).await?;
|
||||||
let ids_decrypted = futures::future::join_all(
|
let ids_decrypted = futures::future::join_all(
|
||||||
candidates.iter().map(|c| async {(
|
candidates.iter().map(|c| async {(
|
||||||
|
|
@ -92,16 +89,44 @@ impl ApplicationService {
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, id)| id == &personal_id_number)
|
.filter(|(_, id)| id == &personal_id_number)
|
||||||
.collect();
|
.collect();
|
||||||
// TODO: take the candidate id directly from the iterator
|
|
||||||
|
let mut recipients = get_recipients(db, pubkey).await?;
|
||||||
|
|
||||||
if found_ids.iter().any(|(_, personal_id)| personal_id == &personal_id_number) {
|
if found_ids.iter().any(|(_, personal_id)| personal_id == &personal_id_number) {
|
||||||
let candidate = Query::find_candidate_by_id(db, found_ids[0].0)
|
let candidate = Query::find_candidate_by_id(db, found_ids[0].0)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(ServiceError::CandidateNotFound)?;
|
.ok_or(ServiceError::CandidateNotFound)?;
|
||||||
|
|
||||||
|
let mut linked_applications_pubkeys = Query::find_applications_by_candidate_id(db, candidate.id)
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.map(|a| a.public_key.to_owned())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
recipients.append(&mut linked_applications_pubkeys);
|
||||||
|
|
||||||
|
|
||||||
|
let enc_personal_id_number = EncryptedString::new(
|
||||||
|
&personal_id_number,
|
||||||
|
&recipients,
|
||||||
|
).await?;
|
||||||
|
|
||||||
let candidate = Mutation::update_personal_id(db, candidate, &enc_personal_id_number.to_owned().to_string()).await?;
|
let candidate = Mutation::update_personal_id(db, candidate, &enc_personal_id_number.to_owned().to_string()).await?;
|
||||||
println!("Candidates linked!");
|
println!("Candidates linked!");
|
||||||
Ok(candidate)
|
Ok(
|
||||||
|
(candidate, enc_personal_id_number.to_string())
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
CandidateService::create(db, enc_personal_id_number.to_owned().to_string()).await
|
let enc_personal_id_number = EncryptedString::new(
|
||||||
|
&personal_id_number,
|
||||||
|
&recipients,
|
||||||
|
).await?;
|
||||||
|
Ok(
|
||||||
|
(
|
||||||
|
CandidateService::create(db, enc_personal_id_number.to_owned().to_string()).await?,
|
||||||
|
enc_personal_id_number.to_string(),
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue