From 804b054ceb53384bba5b42daebe1afb676d45928 Mon Sep 17 00:00:00 2001 From: Colin Reeder Date: Tue, 12 Jan 2021 00:29:46 -0700 Subject: [PATCH] Report errors when adding or removing community moderators --- src/routes/communities.rs | 101 +++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/src/routes/communities.rs b/src/routes/communities.rs index fe02857..4ff4776 100644 --- a/src/routes/communities.rs +++ b/src/routes/communities.rs @@ -438,10 +438,23 @@ async fn page_community_moderators( ) -> Result, crate::Error> { let (community_id,) = params; - let lang = crate::get_lang_for_req(&req); + let headers = req.headers(); let cookies = get_cookie_map_for_req(&req)?; - let base_data = - fetch_base_data(&ctx.backend_host, &ctx.http_client, req.headers(), &cookies).await?; + + page_community_moderators_inner(community_id, headers, &cookies, ctx, None, None).await +} + +async fn page_community_moderators_inner( + community_id: i64, + headers: &hyper::header::HeaderMap, + cookies: &CookieMap<'_>, + ctx: Arc, + display_error_main: Option, + display_error_add: Option, +) -> Result, crate::Error> { + let lang = crate::get_lang_for_headers(headers); + + let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, headers, &cookies).await?; let community_info_api_res = res_to_error( ctx.http_client @@ -457,7 +470,7 @@ async fn page_community_moderators( }, )) .body(Default::default())?, - req.headers(), + headers, &cookies, )?) .await?, @@ -475,7 +488,7 @@ async fn page_community_moderators( ctx.backend_host, community_id, )) .body(Default::default())?, - req.headers(), + headers, &cookies, )?) .await?, @@ -489,6 +502,13 @@ async fn page_community_moderators( Ok(html_response(render::html! {

{title.as_ref()}

+ { + display_error_main.map(|msg| { + render::rsx! { +
{msg}
+ } + }) + }
    { api_res.iter().map(|user| { @@ -521,6 +541,13 @@ async fn page_community_moderators( Some(render::rsx! {

    {lang.tr("community_add_moderator", None)}

    + { + display_error_add.map(|msg| { + render::rsx! { +
    {msg}
    + } + }) + }