Skip to content

Commit a987493

Browse files
authored
Merge pull request #2355 from scpwiki/fix-page-view
Fix incorrect page view enum cases
2 parents f719acf + 3222791 commit a987493

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

deepwell/src/services/view/structs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ use crate::models::session::Model as SessionModel;
2626
use crate::models::site::Model as SiteModel;
2727
use crate::models::user::Model as UserModel;
2828

29+
// NOTE: Any changes to the output structures here, including the variant names,
30+
// MUST be reflected in framerail!
31+
2932
// TODO replace with actual user permissions type
3033
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
3134
pub struct UserPermissions;
@@ -51,6 +54,7 @@ pub struct PageRoute {
5154
pub extra: String,
5255
}
5356

57+
// See also framerail src/lib/server/load/page.ts and src/routes/+error.svelte
5458
#[derive(Serialize, Debug, Clone)]
5559
#[serde(rename_all = "snake_case", tag = "type", content = "data")]
5660
pub enum GetPageViewOutput {
@@ -92,6 +96,7 @@ pub struct GetUserView<'a> {
9296
pub locales: Vec<String>,
9397
}
9498

99+
// See also framerail src/lib/server/load/admin.ts and src/routes/[x+2d]/admin/+error.svelte
95100
#[derive(Serialize, Debug, Clone)]
96101
#[serde(rename_all = "snake_case", tag = "type", content = "data")]
97102
pub enum GetUserViewOutput {
@@ -114,6 +119,7 @@ pub struct GetAdminView {
114119
pub locales: Vec<String>,
115120
}
116121

122+
// See also framerail src/lib/server/load/admin.ts and src/routes/[x+2d]/user/+error.svelte
117123
#[derive(Serialize, Debug, Clone)]
118124
#[serde(rename_all = "snake_case", tag = "type", content = "data")]
119125
pub enum GetAdminViewOutput {

framerail/src/lib/server/load/admin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export async function loadAdminPage(request, cookies) {
3232
break
3333
case "site_missing":
3434
errorStatus = 404
35+
break
36+
default:
37+
// Unexpected response type!
38+
// There is an inconsistency between here / DEEPWELL
39+
errorStatus = 500
3540
}
3641

3742
if (errorStatus !== null) {

framerail/src/lib/server/load/page.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ export async function loadPage(
4545
let errorStatus = null
4646

4747
switch (response.type) {
48-
case "page_found":
48+
case "found":
4949
break
50-
case "page_missing":
50+
case "missing":
5151
viewData.page = null
5252
viewData.page_revision = null
5353
errorStatus = 404
5454
break
55-
case "page_permissions":
55+
case "permissions":
5656
errorStatus = 403
5757
break
58-
case "site_missing":
59-
checkRedirect = false
60-
errorStatus = 404
58+
default:
59+
// Unexpected response type!
60+
// There is an inconsistency between here / DEEPWELL
61+
errorStatus = 500
6162
}
6263

6364
let translateKeys: TranslateKeys = {

framerail/src/lib/server/load/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export async function loadUser(username?: string, request, cookies) {
3333
break
3434
case "site_missing":
3535
errorStatus = 404
36+
break
37+
default:
38+
// Unexpected response type!
39+
// There is an inconsistency between here / DEEPWELL
40+
errorStatus = 500
3641
}
3742

3843
if (errorStatus === null && username && viewData.user.slug !== username) {

framerail/src/routes/+error.svelte

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
Use svelte-switch-case package with {#switch data.view}
8585
as soon as we can figure out prettier support for it.
8686
-->
87-
{#if $page.error.view === "page_missing"}
87+
{#if $page.error.view === "missing"}
8888
UNTRANSLATED:Page not found
8989

9090
{#if $page.error.options?.edit}
@@ -214,14 +214,11 @@ as soon as we can figure out prettier support for it.
214214
</form>
215215
{/if}
216216
{/if}
217-
{:else if $page.error.view === "page_permissions"}
217+
{:else if $page.error.view === "permissions"}
218218
UNTRANSLATED:Lacks permissions for page
219219
{@html $page.error.compiled_html}
220-
{:else if $page.error.view === "site_missing"}
221-
UNTRANSLATED:No such site
222-
{@html $page.error.html}
223220
{:else}
224-
UNTRANSLATED:Fallback error, something really went wrong
221+
UNTRANSLATED:Fatal error: Unable to display view
225222
{/if}
226223

227224
<style global lang="scss">

framerail/src/routes/[x+2d]/admin/+error.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ as soon as we can figure out prettier support for it.
1717
UNTRANSLATED:No such site
1818
{@html $page.error.html}
1919
{:else}
20-
UNTRANSLATED:Fallback error, something really went wrong
20+
UNTRANSLATED:Fatal error: Unable to display view
2121
{/if}
2222

2323
<style global lang="scss">

framerail/src/routes/[x+2d]/user/+error.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ as soon as we can figure out prettier support for it.
1717
UNTRANSLATED:No such site
1818
{@html $page.error.html}
1919
{:else}
20-
UNTRANSLATED:Fallback error, something really went wrong
20+
UNTRANSLATED:Fatal error: Unable to display view
2121
{/if}
2222

2323
<style global lang="scss">

0 commit comments

Comments
 (0)