From 8b783adbdbdee7422bd5e203f307a38daacdb5ea Mon Sep 17 00:00:00 2001 From: Sumit Jain Date: Fri, 12 Apr 2024 15:54:00 +0530 Subject: [PATCH] feat:added roles permission check for webhooks and server script --- .../feature/settings/Integrations.tsx | 19 +++++++++++-------- .../layout/Sidebar/SidebarFooter.tsx | 4 ++-- raven-app/src/utils/roles.ts | 8 ++++++++ raven/www/raven.py | 8 ++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/raven-app/src/components/feature/settings/Integrations.tsx b/raven-app/src/components/feature/settings/Integrations.tsx index 8cc475045..09b6f4cd9 100644 --- a/raven-app/src/components/feature/settings/Integrations.tsx +++ b/raven-app/src/components/feature/settings/Integrations.tsx @@ -1,28 +1,31 @@ import { SidebarGroup, SidebarGroupItem, SidebarGroupLabel, SidebarGroupList, SidebarItem } from "@/components/layout/Sidebar" +import { hasServerScriptEnabled, isSystemManager } from "@/utils/roles" import { Flex, Text } from "@radix-ui/themes" import { BiPlug } from "react-icons/bi" export interface Props { } export const Integrations = (props: Props) => { + + const canAddUsers = isSystemManager() + + const serverScriptEnabled = hasServerScriptEnabled() + return ( - {/* */} - + {canAddUsers && Integrations - + } - + {canAddUsers && - {/* */} - - {/* */} - + {serverScriptEnabled && } + } ) diff --git a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx index 5c574d145..9951785c1 100644 --- a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx +++ b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx @@ -53,8 +53,8 @@ export const SidebarFooter = ({ isSettingsPage = false }: { isSettingsPage?: boo Mobile App - {!isSettingsPage && canAddUsers && - + {!isSettingsPage && + Settings } diff --git a/raven-app/src/utils/roles.ts b/raven-app/src/utils/roles.ts index b8c5a93cb..d8925aaa0 100644 --- a/raven-app/src/utils/roles.ts +++ b/raven-app/src/utils/roles.ts @@ -10,4 +10,12 @@ export const hasRavenUserRole = () => { export const isSystemManager = () => { //@ts-expect-error return (window?.frappe?.boot?.user?.roles ?? []).includes('System Manager'); +} + +export const hasServerScriptEnabled = () => { + if (import.meta.env.DEV) { + return true + } + // @ts-expect-error + return (window?.frappe?.boot?.server_script_enabled) } \ No newline at end of file diff --git a/raven/www/raven.py b/raven/www/raven.py index 5ed720f99..ce7833bc7 100644 --- a/raven/www/raven.py +++ b/raven/www/raven.py @@ -26,6 +26,14 @@ def get_context(context): raise frappe.SessionBootFailed from e boot["push_relay_server_url"] = frappe.conf.get("push_relay_server_url") + + # add server_script_enabled in boot + if "server_script_enabled" in frappe.conf: + enabled = frappe.conf.server_script_enabled + else: + enabled = True + boot["server_script_enabled"] = enabled + boot_json = frappe.as_json(boot, indent=None, separators=(",", ":")) boot_json = SCRIPT_TAG_PATTERN.sub("", boot_json)