From c1eb356a15bdef132e9ff82c238494a0437bfd96 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 17 May 2025 10:21:37 +0800 Subject: [PATCH] Fix uploads for non-admin users --- frontend/src/app.ts | 4 ++++ frontend/src/pages/publish_page.tsx | 2 +- frontend/src/pages/resource_details_page.tsx | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/app.ts b/frontend/src/app.ts index 20147e6..577ccb7 100644 --- a/frontend/src/app.ts +++ b/frontend/src/app.ts @@ -43,6 +43,10 @@ class App { isLoggedIn() { return this.user != null && this.token != null; } + + canUpload() { + return this.isLoggedIn() && (this.user?.can_upload || this.isAdmin()); + } } export const app = new App(); \ No newline at end of file diff --git a/frontend/src/pages/publish_page.tsx b/frontend/src/pages/publish_page.tsx index 807e104..a86ea48 100644 --- a/frontend/src/pages/publish_page.tsx +++ b/frontend/src/pages/publish_page.tsx @@ -94,7 +94,7 @@ export default function PublishPage() { return } - if (!app.user?.is_admin) { + if (!app.canUpload()) { return } diff --git a/frontend/src/pages/resource_details_page.tsx b/frontend/src/pages/resource_details_page.tsx index bcfc0b4..923f616 100644 --- a/frontend/src/pages/resource_details_page.tsx +++ b/frontend/src/pages/resource_details_page.tsx @@ -272,7 +272,7 @@ function Files({files, resourceID}: { files: RFile[], resourceID: number }) { }
{ - app.isAdmin() &&
+ app.canUpload() &&
}