From a5bc443db98b9a0f1866ed2e1da952cd9fa43a00 Mon Sep 17 00:00:00 2001 From: johnnyjoy Date: Sat, 17 Aug 2024 13:11:53 +0800 Subject: [PATCH] feat: add workspace security setting definition --- frontend/web/src/App.tsx | 2 +- frontend/web/src/components/Header.tsx | 4 +- frontend/web/src/components/Logo.tsx | 2 +- .../components/setting/WorkspaceSection.tsx | 12 +- .../web/src/pages/SubscriptionSetting.tsx | 6 +- frontend/web/src/pages/WorkspaceSetting.tsx | 2 +- frontend/web/src/stores/subscription.ts | 2 +- frontend/web/src/stores/workspace.ts | 6 +- proto/api/v1/workspace_service.proto | 27 +- proto/gen/api/v1/README.md | 57 +- proto/gen/api/v1/workspace_service.pb.go | 550 ++++++------------ proto/gen/api/v1/workspace_service_grpc.pb.go | 30 +- proto/gen/apidocs.swagger.yaml | 43 +- proto/gen/store/README.md | 23 +- proto/gen/store/workspace_setting.pb.go | 296 +++++++--- proto/store/workspace_setting.proto | 20 +- server/route/api/v1/shortcut_service.go | 3 +- server/route/api/v1/workspace_service.go | 24 +- store/db/postgres/workspace_setting.go | 14 + store/db/sqlite/workspace_setting.go | 14 + store/workspace_setting.go | 1 - 21 files changed, 488 insertions(+), 650 deletions(-) diff --git a/frontend/web/src/App.tsx b/frontend/web/src/App.tsx index f0d8a9d..bc38fdd 100644 --- a/frontend/web/src/App.tsx +++ b/frontend/web/src/App.tsx @@ -28,7 +28,7 @@ function App() { }, [workspaceStore.setting.customStyle]); useEffect(() => { - const hasCustomBranding = workspaceStore.profile.plan === PlanType.PRO; + const hasCustomBranding = workspaceStore.profile.subscription?.plan === PlanType.PRO; if (!hasCustomBranding || !workspaceStore.setting.branding) { return; } diff --git a/frontend/web/src/components/Header.tsx b/frontend/web/src/components/Header.tsx index 2f163f5..11b26f3 100644 --- a/frontend/web/src/components/Header.tsx +++ b/frontend/web/src/components/Header.tsx @@ -35,10 +35,10 @@ const Header: React.FC = () => { Slash - {[PlanType.PRO, PlanType.ENTERPRISE].includes(profile.plan) && ( + {profile.subscription?.plan && [PlanType.PRO, PlanType.ENTERPRISE].includes(profile.subscription.plan) && ( {/* PRO or ENT */} - {profile.plan.substring(0, 3)} + {profile.subscription.plan.substring(0, 3)} )} {shouldShowRouterSwitch && ( diff --git a/frontend/web/src/components/Logo.tsx b/frontend/web/src/components/Logo.tsx index ddc17b4..f8a69fd 100644 --- a/frontend/web/src/components/Logo.tsx +++ b/frontend/web/src/components/Logo.tsx @@ -9,7 +9,7 @@ interface Props { const Logo = ({ className }: Props) => { const workspaceStore = useWorkspaceStore(); - const hasCustomBranding = workspaceStore.profile.plan === PlanType.PRO; + const hasCustomBranding = workspaceStore.profile.subscription?.plan === PlanType.PRO; const branding = hasCustomBranding && workspaceStore.setting.branding ? new TextDecoder().decode(workspaceStore.setting.branding) : ""; return (
diff --git a/frontend/web/src/components/setting/WorkspaceSection.tsx b/frontend/web/src/components/setting/WorkspaceSection.tsx index 8adfad9..e09e53c 100644 --- a/frontend/web/src/components/setting/WorkspaceSection.tsx +++ b/frontend/web/src/components/setting/WorkspaceSection.tsx @@ -35,7 +35,7 @@ const WorkspaceSection = () => { const [workspaceSetting, setWorkspaceSetting] = useState(workspaceStore.setting); const originalWorkspaceSetting = useRef(workspaceStore.setting); const allowSave = !isEqual(originalWorkspaceSetting.current, workspaceSetting); - const hasCustomBranding = workspaceStore.profile.plan === PlanType.PRO; + const hasCustomBranding = workspaceStore.profile.subscription?.plan === PlanType.PRO; const branding = hasCustomBranding && workspaceSetting.branding ? new TextDecoder().decode(workspaceSetting.branding) : ""; const onBrandingChange = async (event: React.ChangeEvent) => { @@ -80,12 +80,10 @@ const WorkspaceSection = () => { } try { - const setting = ( - await workspaceServiceClient.updateWorkspaceSetting({ - setting: workspaceSetting, - updateMask: updateMask, - }) - ).setting as WorkspaceSetting; + const setting = await workspaceServiceClient.updateWorkspaceSetting({ + setting: workspaceSetting, + updateMask: updateMask, + }); setWorkspaceSetting(setting); await workspaceStore.fetchWorkspaceSetting(); originalWorkspaceSetting.current = setting; diff --git a/frontend/web/src/pages/SubscriptionSetting.tsx b/frontend/web/src/pages/SubscriptionSetting.tsx index a1fc2a9..9ce38f0 100644 --- a/frontend/web/src/pages/SubscriptionSetting.tsx +++ b/frontend/web/src/pages/SubscriptionSetting.tsx @@ -58,7 +58,7 @@ const SubscriptionSetting: React.FC = () => {

Subscription

Current plan: - {stringifyPlanType(profile.plan)} + {stringifyPlanType(profile.subscription?.plan)}