Skip to content

Commit

Permalink
Rename SiteView to AdminView
Browse files Browse the repository at this point in the history
  • Loading branch information
Zokhoi committed Sep 30, 2024
1 parent 800f474 commit b84fe2e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions deepwell/src/endpoints/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use super::prelude::*;
use crate::services::view::{
GetPageView, GetPageViewOutput, GetSiteView, GetSiteViewOutput, GetUserView,
GetAdminView, GetAdminViewOutput, GetPageView, GetPageViewOutput, GetUserView,
GetUserViewOutput,
};

Expand All @@ -46,7 +46,7 @@ pub async fn user_view(
pub async fn admin_view(
ctx: &ServiceContext<'_>,
params: Params<'static>,
) -> Result<GetSiteViewOutput> {
let input: GetSiteView = params.parse()?;
) -> Result<GetAdminViewOutput> {
let input: GetAdminView = params.parse()?;
ViewService::admin(ctx, input).await
}
14 changes: 7 additions & 7 deletions deepwell/src/services/view/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ impl ViewService {

pub async fn admin(
ctx: &ServiceContext<'_>,
GetSiteView {
GetAdminView {
domain,
locales: locales_str,
session_token,
}: GetSiteView,
) -> Result<GetSiteViewOutput> {
}: GetAdminView,
) -> Result<GetAdminViewOutput> {
info!(
"Getting site view data for domain '{}', locales '{:?}'",
domain, locales_str,
Expand All @@ -387,7 +387,7 @@ impl ViewService {
{
ViewerResult::FoundSite(viewer) => viewer,
ViewerResult::MissingSite(html) => {
return Ok(GetSiteViewOutput::SiteMissing { html });
return Ok(GetAdminViewOutput::SiteMissing { html });
}
};

Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
}
Expand Down
7 changes: 3 additions & 4 deletions deepwell/src/services/view/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,21 @@ pub enum GetUserViewOutput {
}

#[derive(Deserialize, Debug, Clone)]
pub struct GetSiteView {
pub struct GetAdminView {
pub domain: String,
pub session_token: Option<String>,
pub locales: Vec<String>,
}

#[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,
Expand Down
3 changes: 2 additions & 1 deletion framerail/src/lib/server/load/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions framerail/src/routes/[x+2d]/admin/+error.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit b84fe2e

Please sign in to comment.