|
1 | 1 | //! Signup invitations, whatever the signup setting: mailed to an address, or |
2 | 2 | //! links to pass on. |
3 | 3 |
|
4 | | -use super::{AdminApplication as App, ReasonForm, Refused}; |
| 4 | +use super::{AdminApplication as App, ReasonForm, ReasonPage}; |
5 | 5 | use crate::{AdminError, InviteExpiry, Reason}; |
6 | 6 | use chrono::Utc; |
7 | 7 | use sourceorigin_common::{ |
@@ -140,59 +140,50 @@ pub(super) async fn create(cx: &Cx, form: Option<Form<CreateInvitation>>) -> Res |
140 | 140 | /// `/invitations/{invitation}/resend`: mails an open invitation's link again. |
141 | 141 | #[route([GET, POST] "/invitations/{invitation}/resend")] |
142 | 142 | pub(super) async fn resend(cx: &Cx, form: Option<Form<ReasonForm>>) -> Result<Response> { |
143 | | - let admin = App::admin(cx).await?; |
144 | | - App::confirm(cx, admin)?; |
| 143 | + let admin = App::confirmed(cx).await?; |
145 | 144 | let service = &App::of(cx).service; |
146 | 145 | let id = *path_param::<Invitation>(cx)?; |
147 | | - let back = href!(list).resolve(cx); |
148 | | - let refusal = App::submit_reason(cx, form, back.clone(), async |reason| { |
| 146 | + App::invitation_change(cx, form, Change::ResendInvitation, id, async |reason| { |
149 | 147 | service.resend_invitation(&admin.operator, id, reason).await |
150 | 148 | }) |
151 | | - .await?; |
152 | | - App::invitation_change(cx, Change::ResendInvitation, id, &back, refusal).await |
| 149 | + .await |
153 | 150 | } |
154 | 151 |
|
155 | 152 | /// `/invitations/{invitation}/revoke`: revokes an unredeemed invitation. |
156 | 153 | #[route([GET, POST] "/invitations/{invitation}/revoke")] |
157 | 154 | pub(super) async fn revoke(cx: &Cx, form: Option<Form<ReasonForm>>) -> Result<Response> { |
158 | | - let admin = App::admin(cx).await?; |
159 | | - App::confirm(cx, admin)?; |
| 155 | + let admin = App::confirmed(cx).await?; |
160 | 156 | let service = &App::of(cx).service; |
161 | 157 | let id = *path_param::<Invitation>(cx)?; |
162 | | - let back = href!(list).resolve(cx); |
163 | | - let refusal = App::submit_reason(cx, form, back.clone(), async |reason| { |
| 158 | + App::invitation_change(cx, form, Change::RevokeInvitation, id, async |reason| { |
164 | 159 | service.revoke_invitation(&admin.operator, id, reason).await |
165 | 160 | }) |
166 | | - .await?; |
167 | | - App::invitation_change(cx, Change::RevokeInvitation, id, &back, refusal).await |
| 161 | + .await |
168 | 162 | } |
169 | 163 |
|
170 | 164 | impl App { |
171 | | - /// The page of `change` to the invitation `id`, going back to `back`, with |
172 | | - /// why its last attempt was refused, if it was. |
173 | | - async fn invitation_change( |
| 165 | + /// The page of `change` to the invitation `id`, made with `call`, which goes |
| 166 | + /// back to the invitations once made. |
| 167 | + async fn invitation_change<F, Fut>( |
174 | 168 | cx: &Cx, |
| 169 | + form: Option<Form<ReasonForm>>, |
175 | 170 | change: Change, |
176 | 171 | id: TokenId, |
177 | | - back: &str, |
178 | | - refusal: Option<Refused<ReasonForm>>, |
179 | | - ) -> Result<Response> { |
| 172 | + call: F, |
| 173 | + ) -> Result<Response> |
| 174 | + where |
| 175 | + F: FnOnce(Reason) -> Fut, |
| 176 | + Fut: Future<Output = Result<(), AdminError>>, |
| 177 | + { |
| 178 | + let back = href!(list).resolve(cx); |
180 | 179 | let shown = id.to_string(); |
181 | | - let target = Target { |
182 | | - name: "Invitation", |
183 | | - id: Some(&shown), |
184 | | - }; |
185 | | - let reason = refusal.as_ref().map(Refused::reason); |
186 | | - let refusal = refusal.as_deref(); |
187 | | - let page = view! { cx => |
188 | | - sourceorigin_ui::dashboard_change( |
189 | | - change: change, |
190 | | - target: target, |
191 | | - back: back, |
192 | | - refusal: refusal, |
193 | | - reason: reason, |
194 | | - ) |
| 180 | + let page = ReasonPage { |
| 181 | + target: Some(Target { |
| 182 | + name: "Invitation", |
| 183 | + id: Some(&shown), |
| 184 | + }), |
| 185 | + ..ReasonPage::new(change, &back) |
195 | 186 | }; |
196 | | - App::render(cx, StatusCode::OK, change.title(), page).await |
| 187 | + Self::reason_change(cx, form, page, back.clone(), call).await |
197 | 188 | } |
198 | 189 | } |
0 commit comments