From 7b9498ca5c3cdf26876aa3ca7eb2c1ed797ab820 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sat, 23 Jul 2022 22:07:45 +0800 Subject: [PATCH] feat: show permissions in profile --- src/lang/en/user.json | 14 ++++++++++++ src/pages/manage/Profile.tsx | 44 +++++++++++++++++++++++++++++++++++- src/types/user.ts | 29 ++++++++++++++++-------- 3 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 src/lang/en/user.json diff --git a/src/lang/en/user.json b/src/lang/en/user.json new file mode 100644 index 000000000..f9a46871a --- /dev/null +++ b/src/lang/en/user.json @@ -0,0 +1,14 @@ +{ + "permission": { + "see_hides": "Can see hides", + "access_without_password": "Access without password", + "add_aria2": "Add aria2 tasks", + "write": "Makedir or upload", + "rename": "Rename", + "move": "Move", + "copy": "Copy", + "remove": "Delete", + "webdav_read": "Webdav read", + "webdav_manage": "Webdav manage" + } +} diff --git a/src/pages/manage/Profile.tsx b/src/pages/manage/Profile.tsx index e5305e95b..cf3b8693f 100644 --- a/src/pages/manage/Profile.tsx +++ b/src/pages/manage/Profile.tsx @@ -1,4 +1,5 @@ import { + Badge, Button, FormControl, FormHelperText, @@ -9,11 +10,20 @@ import { SimpleGrid, VStack, } from "@hope-ui/solid"; -import { createSignal } from "solid-js"; +import { createSignal, JSXElement } from "solid-js"; import { useFetch, useRouter, useT } from "~/hooks"; import { setUser, user } from "~/store"; +import { UserMethods } from "~/types"; import { handleRresp, notify, r } from "~/utils"; +const PermissionBadge = (props: { can: boolean; children: JSXElement }) => { + return ( + + {props.children} + + ); +}; + const Profile = () => { const t = useT(); const { to } = useRouter(); @@ -65,6 +75,38 @@ const Profile = () => { > {t("global.save")} + + + {t("user.permission.see_hides")} + + + {t("user.permission.access_without_password")} + + + {t("user.permission.add_aria2")} + + + {t("user.permission.write")} + + + {t("user.permission.rename")} + + + {t("user.permission.move")} + + + {t("user.permission.copy")} + + + {t("user.permission.remove")} + + + {t("user.permission.webdav_read")} + + + {t("user.permission.webdav_manage")} + + ); }; diff --git a/src/types/user.ts b/src/types/user.ts index eeb061763..faf2d46e7 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -16,15 +16,24 @@ export const UserMethods = { is_guest: (user: User) => user.role === UserRole.GUEST, is_admin: (user: User) => user.role === UserRole.ADMIN, is_general: (user: User) => user.role === UserRole.GENERAL, - can_see_hides: (user: User) => (user.permissions & 1) == 1, + can_see_hides: (user: User) => + UserMethods.is_admin(user) || (user.permissions & 1) == 1, can_access_without_password: (user: User) => - ((user.permissions >> 1) & 1) == 1, - can_add_aria2_tasks: (user: User) => ((user.permissions >> 2) & 1) == 1, - can_write: (user: User) => ((user.permissions >> 3) & 1) == 1, - can_rename: (user: User) => ((user.permissions >> 4) & 1) == 1, - can_move: (user: User) => ((user.permissions >> 5) & 1) == 1, - can_copy: (user: User) => ((user.permissions >> 6) & 1) == 1, - can_remove: (user: User) => ((user.permissions >> 7) & 1) == 1, - can_webdav_read: (user: User) => ((user.permissions >> 8) & 1) == 1, - can_webdav_write: (user: User) => ((user.permissions >> 9) & 1) == 1, + UserMethods.is_admin(user) || ((user.permissions >> 1) & 1) == 1, + can_add_aria2_tasks: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 2) & 1) == 1, + can_write: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 3) & 1) == 1, + can_rename: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 4) & 1) == 1, + can_move: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 5) & 1) == 1, + can_copy: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 6) & 1) == 1, + can_remove: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 7) & 1) == 1, + can_webdav_read: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 8) & 1) == 1, + can_webdav_manage: (user: User) => + UserMethods.is_admin(user) || ((user.permissions >> 9) & 1) == 1, };