From b84fe2e9bbac0aedb80247769eefae047bee1d9f Mon Sep 17 00:00:00 2001 From: Zokhoi <20432565+Zokhoi@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:19:00 +0800 Subject: [PATCH] Rename SiteView to AdminView --- deepwell/src/endpoints/view.rs | 6 +++--- deepwell/src/services/view/service.rs | 14 +++++++------- deepwell/src/services/view/structs.rs | 7 +++---- framerail/src/lib/server/load/admin.ts | 3 ++- framerail/src/routes/[x+2d]/admin/+error.svelte | 4 +--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/deepwell/src/endpoints/view.rs b/deepwell/src/endpoints/view.rs index 5f9a4283d8..734b2f0b90 100644 --- a/deepwell/src/endpoints/view.rs +++ b/deepwell/src/endpoints/view.rs @@ -20,7 +20,7 @@ use super::prelude::*; use crate::services::view::{ - GetPageView, GetPageViewOutput, GetSiteView, GetSiteViewOutput, GetUserView, + GetAdminView, GetAdminViewOutput, GetPageView, GetPageViewOutput, GetUserView, GetUserViewOutput, }; @@ -46,7 +46,7 @@ pub async fn user_view( pub async fn admin_view( ctx: &ServiceContext<'_>, params: Params<'static>, -) -> Result { - let input: GetSiteView = params.parse()?; +) -> Result { + let input: GetAdminView = params.parse()?; ViewService::admin(ctx, input).await } diff --git a/deepwell/src/services/view/service.rs b/deepwell/src/services/view/service.rs index cd7e15cf56..2ca953ef4c 100644 --- a/deepwell/src/services/view/service.rs +++ b/deepwell/src/services/view/service.rs @@ -360,12 +360,12 @@ impl ViewService { pub async fn admin( ctx: &ServiceContext<'_>, - GetSiteView { + GetAdminView { domain, locales: locales_str, session_token, - }: GetSiteView, - ) -> Result { + }: GetAdminView, + ) -> Result { info!( "Getting site view data for domain '{}', locales '{:?}'", domain, locales_str, @@ -387,7 +387,7 @@ impl ViewService { { ViewerResult::FoundSite(viewer) => viewer, ViewerResult::MissingSite(html) => { - return Ok(GetSiteViewOutput::SiteMissing { html }); + return Ok(GetAdminViewOutput::SiteMissing { html }); } }; @@ -434,7 +434,7 @@ impl ViewService { None => { debug!("No user for session, disallow admin access"); - return Ok(GetSiteViewOutput::SitePermissions { + return Ok(GetAdminViewOutput::AdminPermissions { viewer, html: compiled_html, }); @@ -444,11 +444,11 @@ impl ViewService { // Determine whether to return the actual admin panel content let output = if Self::can_access_admin(ctx, user_permissions).await? { debug!("User has admin access, return data"); - GetSiteViewOutput::SiteFound { viewer } + GetAdminViewOutput::SiteFound { viewer } } else { warn!("User doesn't have admin access, returning permission page"); - GetSiteViewOutput::SitePermissions { + GetAdminViewOutput::AdminPermissions { viewer, html: compiled_html, } diff --git a/deepwell/src/services/view/structs.rs b/deepwell/src/services/view/structs.rs index da6f5babd2..9f9acae146 100644 --- a/deepwell/src/services/view/structs.rs +++ b/deepwell/src/services/view/structs.rs @@ -116,22 +116,21 @@ pub enum GetUserViewOutput { } #[derive(Deserialize, Debug, Clone)] -pub struct GetSiteView { +pub struct GetAdminView { pub domain: String, pub session_token: Option, pub locales: Vec, } -#[allow(clippy::enum_variant_names)] #[derive(Serialize, Debug, Clone)] #[serde(rename_all = "snake_case", tag = "type", content = "data")] -pub enum GetSiteViewOutput { +pub enum GetAdminViewOutput { SiteFound { #[serde(flatten)] viewer: Viewer, }, - SitePermissions { + AdminPermissions { #[serde(flatten)] viewer: Viewer, html: String, diff --git a/framerail/src/lib/server/load/admin.ts b/framerail/src/lib/server/load/admin.ts index eeb36e7cde..b819345fee 100644 --- a/framerail/src/lib/server/load/admin.ts +++ b/framerail/src/lib/server/load/admin.ts @@ -27,8 +27,9 @@ export async function loadAdminPage(request, cookies) { switch (response.type) { case "site_found": break - case "site_permissions": + case "admin_permissions": errorStatus = 401 + break case "site_missing": errorStatus = 404 } diff --git a/framerail/src/routes/[x+2d]/admin/+error.svelte b/framerail/src/routes/[x+2d]/admin/+error.svelte index d71af12bd7..a0e3514609 100644 --- a/framerail/src/routes/[x+2d]/admin/+error.svelte +++ b/framerail/src/routes/[x+2d]/admin/+error.svelte @@ -10,9 +10,7 @@ Use svelte-switch-case package with {#switch data.view} as soon as we can figure out prettier support for it. --> -{#if $page.error.view === "page_missing"} - UNTRANSLATED:Page not found -{:else if $page.error.view === "site_permissions"} +{#if $page.error.view === "admin_permissions"} UNTRANSLATED:Lacks permissions for page {@html $page.error.html} {:else if $page.error.view === "site_missing"}