Skip to content

Commit a421384

Browse files
authored
Revert application to the correct state (#280)
1 parent f39acd5 commit a421384

File tree

1 file changed

+35
-51
lines changed

1 file changed

+35
-51
lines changed

fplus-lib/src/core/mod.rs

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,62 +2497,46 @@ impl LDNApplication {
24972497
}
24982498

24992499
let active_allocation = db_application_file.allocation.active();
2500-
let mut remove_allocation = false;
25012500

2502-
let active_allocation_ref = match active_allocation.as_ref() {
2503-
Some(allocation) => allocation,
2504-
None => {
2505-
if db_application_file.lifecycle.is_active {
2506-
db_application_file.lifecycle.state = AppState::Granted;
2507-
} else {
2508-
let last_active_request = Self::get_last_active_request(&db_application_file)
2509-
.ok_or(LDNError::Load(
2510-
"Failed to get last active request".to_string(),
2511-
))?;
2512-
let last_verifier = Self::get_last_verifier(&db_application_file)?
2513-
.ok_or(LDNError::Load("Failed to get last verifier".to_string()))?;
2514-
db_application_file = db_application_file
2515-
.move_back_to_granted_state(&last_verifier, &last_active_request);
2516-
}
2517-
db_application_file.lifecycle.edited = Some(false);
2518-
2519-
let _ = self
2520-
.finalize_changes_approval(
2521-
db_application_file,
2522-
owner,
2523-
repo,
2524-
sha,
2525-
branch_name,
2526-
filename,
2527-
)
2528-
.await;
2529-
return Ok("Changes approved".to_string()); // or return an error if appropriate
2501+
if let Some(active_allocation) = active_allocation {
2502+
if active_allocation.signers.0.is_empty() {
2503+
db_application_file.lifecycle.state = AppState::ReadyToSign
2504+
} else {
2505+
db_application_file.lifecycle.state = AppState::StartSignDatacap
2506+
}
2507+
} else if !db_application_file.lifecycle.is_active {
2508+
// If application is not active, we need to move it back to granted state and set last verifier and last active request
2509+
let last_active_request = Self::get_last_active_request(&db_application_file).ok_or(
2510+
LDNError::Load("Failed to get last active request".to_string()),
2511+
)?;
2512+
let last_verifier = Self::get_last_verifier(&db_application_file)?
2513+
.ok_or(LDNError::Load("Failed to get last verifier".to_string()))?;
2514+
db_application_file = db_application_file
2515+
.move_back_to_granted_state(&last_verifier, &last_active_request);
2516+
} else if let (Some(active_request), Some(sps_change_requests)) = (
2517+
db_application_file.lifecycle.active_request.as_ref(),
2518+
db_application_file.allowed_sps.as_ref(),
2519+
) {
2520+
if sps_change_requests
2521+
.get_active_change_request(active_request)
2522+
.is_some()
2523+
{
2524+
db_application_file.lifecycle.state = AppState::ChangingSP;
25302525
}
2531-
};
2532-
2533-
if allocation_count == 1 && active_allocation_ref.signers.0.is_empty() {
2534-
// case with exactly ONE allocation which is active, but not signed yet
2535-
remove_allocation = true;
2536-
db_application_file.lifecycle.state = AppState::Submitted
2537-
} else if active_allocation_ref.signers.0.is_empty() {
2538-
// case with more than one allocations one of which is active, but not signed yet
2539-
remove_allocation = true;
2540-
db_application_file.lifecycle.state = AppState::Granted
25412526
} else {
2542-
// case with more than one allocations one of which is active and signed, and the number of signatures is 2 because otherwise there'd be no active one
2543-
db_application_file.lifecycle.state = AppState::StartSignDatacap
2544-
};
2545-
2546-
db_application_file.lifecycle.edited = Some(false);
2547-
2548-
if remove_allocation {
2549-
db_application_file.remove_active_allocation();
2527+
db_application_file.lifecycle.state = AppState::Granted;
25502528
}
25512529

2552-
let _ = self
2553-
.finalize_changes_approval(db_application_file, owner, repo, sha, branch_name, filename)
2554-
.await;
2555-
2530+
db_application_file.lifecycle.edited = Some(false);
2531+
self.finalize_changes_approval(
2532+
db_application_file,
2533+
owner,
2534+
repo,
2535+
sha,
2536+
branch_name,
2537+
filename,
2538+
)
2539+
.await?;
25562540
Ok("Changes approved".to_string())
25572541
}
25582542

0 commit comments

Comments
 (0)