Skip to content

Commit b02b039

Browse files
authored
[FIL-758] Allow to close ane reopen application (#269)
* Allow to close ane reopen application
1 parent bc0b1e0 commit b02b039

File tree

6 files changed

+258
-43
lines changed

6 files changed

+258
-43
lines changed

fplus-http-server/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ async fn main() -> std::io::Result<()> {
8484
.service(router::application::approve_changes)
8585
.service(router::application::propose)
8686
.service(router::application::approve)
87-
.service(router::application::decline)
8887
.service(router::application::additional_info_required)
8988
.service(router::application::trigger_ssa)
9089
.service(router::application::request_kyc)
9190
.service(router::application::remove_pending_allocation)
9291
.service(router::application::propose_storage_providers)
9392
.service(router::application::approve_storage_providers)
94-
.service(router::application::allocation_failed),
93+
.service(router::application::allocation_failed)
94+
.service(router::application::decline)
95+
.service(router::application::reopen_declined_application),
9596
)
9697
.service(router::application::merged)
9798
.service(router::application::active)

fplus-http-server/src/router/application.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ pub async fn decline(
278278
Ok(HttpResponse::Ok().body(()))
279279
}
280280

281+
#[post("/application/reopen_declined_application")]
282+
pub async fn reopen_declined_application(
283+
query: web::Query<VerifierActionsQueryParams>,
284+
) -> actix_web::Result<impl Responder> {
285+
LDNApplication::reopen_declined_application(
286+
&query.owner,
287+
&query.repo,
288+
&query.github_username,
289+
&query.id,
290+
)
291+
.await
292+
.map_err(ErrorInternalServerError)?;
293+
294+
Ok(HttpResponse::Ok().body(()))
295+
}
296+
281297
#[post("/application/additional_info_required")]
282298
pub async fn additional_info_required(
283299
query: web::Query<VerifierActionsQueryParams>,

fplus-lib/src/core/application/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub enum AppState {
272272
StartSignDatacap,
273273
Granted,
274274
TotalDatacapReached,
275+
Declined,
275276
ChangingSP,
276277
Error,
277278
}

fplus-lib/src/core/application/lifecycle.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl AppState {
1414
AppState::StartSignDatacap => "start sign datacap",
1515
AppState::Granted => "granted",
1616
AppState::TotalDatacapReached => "total datacap reached",
17+
AppState::Declined => "declined",
1718
AppState::ChangingSP => "changing SPs",
1819
AppState::Error => "error",
1920
}
@@ -118,7 +119,6 @@ impl LifeCycle {
118119

119120
pub fn reached_total_datacap(self) -> Self {
120121
let empty = "".to_string();
121-
122122
LifeCycle {
123123
is_active: false,
124124
updated_at: Utc::now().to_string(),
@@ -127,6 +127,28 @@ impl LifeCycle {
127127
}
128128
}
129129

130+
pub fn decline(self) -> Self {
131+
LifeCycle {
132+
state: AppState::Declined,
133+
is_active: false,
134+
updated_at: Utc::now().to_string(),
135+
active_request: None,
136+
..self
137+
}
138+
}
139+
140+
pub fn move_back_to_granted_state(self, verifier: &str, request_id: &str) -> Self {
141+
LifeCycle {
142+
state: AppState::Granted,
143+
validated_by: verifier.into(),
144+
validated_at: Utc::now().to_string(),
145+
is_active: true,
146+
updated_at: Utc::now().to_string(),
147+
active_request: Some(request_id.into()),
148+
..self
149+
}
150+
}
151+
130152
pub fn move_back_to_governance_review(self) -> Self {
131153
let empty = "".to_string();
132154

@@ -142,6 +164,7 @@ impl LifeCycle {
142164
pub fn move_back_to_submit_state(self) -> Self {
143165
LifeCycle {
144166
state: AppState::Submitted,
167+
is_active: true,
145168
updated_at: Utc::now().to_string(),
146169
..self.clone()
147170
}

fplus-lib/src/core/application/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ impl file::ApplicationFile {
7575
}
7676
}
7777

78+
pub fn decline(&self) -> Self {
79+
let new_life_cycle = self.lifecycle.clone().decline();
80+
Self {
81+
lifecycle: new_life_cycle,
82+
..self.clone()
83+
}
84+
}
85+
86+
pub fn move_back_to_granted_state(&self, verifier: &str, request_id: &str) -> Self {
87+
let new_life_cycle = self
88+
.lifecycle
89+
.clone()
90+
.move_back_to_granted_state(verifier, request_id);
91+
Self {
92+
lifecycle: new_life_cycle,
93+
..self.clone()
94+
}
95+
}
96+
7897
pub fn move_back_to_governance_review(&self) -> Self {
7998
let new_life_cycle = self.lifecycle.clone().move_back_to_governance_review(); // move back to submitted state
8099
let allocation = Allocations::default(); // empty allocations
@@ -197,7 +216,7 @@ impl file::ApplicationFile {
197216
}
198217
}
199218

200-
pub fn move_back_to_submit_state(self) -> Self {
219+
pub fn move_back_to_submit_state(&self) -> Self {
201220
let new_life_cycle = self.lifecycle.clone().move_back_to_submit_state();
202221
Self {
203222
lifecycle: new_life_cycle,

0 commit comments

Comments
 (0)