Fix uploads for non-admin users

This commit is contained in:
2025-05-17 10:21:37 +08:00
parent 1c79b6a0a3
commit c1eb356a15
3 changed files with 6 additions and 2 deletions

View File

@@ -43,6 +43,10 @@ class App {
isLoggedIn() { isLoggedIn() {
return this.user != null && this.token != null; return this.user != null && this.token != null;
} }
canUpload() {
return this.isLoggedIn() && (this.user?.can_upload || this.isAdmin());
}
} }
export const app = new App(); export const app = new App();

View File

@@ -94,7 +94,7 @@ export default function PublishPage() {
return <ErrorAlert className={"m-4"} message={t("You are not logged in. Please log in to access this page.")} /> return <ErrorAlert className={"m-4"} message={t("You are not logged in. Please log in to access this page.")} />
} }
if (!app.user?.is_admin) { if (!app.canUpload()) {
return <ErrorAlert className={"m-4"} message={t("You are not authorized to access this page.")} /> return <ErrorAlert className={"m-4"} message={t("You are not authorized to access this page.")} />
} }

View File

@@ -272,7 +272,7 @@ function Files({files, resourceID}: { files: RFile[], resourceID: number }) {
} }
<div className={"h-2"}></div> <div className={"h-2"}></div>
{ {
app.isAdmin() && <div className={"flex flex-row-reverse"}> app.canUpload() && <div className={"flex flex-row-reverse"}>
<CreateFileDialog resourceId={resourceID}></CreateFileDialog> <CreateFileDialog resourceId={resourceID}></CreateFileDialog>
</div> </div>
} }