Skip to content

Commit

Permalink
feat:added roles permission check for webhooks and server script
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitjain236 committed Apr 12, 2024
1 parent 5f93eeb commit 8b783ad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
19 changes: 11 additions & 8 deletions raven-app/src/components/feature/settings/Integrations.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<SidebarGroup>
<SidebarGroupItem gap='2' className={'pl-1.5'}>
{/* <SidebarViewMoreButton onClick={toggle} /> */}
<BiPlug />
<Flex width='100%' justify='between' align='center' gap='2'>
<Flex gap='3' align='center'>
{canAddUsers && <Flex gap='3' align='center'>
<SidebarGroupLabel className='cal-sans'>Integrations</SidebarGroupLabel>
</Flex>
</Flex>}
</Flex>
</SidebarGroupItem>
<SidebarGroup>
<SidebarGroupList>
{canAddUsers && <SidebarGroupList>
<IntegrationsItem route='/settings/integrations/webhooks' label='Webhooks' />
{/* <IntegrationsItem route='/settings/integrations/doctype-events' label='Document Events' /> */}
<IntegrationsItem route='/settings/integrations/scheduled-messages' label='Scheduled Messages' />
{/* <IntegrationsItem route='/settings/integrations/api-events' label='API Events' /> */}
</SidebarGroupList>
{serverScriptEnabled && <IntegrationsItem route='/settings/integrations/scheduled-messages' label='Scheduled Messages' />}
</SidebarGroupList>}
</SidebarGroup>
</SidebarGroup>
)
Expand Down
4 changes: 2 additions & 2 deletions raven-app/src/components/layout/Sidebar/SidebarFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const SidebarFooter = ({ isSettingsPage = false }: { isSettingsPage?: boo
Mobile App
</Link>
</DropdownMenu.Item>
{!isSettingsPage && canAddUsers && <DropdownMenu.Item color='gray' className='focus-visible:ring-0 focus-visible:outline-none rounded-radius2' asChild>
<Link href="../settings/integrations/webhooks" className='no-underline'>
{!isSettingsPage && <DropdownMenu.Item color='gray' className='focus-visible:ring-0 focus-visible:outline-none rounded-radius2' asChild>
<Link href="../settings" className='no-underline'>
Settings
</Link>
</DropdownMenu.Item>}
Expand Down
8 changes: 8 additions & 0 deletions raven-app/src/utils/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions raven/www/raven.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8b783ad

Please sign in to comment.